How to manage nix with nix-darwin (and maybe home-manager)

Hello everyone,

It appears that I have an older, imperatively installed Nix version that is taking precedence in my shell’s PATH, even though nix-darwin is managing my system.

Here are the details I’m observing:

1. Current which nix output:
My shell is picking up an older Nix executable:

› which nix
/Users/danielo/.nix-profile/bin/nix

2. nix doctor output (showing multiple Nix versions in PATH):

› nix doctor
warning: 'doctor' is a deprecated alias for 'config check'
[FAIL] Multiple versions of nix found in PATH:
  "/nix/store/c6jdhw0wdfn21s0r5i3s1r6dcr61iimf-nix-2.30.2/bin"
  "/nix/store/dfqs9x0l0r4dn7zjp1hymmv9wvpp9x2k-nix-2.26.2/bin"
  "/nix/store/k6lw097k81nj40abgj6xzncvbrvbbx0y-nix-2.25.5/bin"
[PASS] All profiles are gcroots.
[PASS] Client protocol matches store protocol.
[INFO] You are trusted by store uri: daemon

3. Inspection of ~/.nix-profile/bin/nix:
The nix executable in my user’s profile is a symlink to an older store path:

› ls -l ~/.nix-profile/bin/nix
lrwxr-xr-x@ - root  1 Jan  1970 /Users/danielo/.nix-profile/bin/nix -> /nix/store/k6lw097k81nj40abgj6xzncvbrvbbx0y-nix-2.25.5/bin/nix*

4. Inspection of the ~/.nix-profile symlink:
The user profile symlink itself also points to a generic profile-4-link:

› ls -l ~/.nix-profile/
lrwxr-xr-x@ - danielo 26 Feb 11:14 /Users/danielo/.nix-profile -> profile-4-link

5. nix-env --query and nix profile list for my user:
These commands show no imperatively installed packages for my user:

› nix-env --query
# (No output)

› nix profile list
# (No output)

6. nix-env --query and nix profile list for root (using sudo):
When run with sudo, a different set of imperatively installed packages (Nix 2.26.2 and nss-cacert) are shown:

› sudo nix-env --query
warning: $HOME ('/Users/danielo') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
nix-2.26.2
nss-cacert-3.107

› sudo nix profile list
warning: $HOME ('/Users/danielo') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
Name:          nix
Store paths:   /nix/store/dfqs9x0l0r4dn7zjp1hymmv9wvpp9x2k-nix-2.26.2

Name:          nss-cacert
Store paths:   /nix/store/jpj7i429d6v44ca9k1xpgyfq3kq3ng8z-nss-cacert-3.107

7. Attempt to use Determinate Systems uninstaller:
An attempt to use a Determinate Systems uninstaller (if present) failed, indicating nix-darwin was detected:

› sudo /nix/nix-installer uninstall
nix-darwin installation detected, it must be removed before uninstalling Nix. Please refer to [https://github.com/LnL7/nix-darwin#uninstalling](https://github.com/LnL7/nix-darwin#uninstalling) for instructions how to uninstall `nix-darwin`.

What should I do to correctly configure my system so that nix-darwin fully manages the Nix installation and its version in the PATH? How do I remove the older imperative installations.

Thanks in advance!

I see, darwin is not very popular around here… :grimacing:

IIRC I had this problem a couple years ago. I just uninstalled everything managed by nix-env, removed all the .nix-profile links, and GC. Maybe also try nix-sweep, remove all unwanted gc-roots and see what happens?

How did I installed anything using nix-env? I never issued any nix profile and nix-env command, how did it installed anything?

So is it safe to delete those? I don’t have time to spend in fixing my env if it fails

Just to keep track of what I did, I moved the profile (rather than deleting it) at my home directory to a new name, and indeed now I get the right Nix on my path. So far, I haven’t experienced any issues, but I would love to know what is the better way to make this removal definitive.