I’m running a multi-user installation of nix on macOS. Following the instructions here to upgrade nix, I ran into an error on the
nix-env -iA nixpkgs.nix step:
error: packages '/nix/store/h1ri3l45xxf42905bw7cgif85qr0445z-home-manager-path/share/zsh/site-functions/_nix' and '/nix/store/gqf7zhkx1n6sijax727ycrm57ikrv3pc-nix-2.15.1/share/zsh/site-functions/_nix' have the same priority 5; use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' to change the priority of one of the conflicting packages (0 being the highest priority)
Why am I getting this error? How can I work around it? This seems like a bug?
Attempting to follow the advice doesn’t work AFAIU:
❯ nix-env --set-flag priority 4 /nix/store/h1ri3l45xxf42905bw7cgif85qr0445z-home-manager-path/share/zsh/site-functions/_nix
error: selector '/nix/store/h1ri3l45xxf42905bw7cgif85qr0445z-home-manager-path/share/zsh/site-functions/_nix' matches no derivations
nix-env --set-flag priority 4 home-manager-path
did the trick for me, but I am still unsure why I got the error in the first place and which derivation should have been given priority.
As you found out refers to the installed name, not the store path.
The reason this happens is that the package
home-manager-path (I assume this is something internal to home manager) installed files into your profile that the package
nix also wants to install. Only one package can provide any given path, so this is a conflict that you need to resolve manually.
I guess the reason for this is that you already installed nix via home-manger? Or does home-manager do this by default?
In the former case, you should upgrade nix in your home-manager configuration, not with nix-env directly. In the latter, that does seem like somewhat surprising behaviour.
Ah wait, did you actually run
nix-env as sudo?
I thought this was about user’s profile, not system profile.
Yeah the weird part is AFAIK I’ve never installed nix via home-manager, so I wasn’t expecting home-manager and nix to conflict
True, but @samuela didn’t specify whether they were on a single- or multi-user install. I assumed multi-user, and in that case you’d have to upgrade nix with
sudo -i sh -c 'nix-channel --update && nix-env --install --attr nixpkgs.nix && launchctl remove org.nixos.nix-daemon && launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist'
Installing a new version of nix into your user profile on a multi-user install will also not update the nix daemon, which can lead to some confusing issues.
Hmm yeah and the installation docs for home-manager also assume that nix is already installed, so it shouldn’t install it by default. Maybe something else in your home-manager config depends on nix and installed it? When searching through nixpkgs (crudely), I find 51 packages that depend on nix directly:
$ rg -c '^, nix$' | tee >(wc -l)
Did you maybe install one of those?
The very first sentence of the thread says multi-user on macOS.
Oh wow yeah, must’ve skipped that now while re-reading. But then upgrading nix for sure should be done in the system profile.