| nix-collect-garbage(1) | General Commands Manual | nix-collect-garbage(1) |
nix-collect-garbage - delete unreachable store objects
nix-collect-garbage [--delete-old] [-d] [--delete-older-than period] [--max-freed bytes] [--dry-run]
The command nix-collect-garbage is mostly an alias of nix-store --gc. That is, it deletes all unreachable store objects in the Nix store to clean up your system.
However, it provides two additional options, --delete-old and --delete-older-than, which also delete old profiles, allowing potentially more store objects to be deleted because profiles are also garbage collection roots. These options are the equivalent of running nix-env --delete-generations with various augments on multiple profiles, prior to running nix-collect-garbage (or just nix-store --gc) without any flags.
Note
Deleting previous configurations makes rollbacks to them impossible.
These flags should be used with care, because they potentially delete generations of profiles used by other users on the system.
nix-collect-garbage cannot know about all profiles; that information doesn’t exist. Instead, it looks in a few locations, and acts on all profiles it finds there:
These options are for deleting old profiles prior to deleting unreachable store objects.
Keep deleting paths until at least bytes bytes have been deleted, then stop. The argument bytes can be followed by the multiplicative suffix K, M, G or T, denoting KiB, MiB, GiB or TiB units.
{{#include ./opt-common.md}}
{{#include ./env-common.md}}
To delete from the Nix store everything that is not used by the current generations of each profile, do
$ nix-collect-garbage -d