diff --git a/README.md b/README.md index 4aadffb..cb76137 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,11 @@ Connection to itchy.scratchy.com closed. built a lot of the paths from the previous deployment. However, if the remote has a slow upload bandwidth, this would not be a good idea to enable. +- `reboot` *`bool`* + + Whether to reboot the remote host if a newer kernel is available. Defaults to + false. + # Project Principles * No Premature Optimization: Make it work, then optimize it later if the diff --git a/flake.nix b/flake.nix index 5a39796..b56fae6 100644 --- a/flake.nix +++ b/flake.nix @@ -42,6 +42,7 @@ substituteOnTarget = n.substituteOnTarget or false; switch = if dryRun then "dry-activate" else "switch"; nixOptions = concatStringsSep " " (n.nixOptions or []); + reboot = if ! dryRun then n.reboot or false else false; script = '' @@ -64,7 +65,13 @@ echo "🔨 Building system closure locally, copying it to remote store and activating it:" ( set -x; NIX_SSHOPTS="-t" ${flock} -w 60 /dev/shm/nixinate-${machine} ${nixos-rebuild} ${nixOptions} ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo ${optionalString substituteOnTarget "-s"} ) - ''); + '') + (if reboot then '' + ( if ! ${openssh} -t ${user}@${host} '[ "$(readlink /run/booted-system/{initrd,kernel,kernel-modules})" = "$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" ]' + then + echo "🙈 Rebooting host due to newer kernel:" + set -x; ${openssh} -t ${user}@${host} "sudo reboot" + fi ) + '' else ""); in final.writeScript "deploy-${machine}.sh" script; in {