manual nix upgrade

2024-12-15 · 1 min read

(For a multi-user Linux install)

By default, sudo nix upgrade-nix will grab the new nix version from your nixpkgs flake registry entry, which should work for most people. If instead you need to install a specific nix daemon version...

Start by looking at the current system default profile:

$ nix profile history --profile /nix/var/nix/profiles/default
Version 1 (2024-08-03):
  nix: ∅ -> 2.18.5
  nss-cacert: ∅ -> 3.83

Version 2 (2024-11-03) <- 1: # <<< this is our current version
  nix: 2.18.5 -> 2.24.9

$ nix profile list --profile /nix/var/nix/profiles/default
Name:               nix
Store paths:        /nix/store/2nhrwv91g6ycpyxvhmvc0xs8p92wp4bk-nix-2.24.9

Name:               nss-cacert
Store paths:        /nix/store/ba4f8msp39cfvfpw3m7fsalb4psw347z-nss-cacert-3.83

Install the new nix version. In this case, I'm installing nixVersions.latest from a local nixpkgs checkout:

$ cd ~/dev/nixpkgs
$ nix eval -f . nixVersions.latest.version
"nix-2.28.3"

# remove the old version
$ sudo $(which nix) profile remove \
    --profile /nix/var/nix/profiles/default \
    nix

# install the new version
$ sudo $(which nix) profile install \
    --profile /nix/var/nix/profiles/default \
    -f . nixVersions.latest

# update CA certs
$ sudo $(which nix) profile remove \
    --profile /nix/var/nix/profiles/default \
    nss-cacert
$ sudo $(which nix) profile install \
    --profile /nix/var/nix/profiles/default \
    -f . cacert

Reload the nix daemon:

$ sudo systemctl daemon-reload \
    && sudo systemctl restart nix-daemon

Sanity check:

$ nix --version
nix (Nix) 2.28.3

$ nix store info
Store URL: daemon
Version: 2.28.3
Trusted: 0

If something goes horribly wrong, you can always rollback:

$ sudo $(which nix) profile rollback \
    --profile /nix/var/nix/profiles/default

If anything, you'll probably want to rollback before your next "normal" sudo nix upgrade-nix to keep things simple in the future.