Nix:将其他派生的子目录添加到 PATH

Nix: adding other derivation's subdirectory to PATH

我想制作一个 foo.nix 文件,当您 nix-shell foo.nix 并进入沙盒 shell 时,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

我该怎么做?

感谢@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