Error: "X and Y have the same priority 5"

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)
pkgs/applications/video/kodi/addons/addon-update-script/default.nix:1
pkgs/build-support/dotnet/nuget-to-nix/default.nix:1
pkgs/applications/networking/browsers/tor-browser-bundle-bin/update.nix:1
pkgs/applications/editors/vscode/extensions/ms-python.python/default.nix:1
pkgs/applications/editors/emacs/elisp-packages/manual-packages/tsc/default.nix:1
pkgs/applications/virtualization/appvm/default.nix:1
pkgs/applications/misc/electrum/update.nix:1
pkgs/build-support/docker/default.nix:1
pkgs/development/ruby-modules/bundix/default.nix:1
pkgs/development/libraries/aws-c-mqtt/default.nix:1
pkgs/development/python-modules/spacy/models.nix:1
pkgs/development/python-modules/spacy/default.nix:1
pkgs/development/python-modules/nix-kernel/default.nix:1
pkgs/development/libraries/aws-c-s3/default.nix:1
pkgs/development/libraries/aws-crt-cpp/default.nix:1
pkgs/development/libraries/aws-c-auth/default.nix:1
pkgs/development/libraries/librsvg/default.nix:1
pkgs/development/libraries/libarchive/default.nix:1
pkgs/development/libraries/s2n-tls/default.nix:1
pkgs/development/libraries/aws-c-common/default.nix:1
pkgs/development/libraries/aws-c-http/default.nix:1
pkgs/development/libraries/aws-c-sdkutils/default.nix:1
pkgs/development/libraries/aws-c-compression/default.nix:1
pkgs/development/tools/wp4nix/default.nix:1
pkgs/development/tools/language-servers/nixd/default.nix:1
pkgs/development/tools/rust/crate2nix/default.nix:1
pkgs/development/tools/nc4nix/default.nix:1
pkgs/development/tools/misc/hydra/unstable.nix:1
pkgs/development/web/nodejs/update.nix:1
pkgs/common-updater/scripts.nix:1
pkgs/common-updater/unstable-updater.nix:1
pkgs/tools/package-management/nix-bundle/default.nix:1
pkgs/tools/package-management/harmonia/default.nix:1
pkgs/tools/package-management/nix-serve/default.nix:1
pkgs/tools/package-management/nix-eval-jobs/default.nix:1
pkgs/tools/package-management/nix-update/default.nix:1
pkgs/tools/package-management/nix-du/default.nix:1
pkgs/tools/package-management/nixpkgs-review/default.nix:1
pkgs/tools/package-management/nix-template/default.nix:1
pkgs/tools/package-management/nix/nix-perl.nix:1
pkgs/tools/typesetting/lowdown/default.nix:1
pkgs/tools/security/sbomnix/default.nix:1
pkgs/tools/security/vaultwarden/update.nix:1
pkgs/tools/security/tor/default.nix:1
pkgs/tools/security/tor/update.nix:1
pkgs/tools/security/vulnix/default.nix:1
pkgs/tools/nix/nixpkgs-hammering/default.nix:1
pkgs/tools/nix/devour-flake/default.nix:1
pkgs/tools/nix/nix-init/default.nix:1
pkgs/tools/misc/nix-direnv/default.nix:1
pkgs/os-specific/linux/nixos-rebuild/default.nix:1
51

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.