Closed antoineco closed 2 months ago
Backport of NixOS/nixpkgs@e456032addae76701eb17e6c03fc515fd78ad74f, which ensures that NIX_PATH includes nixpkgs=flake:nixpkgs when the system was built from a flake.
NIX_PATH
nixpkgs=flake:nixpkgs
Here is the rationale for having NIX_PATH correctly set in a flake context, especially since Nix 2.24: https://github.com/NixOS/nixpkgs/pull/273170#issuecomment-2342254448
💻 Demonstration from a REPL session, using my own system flake importing this branch
Before switch, despite having extra-nix-path = nixpkgs=flake:nixpkgs in nix.conf:
switch
extra-nix-path = nixpkgs=flake:nixpkgs
nix.conf
$ nix repl --expr 'import <nixpkgs> {}' Nix 2.24.6 error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
Open the REPL and load the flake's output to execute nix-darwin.lib.darwinSystem:
nix-darwin.lib.darwinSystem
$ nix repl Nix 2.24.6 Type :? for help. >
> darwinCfg = (builtins.getFlake (builtins.toString ./.)).darwinConfigurations.myhost
Verify that nix.registry was populated:
nix.registry
With nix.registry.nixpkgs equal to nix-darwin's nixpkgs.source (default)
nix.registry.nixpkgs
nixpkgs.source
> darwinCfg.options.nix.registry.value.nixpkgs.to { path = { ... }; type = "path"; } > builtins.toPath darwinCfg.options.nix.registry.value.nixpkgs.to.path "/nix/store/1h99qq6970gkx3j0m9w4yrrl9y99y1nk-source"
With nix.registry.nixpkgs overriden by the user
> darwinCfg.options.nix.registry.value.nixpkgs.to { type = "tarball"; url = "https://flakehub.com/f/DeterminateSystems/nixpkgs-weekly/0.1.0.tar.gz"; }
Verify that nix.nixPath was populated:
nix.nixPath
With nix.channel.enable = true (default)
nix.channel.enable = true
> darwinCfg.options.nix.nixPath.value [ "nixpkgs=flake:nixpkgs" "/nix/var/nix/profiles/per-user/root/channels" ]
With nix.channel.enable = false
nix.channel.enable = false
> darwinCfg.options.nix.nixPath.value [ "nixpkgs=flake:nixpkgs" ]
After a switch, the system can perform <nixpkgs> lookups successfully:
<nixpkgs>
$ darwin-rebuild switch $ exec zsh -il $ nix repl --expr 'import <nixpkgs> {}' Nix 2.24.6 Type :? for help. Loading installable ''... Added 22627 variables.
Backport of NixOS/nixpkgs@e456032addae76701eb17e6c03fc515fd78ad74f, which ensures that
NIX_PATH
includesnixpkgs=flake:nixpkgs
when the system was built from a flake.Here is the rationale for having
NIX_PATH
correctly set in a flake context, especially since Nix 2.24: https://github.com/NixOS/nixpkgs/pull/273170#issuecomment-2342254448💻 Demonstration from a REPL session, using my own system flake importing this branch
Before
switch
, despite havingextra-nix-path = nixpkgs=flake:nixpkgs
innix.conf
:Open the REPL and load the flake's output to execute
nix-darwin.lib.darwinSystem
:Verify that
nix.registry
was populated:With
nix.registry.nixpkgs
equal to nix-darwin'snixpkgs.source
(default)With
nix.registry.nixpkgs
overriden by the userVerify that
nix.nixPath
was populated:With
nix.channel.enable = true
(default)With
nix.channel.enable = false
After a
switch
, the system can perform<nixpkgs>
lookups successfully: