1
0
Fork 0

pkgs/nixfiles: automatic reboot for system sync to hydra

This commit is contained in:
clerie 2023-11-05 18:24:37 +01:00
parent e711bc69a1
commit b59909b155
1 changed files with 35 additions and 2 deletions

View File

@ -2,6 +2,21 @@
set -euo pipefail
ALLOW_REBOOT=
while [[ $# -gt 0 ]]; do
case $1 in
--allow-reboot)
ALLOW_REBOOT=1
shift
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done
HYDRA_JOB_URL="https://hydra.clerie.de/job/nixfiles/nixfiles/nixosConfigurations.$(hostname)/latest-finished"
echo "Fetching job output from ${HYDRA_JOB_URL}"
@ -13,7 +28,25 @@ nix copy --from "https://nix-cache.clerie.de" "${STORE_PATH}"
echo "Add to system profile"
nix-env -p "/nix/var/nix/profiles/system" --set "${STORE_PATH}"
echo "Activate system"
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
echo "Set as boot target"
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
BOOTED_SYSTEM_KERNEL="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})"
ACTIVATING_SYSTEM_KERNEL="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
if [[ "$BOOTED_SYSTEM_KERNEL" != "$ACTIVATING_SYSTEM_KERNEL" ]]; then
echo "Reboot is required"
if [[ -n "$ALLOW_REBOOT" ]]; then
echo "Rebooting system now"
shutdown -r +1 "System update requires reboot"
else
echo "Automatic reboot not allowed (maybe use --allow-reboot next time)"
echo "The system upgrade is staged, please reboot manually soon"
fi
else
echo "No reboot is required"
echo "Activating system now"
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
fi
echo "Finished system upgrade"