[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:

[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

$ 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

$ echo $PATH

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.


I think this is what I need to do as well to resolve this issue on my machine, but I’m not sure what to do. I attempted to brute-force remove some of the files from the /var/root folder, but I ended up breaking my nix system and needed to reinstall.

Which steps do you use to remove the nix installed in root so only nix-darwin is managing nix?

sudo -i nix-env -e nix should remove the nix package from root’s profile.

1 Like

I had this when I first installed on macOS with 2.13 and 2.14
I installed 2.13 I think I must have upgraded under sudo.
Root was 2.14 and everything else 2.13.
@reckenrode’s post seemed to fix this.

sudo -i nix-env -e nix should remove the nix package from root’s profile.

I think installation instructions for macOS should highlight this.
Because of this I am not sure if I will have this issue upgrading the whole system to 2.14 a bit apprehensive tbh

1 Like

I have just had the same issue the system was and should be on 2.13.3
However, after I installed my system flake (nix-pegs, nix flakes, nix-darwin , home-manager) the system is using nix 2.11.1

[FAIL] Multiple versions of nix found in PATH:
> nix --version 
nix (Nix) 2.11.1

> sudo nix --version 
nix (Nix) 2.11.1

The only thing I can think of is home-manager config stateVersion
I forgot to change it from stateVersion = "22.11.1”

Problem is this time around I can not find a way to remove nix-2.11.1

 > nix-env  -q
< nothing >
> sudo nix-env  -q  

I was able to fix using

sudo nix upgrade-nix -p /nix/var/nix/profiles/per-user/andrew/profile

Apparently, some nix upgrade features use the higher compatible nix for the nixpkgs flake or channel although I don’t think this was the cause in my case.

Havent been able to uninstall nix-2.11.1 yet

UPDATE: 09/05/2023

I now have the similar

sudo and user

>nix --version
nix (Nix) 2.13.3

which nix

nix doctor shows nix 2.11.1

[FAIL] Multiple versions of nix found in PATH:

seems to be under system current system

/run/current-system/sw/bin/nix --version
nix (Nix) 2.11.1

I have tried darwin-rebuild I just don’t seem to be able to find away to change from 2.11.1 to 2.13.3
I am using 2.13.3 and not 2.14 because I found a bug in nix-darwin (has been reported) regarding symbolic links in /etc

I think the issue is to do with nix-darwin.

Is there anybody who can explain why this is happening? I don’t understand the relationship between the current-system nix and the default profile nix binaries.

I have the same issue that people have mentioned here, but I want some clarifications before I start running random nix commands. :slight_smile:

The situation:

❯ nix doctor
[FAIL] Multiple versions of nix found in PATH:

❯ shasum  /nix/store/s0r0bsykfvxp5l1x0kmajw9nb606qqwk-nix-2.15.1/bin/nix  /nix/store/x11cpsjg4q236msfz5scc325pfp9xy64-nix-2.15.1/bin/nix
f751087a2d9b0f75fa8fc16ab563d2c1f60ce58d  /nix/store/s0r0bsykfvxp5l1x0kmajw9nb606qqwk-nix-2.15.1/bin/nix
6896f024a637e6318b20d82c1285cfeb79810be1  /nix/store/x11cpsjg4q236msfz5scc325pfp9xy64-nix-2.15.1/bin/nix

❯ shasum  /run/current-system/sw/bin/nix  /nix/var/nix/profiles/default/bin/nix
f751087a2d9b0f75fa8fc16ab563d2c1f60ce58d  /run/current-system/sw/bin/nix
6896f024a637e6318b20d82c1285cfeb79810be1  /nix/var/nix/profiles/default/bin/nix

❯ file  /nix/store/s0r0bsykfvxp5l1x0kmajw9nb606qqwk-nix-2.15.1/bin/nix
/nix/store/s0r0bsykfvxp5l1x0kmajw9nb606qqwk-nix-2.15.1/bin/nix: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>

❯ file /nix/store/x11cpsjg4q236msfz5scc325pfp9xy64-nix-2.15.1/bin/nix
/nix/store/x11cpsjg4q236msfz5scc325pfp9xy64-nix-2.15.1/bin/nix: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>

My setup is similar to the ones described here. nix + nix-darwin + home-manager.

I used the Determinate Systems nix-installer.


  • I thought this was something that nix was supposed to avoid, how did this happen?
  • which path is “more correct” to continue to exist in my nix environment, the current-system or the profiles/default one?
  • Why is my nix-darwin flake not playing nice with the system environment?
  • Do I need to import the system somehow?
  • Based on my investigation, the current-system nix is the one from nix-darwin (the derivations that reference the nix binary also reference darwin resources). I found this out by just grepping the nix/store derivation files for the sha hash and seeing which drv files refrenced it. This was very slow and terrible, what is the “correct” way to answer the question “where did this binary come from?” if you don’t have a flake file to reference?
  • how do you pretty-print nix code on the CLI? I want to just pipe the drv files to jq, but they aren’t json…

Ok, those are all the questions I can think of for right now, hopefully there are some ideas!

Ok, this is getting weird, so I tried grepping the nix-store for the two nix SHAs and the current-system one has a bunch of hits. It is clearly the “correct” nix that I should be using.

The default profile one has only a single hit:

/nix/store//q0q1xsv1ghp7dfdrxpwc84byqqxdspdy-user-environment.drv:Derive([("out","/nix/store/14xnpyhax1bmi4zzafkxb33zppr1qxmi-user-environment","","")],[],["/nix/store/dpfibfvh14cpnq22y9m2mnyhkaikpnr1-env-manifest.nix"],"builtin","builtin:buildenv",[],[("allowSubstitutes",""),("builder","builtin:buildenv"),("derivations","true 5 1 /nix/store/x11cpsjg4q236msfz5scc325pfp9xy64-nix-2.15.1 true 5 1 /nix/store/pl497357lkfpvdr8v4pfan16k7jna2l2-nss-cacert-3.83"),("manifest","/nix/store/dpfibfvh14cpnq22y9m2mnyhkaikpnr1-env-manifest.nix"),("name","user-environment"),("out","/nix/store/14xnpyhax1bmi4zzafkxb33zppr1qxmi-user-environment"),("preferLocalBuild","1"),("system","builtin")])

I am trying to follow the chain and see where user-environment is coming from, but… if there are any ideas I would be curious to hear them!


Oh hoh hoh… from the docs on nix profile:

The default profile used by nix profile is $HOME/.nix-profile, which, if it does not exist, is created as a symlink to 
    /nix/var/nix/profiles/default if Nix is invoked by the root user, or 
    ${XDG_STATE_HOME-$HOME/.local/state}/nix/profiles/profile otherwise.

So this is the root user profile that is finding its way into my environment because my user doesn’t have its own profile? The config says that my default should be ${XDG_STATE_HOME-$HOME/.local/state}/nix/profiles/profile instead, and that is indeed full of a bunch of stuff:

❯ ls ~/.local/state/nix/profiles
channels@         home-manager-1-link@   home-manager-13-link@  home-manager-4-link@  home-manager-8-link@  profile-2-link@
channels-3-link@  home-manager-10-link@  home-manager-14-link@  home-manager-5-link@  home-manager-9-link@
channels-4-link@  home-manager-11-link@  home-manager-2-link@   home-manager-6-link@  profile@
home-manager@     home-manager-12-link@  home-manager-3-link@   home-manager-7-link@  profile-1-link@

And it looks like those are managed by home-manager, so… they are probably active somehow? Anyway, I deleted the ~/.nix-profile symlink (which I think was pointing to the default root profile, I don’t remember), but it didn’t change anything. Then I checked where my “correct” profile was pointing:

❯ ls -la ~/.local/state/nix/profiles/profile
lrwxr-xr-x 1 pol staff 14 Jul 21 16:04 /Users/pol/.local/state/nix/profiles/profile -> profile-2-link/

❯ ls -la ~/.local/state/nix/profiles/profile-2-link
lrwxr-xr-x 1 pol staff 60 Jul 21 16:04 /Users/pol/.local/state/nix/profiles/profile-2-link -> /nix/store/57904rflsfh46y7fxi62rzc7sidc9vmq-user-environment/

Weird sym-link redirection aside, there is nothing in this folder but an empty list manifest.nix file.

So my questions still stand: I am shooting in the dark.


I am still not clear on what nix profiles are exactly and how they work, any tips would be appreciated, since I think that’s the problem here.

I dont think anything is wrong.

You have one nix from the installation and one from the build as a dependency.
I think its handy to have the one from installation to fallback on if something goes wrong

There is more information here regarding this a nix-darwin

You’re right either use profiles or home-manager. You can use both but it gets confusing.

Either use channels or flakes. Flakes just makes it easier.

Nix-Darwin should be working. However, development stalled I think it’s getting started again there are more developers and helpers just needs organising…

Perhaps take it in steps use Nix for awhile before adding nix-darwin and home-manager. There is a bit of a learning curve and I think it really helps to learn the nix language.

1 Like

Please post the output of

(IFS=: ; for path in $PATH ; do ls -lA $path/nix 2>/dev/null ; done)

Yeah, this is how I first investigated the two nix binaries in my path, though, I have to point this out, sometimes in ZSH the IFS doesn’t work like you expect it to. By that I mean it is completely ignored. This is very frustrating if you are used to the invocation of using IFS=: to split the PATH variable and do stuff.

I am not sure if I have a zsh setting or something configured that ignores IFS functionality, but the way to do this in my ZFS would be to use the @s split string transformation:

❯ for p in ${(@s/:/)PATH}; do ls -lA ${p}/nix 2>/dev/null; done
lrwxr-xr-x 1 root wheel 62 Dec 31  1969 /run/current-system/sw/bin/nix -> /nix/store/sz4iql3xjjjmi7b7l9m8p0gs7plymrj1-nix-2.15.1/bin/nix*
-r-xr-xr-x 1 root nixbld 3014752 Dec 31  1969 /nix/var/nix/profiles/default/bin/nix*

But yeah, I have now determined that nix-darwin is managing the current-system nix as part of what it is doing. I am using flakes, and that is using the experimental nix profile style profiles (in ~/.local/) which are different than the ones in /nix/var/nix/profiles.

The question now is, what is putting /nix/var/nix/profiles/default/bin into my PATH?

I think I am going to try to uninstall nix-darwin and home-manager and see what happens, because I can’t find where that path is added to my PATH variable. I think it is being added by the /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh as this line is hardcoded:

export PATH="$NIX_LINK/bin:/nix/var/nix/profiles/default/bin:$PATH"

So if that nix-daemon.sh is executed, then that default/bin will be in my path, and it will fight with the dependent nix binary installed by nix-darwin into current-system. But, I can’t find where this is actually executed, it doesn’t show up in the zsh places where I would expect.

The issue has already been linked in this thread, but I want to call out LnL7’s response there:

When going through the nix-darwin installer the originally installed nix is not removed from the default profile, but while nix-darwin is used the version of nix specified declaratively will always have priority so this warning from nix doctor is not a problem at all. Keeping the version around in the expected location makes it easier for people to roll back to a still working nix installation if they want to stop using a declarative system configuration.

If you want to disable usage of profiles you can do so, which will result in these locations to not be exposed in environment variables like PATH. Alternatively you can delete the package from the default profile as you did.

  environment.profiles = mkForce [];

It looks like you’ve connected most of these dots already, but AFAIK both the official and detsys Nix installers set up a default profile that starts off with just Nix in it. Nix-darwin is adding current-system, which is basically the same idiom used in NixOS.

As LnL7 notes:

  • this shouldn’t be a problem (though the output of nix doctor certainly makes it sound like one…)
  • you can delete the package from the profile (or even remove the profile entirely), but one consequence is that you may not have a Nix on PATH if you subsequently uninstalled nix-darwin.

This check itself has been around for nearly 5 years already:

I think this thread is demonstrating that nix doctor could be doing something smarter here (even if that’s just updating the message to add context). The status quo is setting people up for having to understand a lot of Nix concepts when they really just want to know the install worked…

I don’t think you need to do this unless you have reason to believe this is the cause of some acute trouble.


I got lazy and just ignored it. I understand now what is happening, and it’s interesting to theorize how it could have been avoided (nix-darwin could have used the default profile maybe?). Either way, it hasn’t caused any issues for me other than making nix doctor look bad.

I totally understand how having two different nix binaries in your path could be really bad if they were very different versions. I am not sure how easy/hard it is to corrupt a nix-store, but… yeah. I get why having more than one in the PATH is a warnable situation.

I still don’t totally understand how to manage profiles (what they are, how they are created/destroyed, what their scopes are, when they are activated, how many can be active at the same time, etc). Looking in my ~/.local directly just confuses me even more. :slight_smile:

I’ll chase it down some day, but for now I am good.

Thanks so much for the excellent response!

1 Like