Search code examples
nix

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


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 ?


Solution

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

    To know the output path:

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

    To know the build-time dependencies:

    nix-store -qR --include-outputs $(nix-instantiate 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