如何在不构建Nix表达式的情况下知道构建计划和存储路径?

not*_*eed 4 nix

nix-build ... --no-out-link给出 Nix 商店中的路径.

  • 是否有可能在不实际构建表达式的情况下找出该路径?

  • 是否可以在不构建表达式的情况下找出依赖关系和计划的构建操作?

  • 我怎样才能自己找到答案呢?

not*_*eed 5

man nix-store有答案,特别是该--query部分。

要知道输出路径:

nix-store -q --outputs $(nix-instantiate default.nix)
Run Code Online (Sandbox Code Playgroud)

要了解构建时依赖关系:

nix-store -qR --include-outputs $(nix-instantiate default.nix)
Run Code Online (Sandbox Code Playgroud)

至于构建计划,我越接近使用该--tree标志。

请注意,它也nix-shell公开了一个$out变量,因此第一个要点的另一个可能的解决方案是:

nix-shell --pure --run 'echo $out' some-file.nix
Run Code Online (Sandbox Code Playgroud)

  • 谢谢@noted。注意:您将 nix-instantiate 错误地拼写为 nix-instanciate。 (2认同)

Rob*_*ing 5

Nix 手册的“构建和测试”部分引用了文档,在最后一个“描述”段落中提到它是和nix-build的组合。nix-instantiatenix-store -r

nix-instantiate不建立。它仅以推导及其闭包的形式计算计划:

$ 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
Run Code Online (Sandbox Code Playgroud)

不过,我更喜欢用它nix repl来探索 Nix 表达式:

$ nix repl '<nixpkgs>'
Loading '<nixpkgs>'...
Added 8623 variables.
nix-repl> hello.outPath
"/nix/store/nic2bl8ry6vfyxr9717983d5b2l4sn1c-hello-2.10"
Run Code Online (Sandbox Code Playgroud)

在探索表达式时,它的制表符补全功能非常有用。