Skip to content

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

Open

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.

Activity

  1. added
    feature
    on Mar 10, 2024
  2. roberth commented on Mar 22, 2024

    @roberth
    Member

    These could also be passed to the outputs function. 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/after

    Also support for rec feels a bit accidental, but I don't see any harm in keeping it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureflakes

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions