Pkgs and storage space: How can I find out how much storage a package uses?

How do I find out how much storage a package uses once it’s installed via nixos config file?

I’ve used Disk Usage Analyzer (baobab), analyzed my / (nixos/nix/store/ and etc.), and it’s hard to understand.

nix-store --query --size /nix/store/some-package is the short answer.

The longer answer is, it depends on why you want to know, for two reasons:

  • A particular package may have files identical to those in another version of that package, and in that case store optimization may make one such file a hard link to the other. When that happens, one of the files effectively takes zero space, but which one counts as ‘zero’ is an accounting question, not a technical one — the two hard links are identical.
  • You may or may not be interested in the full closure of a package, and not just the package itself. Of course, packages in the closure may be on your disk for multiple reasons.

For a more sophisticated analysis, use nix-du, and be prepared to think harder about the question than you would probably like to.

I’m working with computers with different size storage (128GB, 256GB, 1TB, and etc.), and I’m trying to determine which packages I need to essentially keep, and which ones I don’t.

For instance, I have Firefox, Gnome Web, and Chromium browsers installed, in case someone had a preference, but if I had to cut one or two of these from the config, knowing the size could help me make the determination.

Another example is having multiple audio DAWs in a config, or file managers, and etc.

I also figured this might be the case.

If you’re only looking for hints on how much space you might free up by removing a program from your config, I recommend nix-tree.

nix-tree shows two sizes for each package: an unparenthesized size of that package’s entire closure, and a parenthesized size of just that package and its unique dependencies. AFAIK, neither takes store optimization into account, but ignoring that, the two sizes are upper and lower bounds, respectively, for how much space you could save by removing that package along with others.

1 Like