Nix dry run report

Is there a way to ask nix to produce a plan of what would have been done when a given command is executed?

For example before nix shell, nix run or nixos-rebuild switch I would sometimes like to see:

  • list caches that would be tried (in order)
  • list of packages that would be fetched with summary
  • list of packages that would be built with summary
  • global summary

Where summary contains:

  • total number of packages
  • estimated total download size

If it’s not possible right now then is it practically feasible to implement?

As a bonus, in some scenarios it would be extremely helpful if nix could suggest the following:

  • plan requires a build of package X
  • package X is available in cache Y however
  • it cannot be used because your configuration contains custom settings: Z…
1 Like

The estimated download size and the number of packages you will compile by yourself is only known after binary caches are queried, so your dry-run operation would still have to query the binary caches. Otherwise it looks reasonable.

Note that --dry-run does what you want after querying the binary cache:
After modifying nix-du in nixpkgs:

$  nix-build -A nix-du --dry-run
this derivation will be built:
these 51 paths will be fetched (153.85 MiB download, 1125.68 MiB unpacked):

Other commands have similar switches

1 Like

Ah, so the old nix-build and nix-env already have something like it. I still cannot find the equivalent for nix shell, nix run or nixos-rebuild. I use flakes for all my projects these days. I don’t install things on my profile, always system wide or use shells. Don’t remember last time I used nix-build or nix-env :sweat_smile:

Network queries or metadata downloads are completely fine. The only thing I dislike is when I run nix shell or nixos-rebuild switch, after a couple minutes I come back to see how it’s doing and turns out it’s compiling something big which I didn’t expect. I have no idea why, what else it’s going to build etc. In that case I’d often like to stop and investigate. What is the exact build/fetch plan, which caches are used, if suddenly a lot of things need to be build instead of fetched then why?

1 Like