Error: file 'nixpkgs/nixos' was not found in the Nix search path

$  sudo PATH="$PATH" NIX_PATH="$NIX_PATH" `which nixos-install` --root /mnt
building the configuration in /mnt/etc/nixos/configuration.nix...
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)

Note: This should be equivalent to sudo nixos-install --root /mnt.

We need a bit more context to help you with the error. Please check the contents of $NIX_PATH

echo $NIX_PATH
$ echo $NIX_PATH


it is empty

I’m trying this: Installing from another Linux distribution

1 Like

Did you restart your shell after installing Nix? NIX_PATH is set on shell initialization. If installation worked correctly, it should pick it up after a restart.

Note that the installer has numerous edge cases which don’t work, e.g. not all shells are supported flawlessly.

1 Like


If I understand the issue and given the documentation you linked, are you looking for installing NixOS on an existing Linux system?

  • did you add the channel when as root? it’s per user AFAIK
  • can you run this simple command to ensure nix is working? nix-shell -p hello --run hello

I’d generally avoid mixing sudo with nix commands, as it may break your environment variables depending on how it’s configured.

That wasn’t in the guide, but didn’t solve the problem anyway .

It is in the guide

$ nix-shell -p hello --run hello
error: opening lock file '/nix/store/6fz4bq3yi89b28aws84pmnf8b59i02n7-hello-2.12.tar.gz.drv.lock': Permission denied

But sudo (# nix-shell -p hello) works correctly

removing NIX_PATH="$NIX_PATH" from the command seems to solve problem. But it is against what the guide says.

The guide recommends NIX_PATH="$NIX_PATH" so that the channels you set as your user carry over to the command in sudo (without sudo this would just be a no-op). It works because you both followed @Solene 's advice to add the channel as root and removed that env variable setting, but neither is what the guide intended.

sudo --preserve-env=NIX_PATH,PATH would be a much more explicit way of doing this, by the way.

I’m still wondering why the guide didn’t work with the per-user config. My guess is that your shell’s configuration (presumably your .bashrc or .bash_profile) doesn’t load whatever file nix writes its variable setup into on non-NixOS distros.

That guide can probably done a bit more fool-proofly. If it just set up the nix path without relying on the environment variable it’d be far more robust. I guess this is one of the things that will just by nature get less tricky with flakes, though.


We can still update the guide right now to reduce the number of steps and opportunities for something to go wrong.


I need to figure out how to contribute to the manual one day :slight_smile: It’d be cool if there was a way to create documentation tickets against nixpkgs for this kind of situation (with the correct label), but as best as I can tell non-contributors can only create bug tickets.

I should work on that contributor status as well…

In case I (or someone else here) ever get an inspired evening, what distro were you installing from? Would be nice to reproduce the exact scenario to make sure the guide is adapted to it.

It is Endeavour OS

(extra words for 20 characters minimum post)


@TLATER I made PRs for documentation issue template on NixOS/nixpkgs and also on NixOS/nix.