| 1 | { |
| 2 | config, |
| 3 | inputs, |
| 4 | lib, |
| 5 | pkgs, |
| 6 | ... |
| 7 | }: |
| 8 | |
| 9 | { |
| 10 | imports = [ |
| 11 | inputs.fast-nix-gc.nixosModules.default |
| 12 | ]; |
| 13 | |
| 14 | nix = { |
| 15 | # Backport of NixOS/nix#15992: a temp root registered while a GC is in its |
| 16 | # deletion phase was ignored, so hydra-builder's per-build AddTempRoot pins |
| 17 | # raced the hourly GC and inputs/outputs were collected mid-build |
| 18 | # (NixOS/hydra#1806). |
| 19 | package = pkgs.nix.appendPatches [ ./nix-gc-addtemproot-race.patch ]; |
| 20 | nrBuildUsers = config.nix.settings.max-jobs + 32; |
| 21 | |
| 22 | settings = { |
| 23 | accept-flake-config = false; |
| 24 | builders-use-substitutes = true; |
| 25 | extra-experimental-features = [ |
| 26 | "nix-command" |
| 27 | "flakes" |
| 28 | ]; |
| 29 | trusted-users = [ |
| 30 | "build" |
| 31 | "root" |
| 32 | ]; |
| 33 | max-silent-time = 10800; # 3h |
| 34 | }; |
| 35 | }; |
| 36 | |
| 37 | services.fast-nix-gc = { |
| 38 | enable = true; |
| 39 | automatic = true; |
| 40 | dates = "hourly"; |
| 41 | ensureFree = "30%"; # some breathing room for zfs |
| 42 | keepRecent = "24h"; |
| 43 | }; |
| 44 | |
| 45 | systemd.services.prune-stale-nix-builds = { |
| 46 | description = "Prune stale nix build roots"; |
| 47 | startAt = "hourly"; |
| 48 | unitConfig.Documentation = "https://github.com/NixOS/nix/issues/5207"; |
| 49 | serviceConfig = { |
| 50 | ExecStart = lib.concatStringsSep " " [ |
| 51 | (lib.getExe pkgs.findutils) |
| 52 | "/nix/var/nix/builds" |
| 53 | "-mindepth 1" |
| 54 | "-maxdepth 1" |
| 55 | "-type d" |
| 56 | "-mtime +1" # days |
| 57 | "-exec rm -rf {} +" |
| 58 | ]; |
| 59 | }; |
| 60 | }; |
| 61 | } |