pkgs/nixfiles: automatic reboot for system sync to hydra
This commit is contained in:
parent
e711bc69a1
commit
b59909b155
@ -2,6 +2,21 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
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"
|
HYDRA_JOB_URL="https://hydra.clerie.de/job/nixfiles/nixfiles/nixosConfigurations.$(hostname)/latest-finished"
|
||||||
|
|
||||||
echo "Fetching job output from ${HYDRA_JOB_URL}"
|
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"
|
echo "Add to system profile"
|
||||||
nix-env -p "/nix/var/nix/profiles/system" --set "${STORE_PATH}"
|
nix-env -p "/nix/var/nix/profiles/system" --set "${STORE_PATH}"
|
||||||
|
|
||||||
echo "Activate system"
|
echo "Set as boot target"
|
||||||
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
|
/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"
|
echo "Finished system upgrade"
|
||||||
|
Loading…
Reference in New Issue
Block a user