From 1af2f7506a31b05495d8b892fa1946cc9b959339 Mon Sep 17 00:00:00 2001 From: Stefan Frijters Date: Fri, 6 Dec 2024 10:59:19 +0100 Subject: [PATCH] nixos/nix-optimise: add randomizedDelaySec and persistent options This brings the options for nix-optimise more in line with those for nix-gc --- nixos/modules/services/misc/nix-optimise.nix | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/misc/nix-optimise.nix b/nixos/modules/services/misc/nix-optimise.nix index ed33f6746a4e..f3724a5a78cf 100644 --- a/nixos/modules/services/misc/nix-optimise.nix +++ b/nixos/modules/services/misc/nix-optimise.nix @@ -22,6 +22,34 @@ in which the optimiser will run. ''; }; + + randomizedDelaySec = lib.mkOption { + default = "1800"; + type = lib.types.singleLineStr; + example = "45min"; + description = '' + Add a randomized delay before the optimizer will run. + The delay will be chosen between zero and this value. + This value must be a time span in the format specified by + {manpage}`systemd.time(7)` + ''; + }; + + persistent = lib.mkOption { + default = true; + type = lib.types.bool; + example = false; + description = '' + Takes a boolean argument. If true, the time when the service + unit was last triggered is stored on disk. When the timer is + activated, the service unit is triggered immediately if it + would have been triggered at least once during the time when + the timer was inactive. Such triggering is nonetheless + subject to the delay imposed by RandomizedDelaySec=. This is + useful to catch up on missed runs of the service when the + system was powered down. + ''; + }; }; }; @@ -44,8 +72,8 @@ in timers.nix-optimise = lib.mkIf cfg.automatic { timerConfig = { - Persistent = true; - RandomizedDelaySec = 1800; + RandomizedDelaySec = cfg.randomizedDelaySec; + Persistent = cfg.persistent; }; }; };