diff --git a/modules/services.nix b/modules/services.nix index 698c4df..7969c7a 100644 --- a/modules/services.nix +++ b/modules/services.nix @@ -151,5 +151,23 @@ Persistent = true; }; }; + services."nix-prune-generations" = { + description = "Keep only 5 system generations and run nix-collect-garbage"; + serviceConfig = { + Type = "oneshot"; + ExecStart = '' + ${pkgs.nix}/bin/nix-env -p /nix/var/nix/profiles/system --delete-generations +5 || true + ${pkgs.nix}/bin/nix-collect-garbage -d || true + ''; + Nice = "10"; + }; + }; + timers."nix-prune-generations" = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "weekly"; + Persistent = true; + }; + }; }; }