Nixpkgs: error: file ‘nixpkgs/nixos’ was not found in the Nix search path (add it using $NIX_PATH or -I)

Created on 30 Aug 2017  Â·  5Comments  Â·  Source: NixOS/nixpkgs

I do not know what exactly triggered this to start happening:

[root@nixos:~]# nixos-rebuild switch --upgrade
unpacking channels...
warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs’ does not exist, ignoring
error: file ‘nixpkgs/nixos’ was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:13
building Nix...
warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs’ does not exist, ignoring
error: file ‘nixpkgs/nixos’ was not found in the Nix search path (add it using $NIX_PATH or -I)
warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs’ does not exist, ignoring
error: file ‘nixpkgs’ was not found in the Nix search path (add it using $NIX_PATH or -I)
/tmp/nixos-rebuild.l2pkKY/nix
warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs’ does not exist, ignoring
error: file ‘nixpkgs’ was not found in the Nix search path (add it using $NIX_PATH or -I)
building the system configuration...
warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs’ does not exist, ignoring
error: file ‘nixpkgs/nixos’ was not found in the Nix search path (add it using $NIX_PATH or -I)

Most helpful comment

Another way to trigger this is to expect nix.nixPath to add to the existing items by default. In my configuration I added

nix.nixPath = [
  nixpkgs-overlays=/etc/nixos/overlays
];

which removed nixpkgs and nixos-config from $NIX_PATH. To be able to run nixos-rebuild switch again fix or remove the troublesome nix.nixPath listed above and run

nixos-rebuild switch -I nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs -I nixos-config=/etc/nixos/configuration.nix

This will fix the $NIX_PATH.

All 5 comments

[root@nixos:~]# nixos-version
17.03.1700.51a83266d1 (Gorilla)
[root@nixos:~]# nix-env --version
nix-env (Nix) 1.11.13
[root@nixos:~]# nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion
warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs’ does not exist, ignoring
error: file ‘nixpkgs’ was not found in the Nix search path (add it using $NIX_PATH or -I)
[root@nixos:~]# grep build-use-sandbox /etc/nix/nix.conf
build-use-sandbox = false

I've sorted this out via IRC. The "nixos" channel was renamed via nix-channel.

sudo nix-channel --add https://nixos.org/channels/nixos-17.03 nixos

What I did was manually edit the channels configuration file to have:

https://nixos.org/channels/nixos-17.03 stable

Not realizing that would break it.
Might be a good idea to have some check for this type of error in Nix and give a better error message as I seen similar errors on google but with no fix.

Another way to trigger this is to expect nix.nixPath to add to the existing items by default. In my configuration I added

nix.nixPath = [
  nixpkgs-overlays=/etc/nixos/overlays
];

which removed nixpkgs and nixos-config from $NIX_PATH. To be able to run nixos-rebuild switch again fix or remove the troublesome nix.nixPath listed above and run

nixos-rebuild switch -I nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs -I nixos-config=/etc/nixos/configuration.nix

This will fix the $NIX_PATH.

I had this problem when I ran a nix-channel --remove nixos19 command followed by a nix-channel --add <url> nixpkgs command in order to rename a channel (I'm a total newb to NixOS trying to install for the first time right now and tinkering while at it). Then I was able to fix it by running nix-channel --update, which created the missing files at /nix/var/nix/profiles/per-user/trusktr/channels/nixpkgs/nixos which I believe were deleted when I ran the nix-channel --remove command.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edolstra picture edolstra  Â·  3Comments

ob7 picture ob7  Â·  3Comments

ghost picture ghost  Â·  3Comments

chris-martin picture chris-martin  Â·  3Comments

copumpkin picture copumpkin  Â·  3Comments