Skip to content

Commit

Permalink
nix-gc: add randomizedDelaySec option
Browse files Browse the repository at this point in the history
There's no launchd equivalent to this option, so this is a no-op on
Darwin.
  • Loading branch information
ambroisie committed Oct 21, 2024
1 parent c2cd2a5 commit 3296dad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/services/nix-gc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,6 +133,7 @@ in {
Unit = { Description = "Nix Garbage Collector"; };
Timer = {
OnCalendar = "${cfg.frequency}";
RandomizedDelaySec = cfg.randomizedDelaySec;
Persistent = cfg.persistent;
Unit = "nix-gc.service";
};
Expand Down
1 change: 1 addition & 0 deletions tests/modules/services/nix-gc/basic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
nix.gc = {
automatic = true;
frequency = "monthly";
randomizedDelaySec = "42min";
options = "--delete-older-than 30d --max-freed $((64 * 1024**3))";
};

Expand Down
1 change: 1 addition & 0 deletions tests/modules/services/nix-gc/expected.timer
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WantedBy=timers.target
[Timer]
OnCalendar=monthly
Persistent=true
RandomizedDelaySec=42min
Unit=nix-gc.service

[Unit]
Expand Down

0 comments on commit 3296dad

Please sign in to comment.