nix-community/nixos-anywhere

nixpkgs not in search path

Closed this issue · 2 comments

Hello,

after I followed quick-start guide and used this example flake to deploy to a brand new machine, my system does not work the way I expected.

When I execute e.g. nix-shell -p hello to open a shell with package hello available in path, it throws the following error:

[root@nixos:~]# nix-shell -p hello
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error:
       … <borked>

         at «none»:0: (source not available)

       … while calling the 'import' builtin

         at «string»:1:18:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (hello) ]; } ""
             |                  ^

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)

When I manually install NixOS to this machine with this example config, the error does not occur. Have I overlooked something in the documentation regarding nixpkgs being in the path after installing with nixos-anywhere? Is this even desirable?

Best, glanch

Hi,

The idea behind the example was to provide just that - an example which provides a boot-able nixos system which you could customize before actually installing the host. Or afterwards, i.e. via nixos-rebuild --target-host.

So it wasn't originally intended to provide a fully configured nixos experience, but as we've been seeing an influx of users using nixos-anywhere to get there feet wet with nixos-anywhere it probably makes sense to move in that direction. I.e. with enabling flakes and/or a channel by default.

tl;dr: expected behavior, but PRs welcome :)

We intentionally add --no-channel-copy during nixos install to save time and disk space during installation (in many automated installations nixpkgs will not come from a channel but from flakes or through other tools like niv). You can populate a channel yourself however afterwards with the nix-channel command. However if you use flakes, I can recommend this configuration instead that will add the nixpkgs specified to $NIX_PATH: https://github.com/Mic92/dotfiles/blob/1ff8f72883fab28efcbe34291fb62bbaafa34c8b/nixos/modules/nix-path.nix#L4 than all tools like nix-shell/nix-env will work as expected without having to maintain an additional channel.