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

问题描述 投票:2回答:2

nix-build ... --no-out-link在Nix商店提供了一条路径。

  • 是否有可能在没有实际构建表达式的情况下找到该路径?
  • 是否有可能在不构建表达式的情况下找出依赖关系和计划的构建操作?
  • 我怎么能自己找到答案?
nix
2个回答
2
投票

Nix manual,“构建和测试”部分是指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

但是,我更喜欢使用nix repl来探索Nix表达式:

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

在浏览表达式时,它的选项卡完成非常有用。


0
投票

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

要知道输出路径:

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

要了解构建时依赖性:

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

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

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

nix-shell --pure --run 'echo $out' some-file.nix
© www.soinside.com 2019 - 2024. All rights reserved.