Skip to content

All 4 top-level flake attributes should be exposed #10210

@sielicki

Description

@sielicki

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposalflakes
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions