`nix store gc` equivalent to `--delete-older-than`?

In the past, when I wanted to delete system generations older than 7 days, I’d run:

nix-collect-garbage --delete-older-than 7d

I’m in the process of switching my config to flakes and getting up to speed on using the new nix command, and it looks like the replacement for nix-collect-garbage is nix store gc, but how can I get it to delete system generations older than some specified age?

1 Like

I generally use these two commands on my flake based system.

nix-env --list-generations --profile /nix/var/nix/profiles/system
nix-env --delete-generations --profile /nix/var/nix/profiles/system 7d

There might be a more flaky way of doing it but I haven’t seen it yet.

The “modern” way would be nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 7d.

1 Like

Note that this only removes the old generations, but does not run a GC.

nix-collect-garbage --delete-older-than 7d

would translate into

nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 7d
nix store gc

lots more here List and delete NixOS generations too

There’s no reason you need to switch away from nix-collect-garbage just because you are using flakes. That command still works.