Nix shell appends to wrong section in $PATH

Hey,

I’m trying to run older version of nix but it somehow goes to the bottom of my $PATH.

What could be the reason?

$ nix shell github:nixos/nix/2.11.0
$ nix --version
$ echo $PATH
/nix/var/nix/profiles/default/bin /run/current-system/sw/bin /Users/onnimonni/.nix-profile/bin /nix/store/lr32i0bdarx1iqsch4sy24jj1jkfw9vf-nix-2.11.0/bin /nix/var/nix/profiles/default/bin /Users/onnimonni/.nix-profile/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /Library/Apple/usr/bin

So it indeed adds the /nix/store/lr32i0bdarx1iqsch4sy24jj1jkfw9vf-nix-2.11.0/bin to the $PATH but it’s below /nix/var/nix/profiles/default/bin and /run/current-system/sw/bin so it will never be used.

I installed my nix initially from NixOS installer:

curl -L https://nixos.org/nix/install | sh -s

And I’m using nix-darwin with my flake.nix visible here.

How could I setup my environment in a way where the nix shell would actually prepend the path to correct place in the $PATH?

  1. Your PATH variable looks broken, it is supposed to be colon (:) seperated…
  2. You should prefer printenv VAR over echo $VAR to avoid expanding local variables
  3. It is very likely that your shells rc files do something like export PATH=/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:$PATH to prepend those competing entries.

I’m using fish shell and in it uses space instead of “:”.

I will remove any mentions of these from my shell files but I think the /nix/var/nix/profiles/default wasn’t even mentioned there.

I checked the code for nix daemon and it seems to add that path into the front of the PATH.