How to figure if NixOS build changed since boot?

Hello,

I’m wondering if it’s possible on NixOS to detect if the system has changed to another version since it booted? To make it simple, I’d like to detect if nixos-rebuild test / switch has been run.

The kernel version could be used, but it rarely change so it’s not very effective.

You can compare symlinks for /run/current-system and /run/booted-system.

2 Likes

You could also check /proc/cmdline for the init= parameter; that always points to the booted generation on NixOS, and it’s immutable.

1 Like

Thank you very much :+1:t3:

This check is also used by the autoUpdate module when deciding whether to reboot: nixpkgs/auto-upgrade.nix at f5357321bace1f2b8f47868414f9ff420cbef8c3 · NixOS/nixpkgs · GitHub

2 Likes

This will be very handy too :partying_face: