services.nix: delete old generations, automatically run gc

This commit is contained in:
2025-10-31 15:06:20 +01:00
parent d8bc9f12fb
commit a24a8ac966

View File

@@ -151,5 +151,23 @@
Persistent = true; 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;
};
};
}; };
} }