43 lines
1.2 KiB
Nix
43 lines
1.2 KiB
Nix
{ pkgs, lib, config, ... }:
|
|
{
|
|
systemd.services.reboot-check = {
|
|
description = "Check if the system needs a reboot";
|
|
onFailure = [ "status-email@%n.service" ];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
};
|
|
script = ''
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})"
|
|
built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
|
|
|
|
indent()
|
|
{
|
|
while read line ; do
|
|
echo " $line"
|
|
done <<< "$1"
|
|
}
|
|
|
|
if [ "$booted" != "$built" ] ; then
|
|
echo "Booted kernel version"
|
|
indent "$booted"
|
|
echo "does not match currently active"
|
|
indent "$built"
|
|
echo "A reboot is required."
|
|
exit 1
|
|
fi
|
|
'';
|
|
};
|
|
|
|
systemd.timers.reboot-check = {
|
|
wantedBy = [ "timers.target" ];
|
|
enable = true;
|
|
timerConfig = {
|
|
Unit = "reboot-check.service";
|
|
OnCalendar = "*-*-* 18:30:00";
|
|
Persistent = true;
|
|
};
|
|
};
|
|
}
|