git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/nix-gc: add persistent and randomizeDelaySec options
commitdf3d5609998e47a98138259816a0db774d901189 authorMilan Svoboda <milan.svoboda@centrum.cz> dateWed 30 Dec 2020, 11:59 (6 years ago) parentf3ae13d
2 files changed+53−7
nixos/doc/manual/release-notes/rl-2105.xml+7 nixos/modules/services/misc/nix-gc.nix+46−7
nixos/doc/manual/release-notes/rl-2105.xml+7
@@ -738,6 +738,13 @@ self: super:
738738 terminology has been deprecated and should be replaced with Far/Near in the configuration file.
739739 </para>
740740 </listitem>
741+ <listitem>
742+ <para>
743+ The nix-gc service now accepts randomizedDelaySec (default: 0) and persistent (default: true) parameters.
744+ By default nix-gc will now run immediately if it would have been triggered at least
745+ once during the time when the timer was inactive.
746+ </para>
747+ </listitem>
741748 </itemizedlist>
742749 </section>
743750</section>
nixos/modules/services/misc/nix-gc.nix+46−7
@@ -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