35 lines
879 B
Nix
35 lines
879 B
Nix
{pkgs, ...}: let
|
|
shutdownWaitMinutes = 10;
|
|
shutdownScript = pkgs.writeShellScriptBin "shutdown-wait" ''
|
|
|
|
|
|
if [ -n "''${running}" ] && [ "''${running}" = "yes" ]; then
|
|
echo "backups are still running"
|
|
exit 1
|
|
fi
|
|
|
|
echo "WARNING: System will be shut down within the next ${builtins.toString shutdownWaitMinutes} minutes" | ${pkgs.util-linux}/bin/wall
|
|
|
|
sleep 10
|
|
|
|
shutdown -P +${builtins.toString shutdownWaitMinutes}
|
|
'';
|
|
in {
|
|
systemd.services."shutdown-after-backup" = {
|
|
enable = true;
|
|
serviceConfig = {
|
|
ExecStart = "${shutdownScript}/bin/shutdown-wait";
|
|
Type = "oneshot";
|
|
};
|
|
};
|
|
|
|
systemd.timers."shutdown-after-backup" = {
|
|
enable = true;
|
|
timerConfig = {
|
|
OnCalendar = "*-*-* 02..09:00,15,30,45:00 Etc/UTC";
|
|
};
|
|
wantedBy = ["timers.target"];
|
|
partOf = ["shutdown-after-backup.service"];
|
|
};
|
|
}
|