[FAIL] Multiple versions of nix found in PATH

On a fresh installation with:

  • macOs 12.4 (Monterey)
  • Nix 2.9.1 release
  • Nix-darwin unstable
  • Flakes enabled

This is the result of nix doctor:

$ nix doctor
[FAIL] Multiple versions of nix found in PATH:
  /nix/store/cqdwb7khf6zg94bz7lnvfjqx6z775qaw-nix-2.9.1/bin
  /nix/store/cxa1rp3zpqj9k0l0zgn7a0bbf31rhzbz-nix-2.9.0/bin

[PASS] All profiles are gcroots.
[PASS] Client protocol matches store protocol.

I guess this happened because I installed Nix v2.9.1 (https://releases.nixos.org/nix/nix-2.9.1/install) and then nix-darwin, but at that time nixpkgs were still pointing to Nix v2.9.0. Next, I’ve enabled the experimental flakes and noticed the issue.

I’m a newcomer and would like to understand the cause as much as the possible solutions. Note that I’m trying to do a fresh flakes-based installation of nix, nix-darwin, and home-manager but some channels inevitably came into play.

It’s very confusing to see Nix v2.9.1 as the actual version being used and reported, but not listed by nix-env as installed nor even available.

$PATH got messed up and must be cleaned, but I have no clue on what caused it.

Maybe $NIX_PATH should also be simplified?

Please find below additional information that may be helpful for reasoning on this…

$ nix --version
nix (Nix) 2.9.1

$ nix-info -m
 - system: `"x86_64-darwin"`
 - host os: `Darwin 21.5.0, macOS 10.16`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.9.1`
 - channels(root): `"nixpkgs"`
 - channels(bob): `"darwin"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

$ sudo -i nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable

$ nix-channel --list
darwin https://github.com/LnL7/nix-darwin/archive/master.tar.gz

$ sudo -i nix-env -q
nix-2.9.1
nss-cacert-3.66

$ sudo -i nix-env -qasP nix
...
-PS  nixpkgs.nixStable             nix-2.9.0
-PS  nixpkgs.nixFlakes             nix-2.9.0
-PS  nixpkgs.nixStatic             nix-2.9.0
-PS  nixpkgs.nix                   nix-2.9.0

$ nix-env -q

$ nix-env -qasP nix
...
-PS  nixpkgs.nixStable             nix-2.9.0
-PS  nixpkgs.nixFlakes             nix-2.9.0
-PS  nixpkgs.nixStatic             nix-2.9.0
-PS  nixpkgs.nix                   nix-2.9.0

$ echo $NIX_PATH
darwin-config=/Users/bob/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels:/Users/bob/.nix-defexpr/channels

$ echo $PATH
/Users/bob/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/Users/bob/.nix-profile/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin

Go through your $PATH and take a look.

I have my suspicion that nix-env -q (no sudo!) will reveal the problem though.

Investigating the $PATH reveals the problem, caused by the installation of nix-darwin I believe.

$ ls -Fl /run/current-system/sw/bin
...
nix@ -> /nix/store/cxa1rp3zpqj9k0l0zgn7a0bbf31rhzbz-nix-2.9.0/bin/nix
nix-env@ -> /nix/store/cxa1rp3zpqj9k0l0zgn7a0bbf31rhzbz-nix-2.9.0/bin/nix-env
...
nix-info@ -> /nix/store/1s4znmrm1dnfl2hrap3wjzrvykmq4s29-nix-info/bin/nix-info
...

$ nix-env -q reports that there isn’t any package installed, already mentioned in the original post.

It’s very confusing that current-system links to two packages (nix and nix-info) but nix-env has no knowledge of them being installed. I’m unable to explain this since I don’t know yet how nix-darwin works. :frowning:

$ /run/current-system/sw/bin/nix-env --version
nix-env (Nix) 2.9.0

$ /run/current-system/sw/bin/nix-env -q

The package is installed in root’s profile. Try doing sudo -i nix-env -q.

One of the first things I do after setting up my system is remove the nix installed in root’s profile and let nix-darwin manage it.

Hosted by Flying Circus.