2

Is it possible to figure out the size of a derivation after building it? For example, after nixos-rebuild, how much space does the new derivation take, excluding any storage savings because of previous builds?

1
  • One approach: Get a list of dependencies for each, calculate the ones in common and the ones specific to each. And then get the size of each dependency. Sep 1, 2021 at 15:51

2 Answers 2

3

Try this:

nix-store -q --requisites `nix-build --no-out-link '<nixpkgs>' -A vim` | sort -uf | xargs du -ch | tail -1

I also like to look at:

for p in /nix/var/nix/profiles/system* /nix/var/nix/profiles/per-user/$USER/profile*
do
   echo -n $p" ⇒ "
   nix-store -q --requisites $p | sort -uf | xargs du -ch | tail -1
done

Obviously the size of the transitive closure of derivations heavily overlap (shared libs, etc.) so the numbers will always add to more than the total space usage. Still useful though.

4
  • This is closer than the other answer, but it doesn't show where the derivations corresponding to the generations listed by nix-env --list-generations are stored.
    – l0b0
    Oct 10, 2021 at 20:45
  • They're pinned by the symlinks /nix/var/nix/profiles/per-user/$USER/profile*
    – obadz
    Oct 12, 2021 at 17:04
  • Oh, nice! That does it, then :) nix-store -q --requisites /nix/var/nix/profiles/per-user/$USER/profile-1-link | sort -uf | xargs du -ch | tail -1
    – l0b0
    Oct 12, 2021 at 21:32
  • Or even for path in /nix/var/nix/profiles/per-user/$USER/profile-*; do nix-store -q --requisites "$path" | xargs du --si --total | tail --lines=1 | sed "s#total#${path}#"; done
    – l0b0
    Oct 12, 2021 at 21:39
3

You may want nix path-info (e.g., for emacs):

$ nix-build -A emacs '<nixpkgs>'
$ nix path-info -Sh ./result
/nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2   470.4M

From the Nix release notes:

nix path-info shows information about store paths, replacing nix-store -q. A useful feature is the option --closure-size (-S). For example, the following command show the closure sizes of every path in the current NixOS system closure, sorted by size:

nix path-info -rS /run/current-system | sort -nk2

See also the Nix manual on Installables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.