Reinstall Nix: nix-env incompatibility

I have a system on which Nix was installed using apt install nix-bin. I am attempting to reinstall Nix using the official install script (sh <(curl -L https://nixos.org/nix/install) --daemon). I removed Nix using apt remove nix*, but when I run the install script I get an error:

error: profile ‘/nix/var/nix/profiles/default’ is incompatible with ‘nix-env’; please use ‘nix profile’ instead.

I understand why this is happening - I believe it is occurring on line 924 of install-multi-user of the scripts downloaded by the original install script. We have installed packages on the original Nix installation using nix profile, but the official install script is running nix-env in order to configure the whole environment. Because we have run nix profile and are now trying to run nix-env, we are running into an incompatibility.

I also understand that I can fix this by removing the current profile directory. However, as I understand it, that will effectively uninstall my current packages.

Is there a way to reinstall Nix without having to reinstall my packages? I may be understanding Nix incorrectly and there is a way to restore my profile without reinstalling packages. I’d hope that Nix allows for a reinstall without starting over.

System: Ubuntu 22.04
Nix version: 2.16.1
multi-user: yes

It should be noted that I am using version 2.16.1, rather than 2.17.x that came out this week.

Can you check what readlink ~/.nix-profile returns? It should be something like /nix/var/nix/profiles/per-user/$USER. This is separate from the default profile, so removing the default profile won’t affect your installed packages.

Usually, the default profile only contains two packages: nix itself and nsscerts.

Additionally, the contents of the profile directories are only symlinks to directories in the nix store. So if you run readlink -f ~/.nix-profile and write down what it points to (should be a path starting with /nix/store, you can always re-link it later with ln -s.

2 Likes

Thanks for clarifying that for me!