Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix-daemon.nix: Add option nix.registry #84125

Merged
merged 1 commit into from Apr 2, 2020

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Apr 2, 2020

This allows you to specify the system-wide flake registry. One use is to pin nixpkgs to the Nixpkgs version used to build the system:

nix.registry.nixpkgs.flake = nixpkgs;

where nixpkgs is a flake input. This ensures that commands like

$ nix run nixpkgs#hello

pull in a minimum of additional store paths.

You can also use this to redirect flakes, e.g.

nix.registry.nixpkgs.to = {
  type = "github";
  owner = "my-org";
  repo = "my-nixpkgs";
};
Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

This allows you to specify the system-wide flake registry. One use is
to pin 'nixpkgs' to the Nixpkgs version used to build the system:

  nix.registry.nixpkgs.flake = nixpkgs;

where 'nixpkgs' is a flake input. This ensures that commands like

  $ nix run nixpkgs#hello

pull in a minimum of additional store paths.

You can also use this to redirect flakes, e.g.

  nix.registry.nixpkgs.to = {
    type = "github";
    owner = "my-org";
    repo = "my-nixpkgs";
  };
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A review. Better late than never :)

to = mkOption {
type = inputAttrs;
example = { type = "github"; owner = "my-org"; repo = "my-nixpkgs"; };
description = "The flake reference to which <option>from></option> is to be rewritten.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from> can't be right.

description = "The flake reference to which <option>from></option> is to be rewritten.";
};
flake = mkOption {
type = types.unspecified;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #131814

default = null;
example = literalExample "nixpkgs";
description = ''
The flake input to which <option>from></option> is to be rewritten.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what "a flake input" means here. Input seems to be a role, rather than an intrinsic description of what it is that you need here. I guess you could equally say "a flake output attrset", because that's what defines an invoked flake. It'd also be helpful to know by which means this configuration is stored.
What happens when you use this option in a flake where you use inputs.<input>.follows? I don't think that important context preserved, is it?

Comment on lines +420 to +422
} // lib.filterAttrs
(n: v: n == "lastModified" || n == "rev" || n == "revCount" || n == "narHash")
config.flake);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is // { inherit (config.flake) .....; }

));
default = {};
description = ''
A system-wide flake registry.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it do? Maybe reference the Nix manual?

@matt-snider
Copy link
Contributor

matt-snider commented Feb 12, 2022

@roberth @edolstra

I'm using NixOS 21.11 and Nix 2.4. I'd like to globally pin the nixpkgs flake to the same version as my system.

{
  # ...
  nix.registry.nixpkgs.flake = pkgs;
}

But this causes an error:

$ nixos-rebuild test                                                                                                                                                                     
building Nix...
building the system configuration...
error: attribute 'outPath' missing

       at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/services/misc/nix-daemon.nix:522:27:

          521|                 ({ type = "path";
          522|                    path = config.flake.outPath;
             |                           ^
          523|                  } // lib.filterAttrs
(use '--show-trace' to show detailed location information)

Is the documentation out of date or am I doing something wrong?

@matt-snider
Copy link
Contributor

Ok I might have made a bit of progress.

I tried this and now at least the build works:

{
  # ...
  nix.registry.nixpkgs.flake.outPath = toString <nixpkgs>;
}

But when using nixpkgs as an input in a flake I get this error:

$ nix develop                                                                                                                                                                                
warning: Git tree '/home/matt/projectxyz' is dirty
error: access to path '/nix/store/nv5hy4qdqv1cqlhqg8wv3lpvjqn6jpdx-nixos-21.11.335443.e84444b14cc/nixos/flake.nix' is forbidden in restricted mode

@edolstra
Copy link
Member Author

<nixpkgs> doesn't work in a flake because in pure evaluation mode, you don't have access to the Nix search path (NIX_PATH).

Here is what I do:

nix.registry.nixpkgs.flake = nixpkgs;

where nixpkgs is the Nixpkgs flake. See here: https://www.tweag.io/blog/2020-07-31-nixos-flakes/

@matt-snider
Copy link
Contributor

@edolstra Thank you for the response and thank you for bringing the awesomeness that is Nix/NixOS to the world.

I read your blog post, that is where I saw that it was possible to configure the registry and when it didn't work I tracked it down in the code to this MR.

I don't currently have my NixOS configuration set up as a flake, so I think I would have to switch to a flake-based system config to do this. This was my plan anyways, but I was just starting to experiment with flakes to replace shell.nix development environments.

Regarding pure-evaluation: I see that nix develop --impure works, but I don't understand why. The help for --impure says "Allow access to mutable paths and repositories", but /nix/store/nv5hy4qdqv1cqlhqg8wv3lpvjqn6jpdx-nixos-21.11.335443.e84444b14cc/nixos/flake.nix is not mutable. Why is this considered to be impure?

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

Successfully merging this pull request may close these issues.

None yet

3 participants