Files
Nomarchy/modules/nixos/gen-prune.nix
Bernardo Magri e4800d7d8e
Some checks failed
Check / eval (push) Has been cancelled
feat(nixos): prune system+HM gens after 14d, keep ≥3 past (#128)
Weekly nomarchy-gen-prune deletes only generations that are both older
than 14 days and beyond the three most recent past gens (current always
kept), for system and Home Manager profiles. Stock nix.gc no longer uses
--delete-older-than. checks.gen-prune covers selection self-test and
unit wiring; doctor points at the new tool when disk is tight.
2026-07-15 11:59:26 +01:00

42 lines
1.4 KiB
Nix

# #128 — weekly generation prune: system + Home Manager profiles.
# Policy: drop gens older than 14 days only when they are beyond the
# three most recent *past* generations (current always kept).
{ config, lib, pkgs, ... }:
{
config = {
environment.systemPackages = [ pkgs.nomarchy-gen-prune ];
# Stock nix.gc --delete-older-than has no keep-N floor and would fight
# this policy. Keep weekly store GC for dead paths only; generation
# selection is nomarchy-gen-prune's job.
nix.gc = {
automatic = lib.mkDefault true;
dates = lib.mkDefault "weekly";
# Empty options → collect unreferenced store paths only (no age-based
# profile generation wipe).
options = lib.mkDefault "";
};
systemd.services.nomarchy-gen-prune = {
description = "Prune old NixOS and Home Manager generations (14d, keep 3 past)";
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.nomarchy-gen-prune}/bin/nomarchy-gen-prune";
};
# After the stock store GC timer if both fire weekly.
after = [ "nix-gc.service" ];
};
systemd.timers.nomarchy-gen-prune = {
description = "Weekly Nix generation prune (Nomarchy #128)";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "weekly";
Persistent = true;
RandomizedDelaySec = "1h";
};
};
};
}