Subject:

nixos update shell script


Date: Message-Id: https://www.5snb.club/posts/2024/nixos-update-script/

I use a nix flakes setup to manage my system as a whole, so I have a flake.lock in my dotfiles which makes up 50% of my commits to just update it. I wrote these scripts to help make updating my system a bit nicer.

update.sh
#!/usr/bin/env bash

nix flake update --commit-lock-file
./diff.sh HEAD^ HEAD
diff.sh
#!/usr/bin/env bash
set -e

OLD=$(git rev-parse "$1")
NEW=$(git rev-parse "$2")

OUT_DIR=$(mktemp -d)
OLD_LINK="$OUT_DIR/old"
NEW_LINK="$OUT_DIR/new"

trap 'rm --force $OLD_LINK $NEW_LINK && rmdir $OUT_DIR' EXIT

toplevel="nixosConfigurations.nixos.config.system.build.toplevel"

nix build "./?rev=$OLD#$toplevel" --out-link "$OLD_LINK" --quiet
nix build "./?rev=$NEW#$toplevel" --out-link "$NEW_LINK" --quiet

nix store diff-closures "$OLD_LINK" "$NEW_LINK"

Usage is ./update.sh, and ./diff.sh old_rev new_rev (where old/new_rev can be any git revision, like HEAD~4 or a tag/branch name).

This gives an output like:

chromium: 126.0.6478.55 → 126.0.6478.61
chromium-unwrapped: 126.0.6478.55 → 126.0.6478.61
electron: 30.0.6 → 30.1.1
electron-unwrapped: 30.0.6 → 30.1.1, -168.7 KiB
firefox: 127.0 → 127.0.1
firefox-unwrapped: 127.0 → 127.0.1, +11.4 KiB
iniparser: 4.1 → 4.2.3, +426.2 KiB
initrd-kmod-blacklist: ∅ → ε
initrd-linux: 6.6.33 → 6.6.34
libvlc: 3.0.20 → 3.0.21, +11.0 KiB
linux: 6.6.33, 6.6.33-modules → 6.6.34, 6.6.34-modules, -14.6 KiB
nixos-system-nixos: 3fcf3f779b-24.05.20240615.752c634 → ∅, -64.6 KiB
nixos-system-nixos-c3530d27d1: ∅ → 24.05.20240619.dd457de, +64.6 KiB
source: +35.3 KiB
telegram-desktop: 5.1.5 → 5.1.7, +25.4 KiB
thunderbird: 115.11.0 → 115.12.0
thunderbird-unwrapped: 115.11.0 → 115.12.0, +11.1 KiB
tor-browser: 13.0.15 → 13.0.16, +8.6 KiB

It’s quite useful at keeping track of what actually changed. Documentation on the output format is https://nix.dev/manual/nix/2.22/command-ref/new-cli/nix3-store-diff-closures

Remember you still need to switch to the new system, this does not do that for you.