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-10-11 23:27:07 +03:00
|
|
|
{
|
2024-11-04 04:37:29 +03:00
|
|
|
config,
|
|
|
|
const,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
secret,
|
|
|
|
util,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
cfg = config.module.autoupdate;
|
|
|
|
in {
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
programs.git = {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed;
|
|
|
|
};
|
|
|
|
};
|
2024-07-01 16:19:58 +03:00
|
|
|
|
2024-11-04 04:37:29 +03:00
|
|
|
systemd.services.autoupdate = util.mkStaticSystemdService {
|
|
|
|
enable = true;
|
|
|
|
description = "Signed system auto-update.";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
path = with pkgs; [
|
|
|
|
bash
|
|
|
|
coreutils
|
|
|
|
git
|
|
|
|
gnumake
|
|
|
|
nixos-rebuild
|
|
|
|
openssh
|
|
|
|
];
|
|
|
|
script = ''
|
|
|
|
pushd /tmp
|
|
|
|
rm -rf ./nixos
|
|
|
|
git clone --depth=1 --single-branch --branch=main ${const.url} ./nixos
|
|
|
|
pushd ./nixos
|
|
|
|
git verify-commit HEAD && git fsck || {
|
|
|
|
echo "Verification failed."
|
|
|
|
exit 1
|
|
|
|
};
|
|
|
|
timeout 55m make switch
|
|
|
|
'';
|
|
|
|
after = [
|
|
|
|
"network-online.target"
|
|
|
|
];
|
|
|
|
wants = [
|
|
|
|
"network-online.target"
|
|
|
|
];
|
|
|
|
};
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-11-04 04:37:29 +03:00
|
|
|
systemd.timers.autoupdate = {
|
|
|
|
enable = true;
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "hourly";
|
|
|
|
Persistent = true;
|
|
|
|
RandomizedDelaySec = 60;
|
|
|
|
Unit = "autoupdate.service";
|
|
|
|
};
|
|
|
|
wantedBy = [
|
|
|
|
"timers.target"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-04-14 19:44:38 +03:00
|
|
|
}
|