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
~: /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
warning: there are multiple derivations named 'nix-2.4'; using the first one
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.
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
~: nix eval --file /home/jan/.nix-defexpr/channels/nixpkgs nix.version
Nothing surprsing here. Still no clue why
nix-env gives me a Nix 2.4 though.
nix-env -iA nixpkgs.nix.
EDIT: or rather
nix-env --file ~/repositories/github.com/NixOS/nixpkgs -iA nix
-A will do a “full text” search for derivations with the name
nix and pick the one with the highest version.
-A to specifiy the derivation by attribute name rather than derivation name.
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.