Unable to upgrade `nix` on NixOS

Today I updated my channels with nix-channel --update and after a reboot I was no longer able to use nix profile commands, but also not able to upgrade nix to a newer version.

λ nix profile list
error: profile manifest '/home/mathym/.local/state/nix/profiles/profile/manifest.json' has unsupported version 3

λ nix upgrade-nix --profile /home/mathym/.local/state/nix/profiles/profile
error: profile '/home/mathym/.local/state/nix/profiles/profile' is incompatible with 'nix-env'; please use 'nix profile' instead
error: program '/nix/store/v7gdmdc9yhx3ngh840xx5kr46840s73b-nix-2.18.2/bin/nix-env' failed with exit code 1

λ nix --version
nix (Nix) 2.18.2

What’s the best way to upgrade to a newer version of nix? I don’t mind backing up the programs installed into my profile and reinstalling them if I can’t update otherwise.

Set nix.package in your NixOS config and rebuild, if you want some version other than the current stable (2.18.x), but be aware that this can lead to regressions.

Not sure how your nix profile got broken like this, but in general, never run nix upgrade-nix on NixOS - you have a NixOS config for a reason. Managing nix imperatively is essentially fighting the benefits of using NixOS.

1 Like