Garbage collect a closure
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>.
@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
Ohh, it does delete it but it says it didn't :laughing:
Really? That would be very bad.
$ 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
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.
@edolstra what do you think about this approach by @thufschmitt https://github.com/tweag/nix/commit/0bb351b979689b19703a3cafbb8b7ca3dab69946
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
Is there plan to still address this issue?