【问题标题】:Nix: adding other derivation's subdirectory to PATHNix:将其他派生的子目录添加到 PATH
【发布时间】:2020-10-19 14:29:57
【问题描述】:

我想创建一个foo.nix 文件,当您nix-shell foo.nix 并进入沙盒外壳时,PATH 包含一些其他派生的bin/ 子目录。我该怎么做?

--- 最小的可重现示例 ---

以下是我迄今为止最好的尝试。

这是我当前的 .nix 文件

let git = builtins.fetchGit {
        url = https://github.com/ingun37/haskell-script.git;
        rev = "e96ac79d6bf338c98697bb4ba510f22cb5f502ac";
    };
    haskellScriptD = import git {};
in  derivation {
    name = "a"; # giving any name because I won't actually build it.
    builder = "a"; # Same here
    system = builtins.currentSystem;
    script = haskellScriptD;
}

这就是我为了在派生的bin/ 子目录中运行可执行文件而运行的。您可以看到我必须在可执行文件之前附加路径,因为我不知道如何配置 PATH。

nix-shell a.nix --run "\$script/bin/json-generator"

我要运行的是

nix-shell a.nix --run json-generator

我该怎么做?

【问题讨论】:

  • 您是真的在使用derivation 还是在使用stdenv.mkDerivation?您能否使用 nixpkgs 中的软件包提供 minimal reproducible example 而不是伪代码?这会很方便,因为我可以尝试编辑它的几行来尝试一些不同的想法,看看它们是否有效。
  • @DavidGrayson 我使用推导。
  • @DavidGrayson 我编辑了帖子以包含我使用的实际 nix 代码。
  • @DavidGrayson 当我没有实际构建它时,使用 mkDerivation 有什么意义吗?我只用它来设置沙盒外壳。
  • 嗯...您的最小示例从 Internet 中提取未知代码并运行它。无论如何,我认为您可以执行类似使用 stdenv.mkDerivation 之类的操作,并将您感兴趣的程序添加到 inputnativeInputs 属性中,这些属性应该是派生列表。

标签: nix


【解决方案1】:

感谢@DavidGrayson,我通过使用 stdenv.mkDerivative 而不是 derivative 并将导数包含到 buildInputs 中解决了这个问题。

这是工作脚本

with import <nixpkgs> {};
let git = builtins.fetchGit {
        url = https://github.com/ingun37/haskell-script.git;
        rev = "e96ac79d6bf338c98697bb4ba510f22cb5f502ac";
    };
    haskellScriptD = import git {};
in stdenv.mkDerivation {
    name = "a";
    buildInputs = [ haskellScriptD ];
}

现在我可以跑了

nix-shell a.nix --run json-generator

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 2010-10-14
    • 2014-09-15
    • 2020-01-21
    • 2011-08-07
    相关资源
    最近更新 更多