Trying to upgrade nix ends up in downgrade

Hey folks,

I’ve been following the Nix manual, and stumbled upon this weird behaviour:

Following the instructions for Upgrading Nix I end up with what looks like a Nix downgrade:

$ sudo -i sh -c 'nix-channel --update && nix-env -iA nixpkgs.nix'
unpacking channels...
replacing old 'nix-2.15.0'
installing 'nix-2.13.3'

Checking the channels shows me I’m on unstable:

# (root shell)
$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable

A bit of Google around showed me that if I run the following, I get back to 2.15.0, but I’m totally confused about what’s going on:

# (root shell)
$ nix-env -u '*'
upgrading 'nix-2.13.3' to 'nix-2.15.0'

I left with the following questions in my mind:

  • Is the manual is out of date or makes assumption the user wants to upgrade to stable only?
  • Why do I get stable nix if my channel is unstable?
  • Why doesn’t nix-env -uA nixpkgs.nix work?

Bit of context: macOS user (multi-user install).

As 2.14 and 2.15 have some troubles currently (which are especially recognizeable in channel based setupts), the nix attribute in all channels is currently pointing to 2.13.x as the "recommended version.

I would currently not suggest to use something newer then that.

nix-env -u nix though will evaluate the entirety of nixpkgs, and search for the “packages” which have the same “name” (not attribute name but drv name!) and compare their versions and will take the highest, that it understands as stable.

I do not know the details, about which version schema is applied for the comparison or when a version is considered a “pre-release”.

But thats why nix-env -u “works” to get the latest version.

Be aware though, that there might be even deeper and nuanced differences between the commands, depending on how the demon is started on your system.

As 2.14 and 2.15 have some troubles currently (which are especially recognizeable in channel based setupts), the nix attribute in all channels is currently pointing to 2.13.x as the "recommended version.

Makes sense! The thing is, I got 2.15.0 installed because I think that’s what the installer script installed. The download page seem to point at 2.15.0 as well.

So I’m not sure why is that, probably a miscommunication of some sort.

and search for the “packages” which have the same “name” (not attribute name but drv name!)

Oh. While I’m still quite new to this, I think it makes sense to me. Thanks.

Be aware though, that there might be even deeper and nuanced differences between the commands, depending on how the demon is started on your system.

Good to know. Any chance you have any source of reference to that? Sadly the nix-manual and man pages only offer very a brief explanation about nix-daemon and the install section doesn’t mention anything.

On closer inspection:

$ tree /nix/var/nix/profiles/default-1-link
/nix/var/nix/profiles/default-1-link
├── Library -> /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/Library
├── bin -> /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/bin
├── etc -> /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/etc
├── lib -> /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/lib
├── libexec -> /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/libexec
├── manifest.nix -> /nix/store/f3kndih6bg1a9q64g6k0ybgnimfhi45k-env-manifest.nix
└── share -> /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/share

If I understand correctly, this means that generation one of my install had nix-2.13.3 and not 2.15.0 like I thought. So I guess somewhere along the way I upgraded to 2.15.0 by mistake and forgot about it.