Nix-env installs unexpected nix version

Hi,

I am using nix-env to install packages from nixpkgs to my Archlinux machine. The channel nixos-21.11 should contain Nix 2.3.16, however nix-env installs Nix 2.4. In order to exclude an issue in the channel logic, I’m explicitly using a --file parameter in this example:

~: nix eval --file ~/repositories/github.com/NixOS/nixpkgs nix.version
"2.3.16"

~: /nix/store/68a4al6chfnzcqwnyndavwx4aylxi0lm-nix-2.3.16/bin/nix-env --file ~/repositories/github.com/NixOS/nixpkgs --uninstall nix && /nix/store/68a4al6chfnzcqwnyndavwx4aylxi0lm-nix-2.3.16/bin/nix-env --file ~/repositories/github.com/NixOS/nixpkgs --install nix
uninstalling 'nix-2.4'
warning: there are multiple derivations named 'nix-2.4'; using the first one
installing 'nix-2.4'
building '/nix/store/xw1vi9q5ja16hp31h002i20pjyn0p2vq-user-environment.drv'...
created 897 symlinks in user environment

The git repository referenced in the nix-env command has the nixos-21.11 branch checked out, and the nix eval command confirms that this points to Nix 2.3.16. Still the nix-env (taken from some Nix 2.3 store path to be independent of the nix I am installing/uninstalling) installs Nix 2.4.

I tried nix-shell -p nix instead of nix-env, and it does give me a Nix 2.3.16.

I assume to see where nix-shell gets its nixpkgs, I can do nix-instantiate --eval -E '<nixpkgs>' which results in /home/jan/.nix-defexpr/channels/nixpkgs

~: nix eval --file /home/jan/.nix-defexpr/channels/nixpkgs nix.version
"2.3.16"

Nothing surprsing here. Still no clue why nix-env gives me a Nix 2.4 though.

Please try nix-env -iA nixpkgs.nix.

EDIT: or rather nix-env --file ~/repositories/github.com/NixOS/nixpkgs -iA nix

1 Like

--install without -A will do a “full text” search for derivations with the name nix and pick the one with the highest version.

Please use -A to specifiy the derivation by attribute name rather than derivation name.

Though nix-env will not remember that nix has been installed using the nix attribute. The next time you do an --update, nix will get updated to 2.4, as thats the higher version.

The best way to circumvent this issue is to not use nix-env to manage installed stuff, but instead any declarative approach, be it nixos, nix-darwin, home-manager or some workaround that uses nix-env as a low-level tool to build and manage a profile, rather than individual packages.

3 Likes