Add support for rebooting when a newer kernel is detected #27

Closed
adamcstephens wants to merge 1 commit from reboot into master
2 changed files with 13 additions and 1 deletions
Showing only changes of commit 3b2f2de09f - Show all commits

View file

@ -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

View file

@ -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
{