2024-05-04 23:15:57 +03:00
|
|
|
# System automatic updates.
|
|
|
|
# This is a systemd service that pulls updates every hour.
|
|
|
|
# Unlike system.autoUpgrade, this script also verifies my git signature
|
|
|
|
# to prevent unathorized changes to hosts.
|
2024-05-10 20:34:15 +03:00
|
|
|
{ const, pkgs, lib, secret, util, ... }: {
|
|
|
|
systemd.services.autoupdate = util.mkStaticSystemdService {
|
|
|
|
enable = true;
|
|
|
|
description = "Signed system auto-update.";
|
2024-04-14 19:44:38 +03:00
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
path = with pkgs; [
|
|
|
|
bash
|
|
|
|
git
|
|
|
|
gnumake
|
|
|
|
nixos-rebuild
|
|
|
|
openssh
|
|
|
|
];
|
|
|
|
script = ''
|
|
|
|
pushd /tmp
|
|
|
|
rm -rf ./nixos
|
|
|
|
${lib.getExe pkgs.git} clone --depth=1 --single-branch --branch=main ${const.url} ./nixos
|
|
|
|
pushd ./nixos
|
|
|
|
${lib.getExe pkgs.git} verify-commit HEAD || {
|
|
|
|
echo "Verification failed."
|
|
|
|
exit 1
|
|
|
|
};
|
|
|
|
${lib.getExe pkgs.gnumake} switch
|
|
|
|
'';
|
2024-05-04 22:22:59 +03:00
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
2024-04-14 19:44:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.autoupdate = {
|
2024-06-14 03:22:51 +03:00
|
|
|
enable = true;
|
2024-04-14 19:44:38 +03:00
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "hourly";
|
|
|
|
Persistent = true;
|
|
|
|
Unit = "autoupdate.service";
|
2024-05-04 22:22:59 +03:00
|
|
|
# RandomizedDelaySec = 60;
|
2024-04-14 19:44:38 +03:00
|
|
|
};
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
};
|
|
|
|
}
|