From 6cc03e337aa1d0222e5942f58839d965075a9781 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 21 Oct 2024 10:29:57 +0000 Subject: [PATCH] nix-gc: add `randomizedDelaySec` option There's no launchd equivalent to this option, so this is a no-op on Darwin. --- modules/services/nix-gc.nix | 13 +++++++++++++ tests/modules/services/nix-gc/basic.nix | 1 + tests/modules/services/nix-gc/expected.timer | 1 + 3 files changed, 15 insertions(+) diff --git a/modules/services/nix-gc.nix b/modules/services/nix-gc.nix index 50e8b6351..7789aeffb 100644 --- a/modules/services/nix-gc.nix +++ b/modules/services/nix-gc.nix @@ -81,6 +81,18 @@ in { ''; }; + randomizedDelaySec = lib.mkOption { + default = "0"; + type = lib.types.singleLineStr; + example = "45min"; + description = '' + Add a randomized delay before each garbage collection. + 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)` + ''; + }; + options = mkOption { type = types.nullOr types.str; default = null; @@ -121,6 +133,7 @@ in { Unit = { Description = "Nix Garbage Collector"; }; Timer = { OnCalendar = "${cfg.frequency}"; + RandomizedDelaySec = cfg.randomizedDelaySec; Persistent = cfg.persistent; Unit = "nix-gc.service"; }; diff --git a/tests/modules/services/nix-gc/basic.nix b/tests/modules/services/nix-gc/basic.nix index a06b67238..1fc019da7 100644 --- a/tests/modules/services/nix-gc/basic.nix +++ b/tests/modules/services/nix-gc/basic.nix @@ -4,6 +4,7 @@ nix.gc = { automatic = true; frequency = "monthly"; + randomizedDelaySec = "42min"; options = "--delete-older-than 30d --max-freed $((64 * 1024**3))"; }; diff --git a/tests/modules/services/nix-gc/expected.timer b/tests/modules/services/nix-gc/expected.timer index ef30df435..70232bb47 100644 --- a/tests/modules/services/nix-gc/expected.timer +++ b/tests/modules/services/nix-gc/expected.timer @@ -4,6 +4,7 @@ WantedBy=timers.target [Timer] OnCalendar=monthly Persistent=true +RandomizedDelaySec=42min Unit=nix-gc.service [Unit]