我正在制作一个haskell程序,我将buildInput设置为包含pkgs.ffmpeg-full
(myHaskellPackages.callCabal2nix "App" (./.) {}).overrideAttrs (oldAttrs: {
  buildInputs = (oldAttrs.buildInputs or []) ++ [ pkgs.ffmpeg-full ];
})然而,这似乎使ffmpeg包只能在构建时访问,而不是在应用程序的运行时访问。
要使ffmpeg-full在运行时可用,需要设置哪些属性--能够调用ffmpeg可执行文件?
在nix药丸中有一节是关于运行时依赖的,但我不明白这一节,它怎么能总是通过散列来确定运行时依赖呢?我的意思是,如果我在shell脚本中引用一个可执行文件,那么nix肯定不会解析shell脚本来确定我引用的可执行文件。https://nixos.org/guides/nix-pills/automatic-runtime-dependencies.html#idm140737320205792
但是,对于运行时依赖项,
是不同的。构建依赖关系一旦在任何派生调用中使用,就会被Nix自动识别,但我们从不指定派生的运行时依赖项是什么。
这里面真的有黑魔法。乍一看,这会让你觉得“不,从长远来看,这是行不通的”,但同时,它工作得非常好,以至于整个操作系统都建立在这个神奇的基础之上。
换句话说,Nix会自动计算派生的所有运行时依赖项,这是可能的,这要归功于存储路径的散列。。
发布于 2021-09-30 15:58:57
default.nix:
{
  ghc ? "ghc8106",
  pkgs ? import <nixpkgs> {}
}:
with pkgs.haskell.lib;
let
  haskellPkgs = pkgs.haskell.packages.${ghc};
  inherit (pkgs) lib;
  mySourceRegexes = [
    "^app.*$"
    "^.*\\.cabal$"
    "package.yaml"
  ];
  myApp = (haskellPkgs.callCabal2nix "my-hello"
    (lib.sourceByRegex ./. mySourceRegexes) { });
in myApp
   .overrideAttrs(
      oa: {
        nativeBuildInputs = oa.nativeBuildInputs ++ [pkgs.hello pkgs.makeWrapper];
        installPhase = oa.installPhase + ''
          ln -s ${pkgs.hello.out}/bin/hello $out/bin/hello
        '';
        postFixup = ''
          wrapProgram $out/bin/x-exe --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.hello ]}
        '';
      })src/Main.hs:
module Main where
import System.Process (callCommand)
main :: IO ()
main = do
  putStrLn "HELLO"
  callCommand "hello"
  putStrLn "BYE"发布于 2021-07-10 17:26:36
似乎没有明确声明的依赖项列表直接支持这一点。然而,我们可以通过“包装”间接地实现这一点。
我在这里找到了更多关于包装的信息:https://nixos.wiki/wiki/Nix_Cookbook#Wrapping_packages
所以我可以做一个引用包的ls。
...
appPkg = (myHaskellPackages.callCabal2nix "HaskellNixCabalStarter" (./.) {}).overrideAttrs (oldAttrs: {
  buildInputs = (oldAttrs.buildInputs or []) ++ [ pkgs.ffmpeg-full ];
  });
in
(pkgs.writeScriptBin "finderapp" ''
  #!${pkgs.stdenv.shell}
  ls ${pkgs.ffmpeg-full}/bin/ffmpeg
  exec ${appPkg}/bin/app
''
)我们可以验证构建的包(?)正确地取决于适当的和:
nix-store -q --references result
/nix/store/0cq84xic2absp75ciajv4lfx5ah1fb59-ffmpeg-full-4.2.2
/nix/store/rm1hz1lybxangc8sdl7xvzs5dcvigvf7-bash-4.4-p23
/nix/store/wlvnjx53xfangaa4m5rmabknjbgpvq3d-HaskellNixCabalStarter-0.1.0.0https://stackoverflow.com/questions/68329265
复制相似问题