File 'nixpkgs' was not found in the Nix search path

Hi. I’m at a bit of a loss here, looking at the other forum posts about this error, they don’t seem exactly related to my problem (the forum posts I saw are related to running nix-shell, and I’m not trying to run nix-shell).

I’m running NixOS 20.9, and I tried to install a package from unstable following the FAQ in FAQ - NixOS Wiki
Now I’m aware that there is the bug 1865, but according with https://github.com/NixOS/nix/issues/1865 it was solved in nix 2.3.1 (I’m on 2.3.9 right now).
This is what I put in my configuration.nix file (after adding the unstable channel and updating it):

let
unstable = import < nixos-unstable> {};
in {
environment.systemPackages = [ unstable.appimage-run ];
}

And this is the long list of error messages I get when I try to run sudo nixos-rebuild:

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’ 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’ does not exist, ignoring
error: file ‘nixpkgs’ 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’ does not exist, ignoring
error: file ‘nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix’ was not found in the Nix search path (add it using $NIX_PATH or -I)
/tmp/nixos-rebuild.1M8hkU/nix
warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels/nixos’ 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’ does not exist, ignoring
error: file ‘nixpkgs/nixos’ was not found in the Nix search path (add it using $NIX_PATH or -I)

What really throws me off is that the path /nix/var/nix/profiles/per-user/root/channels/nixos is declared in my $NIX_PATH:

echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/conf
iguration.nix:/nix/var/nix/profiles/per-user/root/channels

This is the result I get from nix-channel --list:

nixos nixos-20.09 release nixos-20.09.4407.1c1f5649bb9
nixos-unstable nixos-unstable release nixos-21.11pre326932.b165ce0c4ef

Is there anything I may be doing wrong, like the syntax of my configuration.nix file?

1 Like

While using sudo, the environment variables are read from another session (root user), try executing sudo sh -c 'echo $NIX_PATH' and sudo nix-channel --list

Hi, thanks for the help.
Those are the results:

sudo echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

sudo nix-channel --list
nixos nixos-20.09 release nixos-20.09.4407.1c1f5649bb9
nixos-unstable nixos-unstable release nixos-21.11pre326932.b165ce0c4ef

I must have forgotten to mention that when I added and updated the unstable channel the first time, I did it with sudo, so as far as I am aware, the environment variables of the root user should be OK.

BTW, I’ve just realized the path command you asked me to do was a bit different, so I tried it to check, and it seems the $NIX_PATH variable of the root user is fine.

sudo sh -c 'echo $NIX_PATH'
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

OK, so, just to add:

  • I tried removing the extra bits in my configuration.nix file (the import unstable, unstable system packages, etc), and I get the same error even if I just try to add regular packages, which means I can’t rebuild my system anymore
  • I tried removing the unstable channel from my channel list using sudo nix-channel --remove, and now it doesn’t show in nix-channel --list anymore, but I still get the same errors
  • I tried rolling back a couple generations to see if I can get to one that is working, but I still have the same issue

So I think that somehow I managed to completely bork my installation, and maybe I’ll need to reinstall everything tonight.

  1. Prefer printenv NIX_PATH over echo $NIX_PATH, as the latter will also print local variables, while the latter will only print variables that are indeed in the environment.
  2. After you added or removed channels, have you done an nix-channel --update?
  3. Can you perhaps make it work by git clone nixpkgs, checking out your selected stable branch and providing the clones location via -I?
2 Likes

Heh, what do I know? Last night when I added the unstable channel I remembered to do a nix-channel --update, but today after I removed it I had forgotten this step.

So, after doing the right steps this time, I’m able to rebuild the system again, thanks a lot.

So, knowing I can go back and not actually bork my system, I’ll try again to add the unstable repository later.

Right.
So, the good news is: after removing the channel, updating and then rebuilding my system, I tried adding it again and updating the channels again, and I guess it worked, so I must have done something wrong the first time.
The bad news is that I tried doing a simple rebuild without adding the import lines for installing unstable packages in my configuration file, and now I think my whole system was updated to the unstable channel

So, just so I know: if I just add the unstable channel and then don’t do an import line in the configuration file, my system will just update with the unstable channel? By reading the manual, I was under the impression that the “default” channel would be the one tagged as “nixos”. For reference, this is my channel list:

sudo nix-channel --list
nixos nixos-20.09 release nixos-20.09.4407.1c1f5649bb9
nixos-unstable nixos-unstable release nixos-21.11pre326932.b165ce0c4ef

Also, just for reference: how unstable is the “unstable” branch? I know it’s not recommended for production servers, but I’m a desktop user.

Check /etc/os-release it will tell you the version your system was built on.

If it say 21.0x, it unstable.

Though it should be stable from what I can see in the channels.

Though as you probably haven’t updated your channel for a while now, it of course updated some programs on the rebuild.

1 Like

OK, that was it. It says 20.09, so everything is fine.
It’s weird that it updated all those programs in the rebuild, though, this system is pretty new, I installed it 2 days ago, but whatever.

Either way, now I managed to make everything work, including the declarations inside the configuration.nix, thanks for the help.