What is the difference, if any, between nix-collect-garbage and nix-store --gc?

:wave: I was reading Garbage Collection - Nix Reference Manual and noted it mentions nix-store --gc for garbage collection.

When I started using nix a few years back I learned nix-collect-garbage -d.

Now Iā€™m curious if any meaningful difference exists between the two. Or whether to prefer one form over another.

Any experience or ideas on the matter? Thanks!

https://nixos.org/manual/nix/stable/command-ref/nix-collect-garbage#description

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.

2 Likes