feat(nixos): prune system+HM gens after 14d, keep ≥3 past (#128)
Some checks failed
Check / eval (push) Has been cancelled

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.
This commit is contained in:
2026-07-15 11:59:26 +01:00
parent 1f6f21249e
commit e4800d7d8e
9 changed files with 344 additions and 45 deletions

View File

@@ -35,7 +35,11 @@ let
in if builtins.isBool v then v else null;
in
{
imports = [ ./options.nix ./plymouth.nix ./greeter.nix ./file-manager.nix ./power.nix ./services.nix ./hardware.nix ./timezone.nix ./oom.nix ];
imports = [
./options.nix ./plymouth.nix ./greeter.nix ./file-manager.nix
./power.nix ./services.nix ./hardware.nix ./timezone.nix ./oom.nix
./gen-prune.nix # #128 system+HM generation prune (14d, keep ≥3 past)
];
config = {
# Distro branding. distroName flows into /etc/os-release PRETTY_NAME,
@@ -512,11 +516,8 @@ in
# dirty" warning fires on every rebuild and is pure noise here.
warn-dirty = lib.mkDefault false;
};
gc = {
automatic = lib.mkDefault true;
dates = lib.mkDefault "weekly";
options = lib.mkDefault "--delete-older-than 14d";
};
# Generation age+floor policy + store GC: modules/nixos/gen-prune.nix (#128).
};
};
}

View File

@@ -0,0 +1,41 @@
# #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";
};
};
};
}