From 2bbdb2d50fe515cc9fde2b33b3b332f2cb7fbbd6 Mon Sep 17 00:00:00 2001 From: blargg Date: Sat, 15 May 2021 11:42:30 -0700 Subject: [PATCH] (nixos/systemd): Add Persistent for services. Persistent will check on startup if a timer trigger was missed while the timer was inactive and trigger the timer once if it was. This is useful for computers to catch up on missed automated tasks from while they were shut down. --- .../modules/system/boot/systemd-unit-options.nix | 15 +++++++++++++++ nixos/modules/system/boot/systemd.nix | 2 ++ 2 files changed, 17 insertions(+) diff --git a/nixos/modules/system/boot/systemd-unit-options.nix b/nixos/modules/system/boot/systemd-unit-options.nix index 4154389b2ce5fb..78f0d0f9e01ff1 100644 --- a/nixos/modules/system/boot/systemd-unit-options.nix +++ b/nixos/modules/system/boot/systemd-unit-options.nix @@ -371,6 +371,21 @@ in rec { apply = v: if isList v then v else [ v ]; }; + persistent = mkOption { + type = types.bool; + default = false; + example = "true"; + description = '' + When the timer is activated, trigger immediately if the timer would have + triggered at least once while the timer was inactive. Can be useful to + trigger missed runs of a service while the system was powered down. See + systemd.timer + 5. This is equivalent to adding a + corresponding timer unit with set to the + value given here. + ''; + }; + }; diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index d4ae4c93468f4a..6b914bb5bd2857 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -1134,6 +1134,7 @@ in mapAttrs (name: service: { wantedBy = [ "timers.target" ]; timerConfig.OnCalendar = service.startAt; + timerConfig.Persistent = service.persistent; }) (filterAttrs (name: service: service.enable && service.startAt != []) cfg.services); @@ -1142,6 +1143,7 @@ in mapAttrs (name: service: { wantedBy = [ "timers.target" ]; timerConfig.OnCalendar = service.startAt; + timerConfig.Persistent = service.persistent; }) (filterAttrs (name: service: service.startAt != []) cfg.user.services);