Repository navigation
Open
Description
Is your feature request related to a problem? Please describe.
I wanted to be able to generically refer to nixConfig settings in my flake outputs, eg:
❯ cat flake.nix
{
nixConfig = {
extra-substituters = [ "https://nix-community.cachix.org" ];
extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ];
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
};
outputs = { self, ... }@inputs: {
nixosConfigurations.machine = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
({ inputs, ... }: {
nix.settings = {
substituters = inputs.self.nixConfig.extra-substituters;
trusted-public-keys = inputs.self.nixConfig.extra-trusted-public-keys;
};
})
];
};
};
}
example on master
❯ nix eval .#nixosConfigurations.machine.config.nix.settings.substituters
error:
… while calling the 'head' builtin
at /nix/store/n6lhdmjihwplszgvfvnlsc38yfkxf7jv-source/lib/attrsets.nix:967:11:
966| || pred here (elemAt values 1) (head values) then
967| head values
| ^
968| else
… while evaluating the attribute 'value'
at /nix/store/n6lhdmjihwplszgvfvnlsc38yfkxf7jv-source/lib/modules.nix:809:9:
808| in warnDeprecation opt //
809| { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
810| inherit (res.defsFinal') highestPrio;
(stack trace truncated; use '--show-trace' to show the full trace)
error: attribute 'nixConfig' missing
at /nix/store/ry1yd7s8g99115ixcbh407ag4r39j03n-source/flake.nix:18:28:
17| nix.settings = {
18| substituters = inputs.self.nixConfig.extra-substituters;
| ^
19| trusted-public-keys = inputs.self.nixConfig.extra-trusted-public-keys;
This can be worked around locally by wrapping the entire flake in rec, then injecting it:
rec {
nixConfig = {
extra-substituters = [ "https://nix-community.cachix.org" ];
extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ];
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
};
outputs = { self, ... }@inputs':
let
inputs = (inputs' // { self = inputs'.self // { inherit nixConfig; }; });
in
{
nixosConfigurations.machine = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
({ inputs, ... }: {
nix.settings = {
substituters = inputs.self.nixConfig.extra-substituters;
trusted-public-keys = inputs.self.nixConfig.extra-trusted-public-keys;
};
})
];
};
};
}
❯ nix eval .#nixosConfigurations.machine.config.nix.settings.substituters
warning: Git tree '/private/tmp/example' is dirty
[ "https://nix-community.cachix.org" "https://cache.nixos.org/" ]
This workaround is not so gross in the grand scheme of things, but it would not help in the case where a user wants to eg: consume and aggregate nixConfig settings from a set of input flakes.
Describe the solution you'd like
I don't see any reason why description or nixConfig should be any different than inputs and outputs -- call-flake.nix should make them available.
Describe alternatives you've considered
Described above.
Priorities
Add 👍 to issues you find important.
Reacted by Yang, Bo, Drewry Pope, Gregor Grigorjan, Steven Stokes, Malix - Alix Brunet and programmerlexi
Activity
roberth commentedon Mar 22, 2024
These could also be passed to the
outputsfunction. That way it's easily available to functions that help with constructing flakes, such as those in flake-utils or flake-parts. Adding an argument requires a bit of care, not to break more flakes than necessary - this part could be done in/afteroutPaththrough newmetaargument #8908Also support for
recfeels a bit accidental, but I don't see any harm in keeping it.refactor(nix): move `nix.settings` to `nixConfig`