Is it normal for nixpkgs to take double the amount of storage?

I’m still trying to understand NixOS, and while I was using Disk Analyzer to determine what’s taking a lot of storage, I noticed a lot of duplicates of some of my packages.

From the image above, you’ll notice certain programs installed more than once, such as:
stuntrally
redeclipse
speedreams
wesnoth
atom

Is it normal that Nix has multiple copies of one specific package, or do I need to optimize in someway?

Generally, I’ve occasionally only removed old generations and do garbage collection when needed, and it usually frees up tons of storage. But looking at my nixpkgs, is it normal to have these duplicate directories or installs?

I know nix filesystem is uniquely different, but feel free to chime in and explain that.

Thank you!

https://nixos.wiki/wiki/Storage_optimization

Nix may end up installing multiple copies depending on how many past revisions you have and how you invoke nix. With flakes and profiles you have to be extra careful. Luckily hardlinking saves a lot of space

In the future once CA derivations hopefully become q thing we might see less disk usage and bandwidth use

1 Like

Yea, when a package is updated (or indeed anything it depends on), it gets a whole new copy in your /nix/store. These stick around until 1) the generations referring to them are deleted, and 2) the garbage collector is run.

3 Likes

Another source of duplicates is that some packages require particular versions of their dependencies. To some extent this is unavoidable, but there are instances where simply no one took the time to weed those out. I’ve seen some statistics that the NixOS installer closure has grown substantially over the years, which is in part due to duplicates.

You can use GitHub - utdemir/nix-tree: Interactively browse dependency graphs of Nix derivations. to find out which store paths your closure contains.

4 Likes

Every time you build/update your NixOS setup, it keeps your previous configuration and packages in case you need to fall back to it. If you don’t need to, you can run as root nix-collect-garbage -d to delete them.

You can also squeeze some extra space by running as root nix-store --optimise.

Is there a difference between nix-store --gc and this one you’ve shown me?

https://nixos.org/manual/nix/unstable/command-ref/nix-store/gc

https://nixos.org/manual/nix/unstable/command-ref/nix-collect-garbage

The second one also deletes profile generations, which are garbage collector roots as well and would otherwise not be picked up.

1 Like

It seems and looks to be exactly the same, but nix-collect-garbage -d seems to clear more system stuff too

The “system stuff” is because nix-collect-garbage -d deletes profile generations, and NixOS uses profiles to persist previous versions of built configurations.