From f1b915373750f7bdc09cbdaa011d0f49efea6cc8 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 12 Mar 2022 20:55:33 +0100 Subject: rebuild-machines: period --- system-profiles/rebuild-machines/default.nix | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'system-profiles/rebuild-machines') diff --git a/system-profiles/rebuild-machines/default.nix b/system-profiles/rebuild-machines/default.nix index e2a15aae..68788023 100644 --- a/system-profiles/rebuild-machines/default.nix +++ b/system-profiles/rebuild-machines/default.nix @@ -90,6 +90,13 @@ in { format = "binary"; }; }; + + period = mkOption { + type = types.nullOr types.str; + description = "Call rebuild-${hostName} boot periodically"; + default = null; + example = "hourly"; + }; }; }; @@ -107,5 +114,27 @@ in { }; environment.systemPackages = [ rebuildScript ]; + + systemd.services."rebuild-${hostName}" = lib.mkIf (cfg.period != null) { + description = "Upgrade System on Next Boot"; + requisite = [ "network.target" ]; + after = [ "network.target" ]; + + restartIfChanged = false; + unitConfig.X-StopOnRemoval = false; + + serviceConfig = { + Type = "oneshot"; + ExecStart = "${rebuildScript}/bin/${cfg.scriptName} boot"; + }; + }; + + systemd.timers."rebuild-${hostName}" = lib.mkIf (cfg.period != null) { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = cfg.period; + Persistent = true; + }; + }; }; } -- cgit v1.2.3