1 { lib, python3, buildEnv, writeText, runCommandCC, stdenv, runCommand
2 , vapoursynth, makeWrapper, withPlugins }:
5 pythonEnvironment = python3.buildEnv.override {
9 getRecursivePropagatedBuildInputs = pkgs: lib.flatten
11 (pkg: let cleanPropagatedBuildInputs = lib.filter lib.isDerivation pkg.propagatedBuildInputs;
12 in cleanPropagatedBuildInputs ++ (getRecursivePropagatedBuildInputs cleanPropagatedBuildInputs))
15 deepPlugins = lib.unique (plugins ++ (getRecursivePropagatedBuildInputs plugins));
17 pluginsEnv = buildEnv {
18 name = "vapoursynth-plugins-env";
19 pathsToLink = [ "/lib/vapoursynth" ];
24 source = writeText "vapoursynth-nix-plugins.c" ''
25 void VSLoadPluginsNix(void (*load)(void *data, const char *path), void *data) {
26 ${lib.concatMapStringsSep "" (path: "load(data, \"${path}/lib/vapoursynth\");") deepPlugins}
30 runCommandCC "vapoursynth-plugin-loader" {
32 preferLocalBuild = true;
33 allowSubstitutes = false;
36 $CC -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
39 ext = stdenv.targetPlatform.extensions.sharedLibrary;
41 runCommand "${vapoursynth.name}-with-plugins" {
42 nativeBuildInputs = [ makeWrapper ];
45 inherit (vapoursynth) src version;
46 withPlugins = plugins': withPlugins (plugins ++ plugins');
52 $out/lib/vapoursynth \
53 $out/${python3.sitePackages}
56 lib/pkgconfig/vapoursynth{,-script}.pc \
57 lib/libvapoursynth.la \
58 lib/libvapoursynth-script.la \
59 ${python3.sitePackages}/vapoursynth.la
61 substitute ${vapoursynth}/$textFile $out/$textFile \
62 --replace "${vapoursynth}" "$out"
65 for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do
66 ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"}
69 for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do
70 ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"}
74 lib/libvapoursynth${ext} \
75 lib/libvapoursynth-script${ext}.0.0.0
77 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
78 new_rpath="$old_rpath:$out/lib"
80 --set-rpath "$new_rpath" \
81 --output $out/$binaryFile \
82 ${vapoursynth}/$binaryFile
84 --add-needed libvapoursynth-nix-plugins${ext} \
89 ${python3.sitePackages}/vapoursynth${ext} \
92 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
93 new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}"
95 --set-rpath "$new_rpath" \
96 --output $out/$binaryFile \
97 ${vapoursynth}/$binaryFile
101 ${pluginLoader}/lib/libvapoursynth-nix-plugins${ext} \
102 $out/lib/libvapoursynth-nix-plugins${ext}
103 ln -s ${vapoursynth}/include $out/include
104 ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth
106 libvapoursynth-script${ext}.0.0.0 \
107 $out/lib/libvapoursynth-script${ext}
109 libvapoursynth-script${ext}.0.0.0 \
110 $out/lib/libvapoursynth-script${ext}.0
112 makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \
113 --prefix PYTHONPATH : $out/${python3.sitePackages}