How can I optimize a store that looks like this?

I use shell.nix + direnv extensively to manage project dependencies, and my store looks like this, I tried nix-collect-garbage -d but it doesn’t do much, saving maybe 1GB or so.

So I’m looking for ways to optimize this more if possible…

The first place to start is nix-store --gc --print-roots

That will show you all the places that are currently holding things alive, which for your case will likely include a lot of project directories with .direnv caches.

If a project is idle, you can just remove that directory and let the store references be gc’d. In all probability, when you next pick up the project, your first step will be to update to current inputs anyway.

1 Like

This works, but there is no way to some form of deduplication for example?

Hi. There is a built-in mechanics for file-level deduplication for the nix store. See Nix Cookbook - NixOS Wiki

1 Like

Thanks will have a look at this