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:
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.
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
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.
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.
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.