How do I auto-cleanup old Generations?

This is the command to delete all generations (backup systems) older than 3 days

sudo nix-collect-garbage --delete-older-than 3d

(There seems to be none for keeping x generations? That would be way more useful for me)

How can I easily make this run on every update? I have automatic updates enabled in a separate updates.nix config

{ config, lib, pkgs, inputs, ... }:
{
	system.autoUpgrade = {
		enable = true;
		flake = inputs.self.outPath;
		flags = [
			"nixpkgs"
			"-L" # print build logs
			];
			dates = "19:00";
			randomizedDelaySec = "45min";
	};
}

See the nix.gc options.

2 Likes

Thanks!

So in my case it would be

nix.gc.automatic = true;
nix.gc.date = "20:00";
nix.gc.options = "--delete-older-than 3d";

Persistent is already set, so the date is optional.