`nix-collect-garbage -d` not deleting everything that it should

I recently updated my system by:

  1. Updating the root channel with nix-channel --update

  2. Upgrading the nixos installation with nixos-rebuild --upgrade boot

  3. Rebooting in the new system

After that, I tried to purge the old system by doing nix-collect-garbage -d as root. And it did not delete the old system completely:

[$] ls /nix/store/*nixos-system-nixos* -d                                                                                                                    
/nix/store/1827aq1czj22gkcq71cy4057ik3w720a-nixos-system-nixos-19.09.976.c75de8bc12c.drv
/nix/store/9wxxzxpp82f5mnn3px0489pzsirrvag5-nixos-system-nixos-19.09.2218.a81842b6994.drv
/nix/store/avsckp16ggsjb2biiagmgg080an6rw2d-nixos-system-nixos-19.09.976.c75de8bc12c
/nix/store/g2g3fdvia9x5asrzny9n9zbjywlzmlwm-nixos-system-nixos-19.09.976.c75de8bc12c.drv
/nix/store/x8v3pfjf70sncbmw5sd0sa87ds82g2z7-nixos-system-nixos-19.09.976.c75de8bc12c
/nix/store/zc04hz2v6x55amngwba7cf9nr17snqsv-nixos-system-nixos-19.09.2218.a81842b6994
[$]                                                                                                                                                          

There are still two derivations from the old system (19.09.976.c75de8bc12c). No other derivation refers to these derivations. Why weren’t these derivations deleted as well?

Have you checked if they are perhaps still referenced in a user’s profile?

Or from a nix build you did and didn’t delete the result link?

You can check in /nix/var/nix/{profiles,gcroots}/per-user/* if there are any links pointing to those old configurations.

Be aware that they are not necessarily referenced directly, but might be a transient dependency of what is linked from there.

1 Like