我正在制作一个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"https://stackoverflow.com/questions/68329265
复制相似问题