at 22.05-pre 2.7 kB view raw
1{ config, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.nix.gc; 7in 8 9{ 10 11 ###### interface 12 13 options = { 14 15 nix.gc = { 16 17 automatic = mkOption { 18 default = false; 19 type = types.bool; 20 description = "Automatically run the garbage collector at a specific time."; 21 }; 22 23 dates = mkOption { 24 type = types.str; 25 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"; 39 type = types.str; 40 example = "45min"; 41 description = '' 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 45 <citerefentry><refentrytitle>systemd.time</refentrytitle> 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. 63 ''; 64 }; 65 66 options = mkOption { 67 default = ""; 68 example = "--max-freed $((64 * 1024**3))"; 69 type = types.str; 70 description = '' 71 Options given to <filename>nix-collect-garbage</filename> when the 72 garbage collector is run automatically. 73 ''; 74 }; 75 76 }; 77 78 }; 79 80 81 ###### implementation 82 83 config = { 84 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; 95 }; 96 }; 97 98 }; 99 100}