How to know the build plan and store path without building a Nix expression?

Viewed 680

nix-build ... --no-out-link gives a path in the Nix store.

  • Is it possible to find out that path without actually building the expression ?

  • Is it possible to find out the dependencies and the planned build operations without building the expression ?

  • How could I find the answer myself ?

2 Answers

The Nix manual, "Building and testing" section refers to nix-build documentation, which in the last "Description" paragraph mentions it is a combination of nix-instantiate and nix-store -r.

nix-instantiate does not build. It only calculates the plan, in the form of a derivation and its closure:

$ nix-instantiate '<nixpkgs>' -A hello
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/20bc2g6gfn44p9wk98s30pm346pmz0x9-hello-2.10.drv

However, I prefer to use nix repl to explore Nix expressions:

$ nix repl '<nixpkgs>'
Loading '<nixpkgs>'...
Added 8623 variables.
nix-repl> hello.outPath
"/nix/store/nic2bl8ry6vfyxr9717983d5b2l4sn1c-hello-2.10"

Its tab completion is very helpful when exploring expressions.

man nix-store has the answer, and in particular the --query section.

To know the output path:

nix-store -q --outputs $(nix-instanciate default.nix)

To know the build-time dependencies:

nix-store -qR --include-outputs $(nix-instanciate default.nix)

As for a build plan, the closer I get is to use the --tree flag.

Note that nix-shell exposes a $out variable too, so another possible solution to the first bullet point would be:

nix-shell --pure --run 'echo $out' some-file.nix
Related