From a24a8ac96644dbaf8ca9727e54198fed601613d6 Mon Sep 17 00:00:00 2001 From: Roman Lubij Date: Fri, 31 Oct 2025 15:06:20 +0100 Subject: [PATCH] services.nix: delete old generations, automatically run gc --- modules/services.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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; + }; + }; }; }