Is there a way to safely delete these .tar.gz files from my nix store?

I wanted to free some disk space and I noticed that some programs have retained their .tar.gz files in the nix store (e.g Rust Rover — line 2 and 6):

Is this necessary for flawless operation of Nix or is there a way to remove the .tar.gz files safely?

Thanks in advance.

If it’s not referenced and it’s in the store it can be collected via nix-collect-garbage. If it cannot then it is referenced and you need to remove what is referencing it. You can use a bunch of tools for this. nix-tree is quite useful for interactively tracing. nix-store --query is helpful if you want to script it (man nix-store-query).

nix store delete <path> (experimental interface) or nix-store --delete <path> (stable) will safely attempt to delete the path.
If it still has referents, it won’t be deleted.

But yes, rather than manually pruning paths, running GC would be better. You will also want to delete old profile generations eventually.

If you’re on NixOS, this can be set up on a schedule: https://search.nixos.org/options?channel=25.11&query=nix.gc

1 Like