NixOS: automatically delete old profiles

categories
NixOS

Even if you configure NixOS to automatically collect garbage, it won't automatically delete old profiles. The solution is to pass a command line argument to nix-collect-garbage, which is what the automatic garbage collection service uses.

Probably you want to use either --delete-old (delete all generations other than the current one) or --delete-older-than (delete all generations older than a certain amount of time).

Deleting generations older than 1 month sounds like a reasonable default.

{
  nix.gc.options = "--delete-older-than 30d"
}

Author: Nicholas Coltharp

Created: 2025-07-19 Sat 00:00

Validate