modules/nixos/common/update: cancel unnecessary reboots

this is needed if the host is updated to a newer generation that doesn't require a reboot or is reverted to the current generation
This commit is contained in:
zowoq 2025-01-05 13:56:30 +10:00
parent 55ea0aed0f
commit 8528527e06

View file

@ -2,7 +2,15 @@ arch=$(uname -m)
hostname=$(uname -n)
p=$(curl -L https://buildbot.nix-community.org/nix-outputs/nix-community/infra/master/"$arch"-linux.host-"$hostname")
cancel_reboot() {
if [[ -e /run/systemd/shutdown/scheduled ]]; then
shutdown -c
kexec --unload
fi
}
if [[ "$(readlink /run/current-system)" == "$p" ]]; then
cancel_reboot
exit 0
fi
@ -26,5 +34,6 @@ if [[ $booted != "$built" ]]; then
shutdown -r "+$(shuf -i 5-60 -n 1)"
fi
else
cancel_reboot
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
fi