NixOS: automatically collect garbage

categories
NixOS

The following enables automatic periodic garbage collection:

{
  nix.gc.automatic = true;
}

The default behavior (as of <2025-06-15 Sun>) is to collect garbage daily at 3:15. This can be configured via nix.gc.dates, which (according to the configuration.nix man page) takes “a calendar event in the format specified by ~systemd.time~” or a list of such. “For most desktop and server systems a sufficient garbage collection is once a week”, so:

{
  nix.gc.dates = "weekly";
}

Author: Nicholas Coltharp

Created: 2025-07-19 Sat 00:00

Validate