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?
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.
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-infoshows information about store paths, replacing
nix-store -q. A useful feature is the option
-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.