Where is NIX_PATH supposed to be set?

On non-NixOS, NIX_PATH doesn’t get set anymore if you installed via the binary tarball installer. Instead, it’s supposed to use a default search path here.

On NixOS, it’s still set in the NixOS module that configures Nix. On Debian-based systems, if you install nix-setup-systemd, you get a file called /usr/lib/environment.d/nix-daemon.conf where this gets set. On my Ubuntu system, it reads:

NIX_REMOTE=daemon
PATH="$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"
NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/$USER/channels/nixpkgs:/nix/var/nix/profiles/per-user/$USER/channels"

I assume all of this led to few people noticing the issue you’re seeing.

What’s weird is that Nix is complaining about NIX_PATH being unset, even though it gets a default one in eval.cc. That seems inconsistent.

NIX_PATH still gets set in nix.sh and nix-daemon.sh in Nix 2.3.x, both for single-user and for multi-user installations. So that you now get the warning is a bug in Nix 2.4 which was previously unnoticed.

This commit is where NIX_PATH got pulled from the relevant file in favor of the default in eval.cc, I think.

If you want to add what was in Nix 2.3, for your convenience, it’s this for single-user:

    # Append ~/.nix-defexpr/channels to $NIX_PATH so that <nixpkgs>
    # paths work when the user has fetched the Nixpkgs channel.
    export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels

Are commands you need actually crapping out on you, or does the error message seem superfluous?

2 Likes