@@ -21,13 +21,45 @@ in
2121 };
2222
2323 dates = mkOption {
24+ type = types.str;
2425 default = "03:15";
26+ example = "weekly";
27+ description = ''
28+ How often or when garbage collection is performed. For most desktop and server systems
29+ a sufficient garbage collection is once a week.
30+
31+ The format is described in
32+ <citerefentry><refentrytitle>systemd.time</refentrytitle>
33+ <manvolnum>7</manvolnum></citerefentry>.
34+ '';
35+ };
36+
37+ randomizedDelaySec = mkOption {
38+ default = "0";
2539 type = types.str;
40+ example = "45min";
2641 description = ''
27− Specification (in the format described by
42+ Add a randomized delay before each automatic upgrade.
43+ The delay will be chosen between zero and this value.
44+ This value must be a time span in the format specified by
2845 <citerefentry><refentrytitle>systemd.time</refentrytitle>
29− <manvolnum>7</manvolnum></citerefentry>) of the time at
30− which the garbage collector will run.
46+ <manvolnum>7</manvolnum></citerefentry>
47+ '';
48+ };
49+
50+ persistent = mkOption {
51+ default = true;
52+ type = types.bool;
53+ example = false;
54+ description = ''
55+ Takes a boolean argument. If true, the time when the service
56+ unit was last triggered is stored on disk. When the timer is
57+ activated, the service unit is triggered immediately if it
58+ would have been triggered at least once during the time when
59+ the timer was inactive. Such triggering is nonetheless
60+ subject to the delay imposed by RandomizedDelaySec=. This is
61+ useful to catch up on missed runs of the service when the
62+ system was powered down.
3163 '';
3264 };
3365
@@ -50,11 +82,18 @@ in
5082
5183 config = {
5284
53− systemd.services.nix-gc =
54− { description = "Nix Garbage Collector";
55− script = "exec ${config.nix.package.out}/bin/nix-collect-garbage ${cfg.options}";
56− startAt = optional cfg.automatic cfg.dates;
85+ systemd.services.nix-gc = {
86+ description = "Nix Garbage Collector";
87+ script = "exec ${config.nix.package.out}/bin/nix-collect-garbage ${cfg.options}";
88+ startAt = optional cfg.automatic cfg.dates;
89+ };
90+
91+ systemd.timers.nix-gc = lib.mkIf cfg.automatic {
92+ timerConfig = {
93+ RandomizedDelaySec = cfg.randomizedDelaySec;
94+ Persistent = cfg.persistent;
5795 };
96+ };
5897
5998 };
6099