nix icon indicating copy to clipboard operation
nix copied to clipboard

Garbage collect a closure

Open domenkozar opened this issue 3 years ago • 8 comments

I'd like to give Nix a closure that I'd like to garbage collect leaf nodes up to the point it hits a live node.

Something like nix store delete --recursive <installable>.

domenkozar avatar Oct 29 '22 23:10 domenkozar

@edolstra shouldn't this delete the second path?

$ nix store delete /run/current-system /nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/zhx2jgcxczry9v3234viaywpc276ss2b-nixos-system-cherimoya-22.05pre-git' since it is still alive. To find out why, use: nix-store --query --roots

domenkozar avatar Oct 31 '22 15:10 domenkozar

Ohh, it does delete it but it says it didn't :laughing:

domenkozar avatar Oct 31 '22 15:10 domenkozar

Really? That would be very bad.

edolstra avatar Oct 31 '22 15:10 edolstra

$ nix-store -r /nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0

$ nix store delete /nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0 /run/current-system
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/zhx2jgcxczry9v3234viaywpc276ss2b-nixos-system-cherimoya-22.05pre-git' since it is still alive. To find out why, use: nix-store --query --roots

$ nix-store -r /nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0
this path will be fetched (10.09 MiB download, 13.55 MiB unpacked):
  /nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0
copying path '/nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0' from 'https://cache.nixos.org'...
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/2vigl5h3qja0ms9a4grbn7z71psz2vcl-abcl-1.9.0

domenkozar avatar Oct 31 '22 15:10 domenkozar

Just to clarify, by closure, you mean you want to be able to automatically delete exactly those paths printed by nix-store -qR? It is confusing why you refer to "live nodes" here. Nothing in the closure of a live path could ever be deleted, correct?

EDIT: I see what you mean I think. Some paths printed by nix-store -qR might not be deletable because they are also in the closure of a live path. So you would want those would be skipped.

tpwrules avatar Dec 20 '22 18:12 tpwrules

@edolstra what do you think about this approach by @thufschmitt https://github.com/tweag/nix/commit/0bb351b979689b19703a3cafbb8b7ca3dab69946

domenkozar avatar Feb 20 '23 09:02 domenkozar

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-23-nix-team-meeting-minutes-43/26758/1

nixos-discourse avatar Mar 27 '23 13:03 nixos-discourse

Is there plan to still address this issue?

takeda avatar Nov 24 '25 17:11 takeda