1 { lib, python3, buildEnv, writeText, runCommandCC, stdenv, runCommand
2 , vapoursynth, makeWrapper, withPlugins }:
5 pythonEnvironment = python3.buildEnv.override {
9 getRecursivePropagatedBuildInputs = pkgs: lib.flatten
11 (pkg: pkg.propagatedBuildInputs ++ (getRecursivePropagatedBuildInputs pkg.propagatedBuildInputs))
14 deepPlugins = plugins ++ (getRecursivePropagatedBuildInputs plugins);
16 pluginsEnv = buildEnv {
17 name = "vapoursynth-plugins-env";
18 pathsToLink = [ "/lib/vapoursynth" ];
23 source = writeText "vapoursynth-nix-plugins.c" ''
24 void VSLoadPluginsNix(void (*load)(void *data, const char *path), void *data) {
25 ${lib.concatMapStringsSep "" (path: "load(data, \"${path}/lib/vapoursynth\");") deepPlugins}
29 runCommandCC "vapoursynth-plugin-loader" {
31 preferLocalBuild = true;
32 allowSubstitutes = false;
35 $CC -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
38 ext = stdenv.targetPlatform.extensions.sharedLibrary;
40 runCommand "${vapoursynth.name}-with-plugins" {
41 nativeBuildInputs = [ makeWrapper ];
44 withPlugins = plugins': withPlugins (plugins ++ plugins');
50 $out/lib/vapoursynth \
51 $out/${python3.sitePackages}
54 lib/pkgconfig/vapoursynth{,-script}.pc \
55 lib/libvapoursynth.la \
56 lib/libvapoursynth-script.la \
57 ${python3.sitePackages}/vapoursynth.la
59 substitute ${vapoursynth}/$textFile $out/$textFile \
60 --replace "${vapoursynth}" "$out"
63 for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do
64 ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"}
67 for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do
68 ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"}
72 lib/libvapoursynth${ext} \
73 lib/libvapoursynth-script${ext}.0.0.0
75 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
76 new_rpath="$old_rpath:$out/lib"
78 --set-rpath "$new_rpath" \
79 --output $out/$binaryFile \
80 ${vapoursynth}/$binaryFile
82 --add-needed libvapoursynth-nix-plugins${ext} \
87 ${python3.sitePackages}/vapoursynth${ext} \
90 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
91 new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}"
93 --set-rpath "$new_rpath" \
94 --output $out/$binaryFile \
95 ${vapoursynth}/$binaryFile
99 ${pluginLoader}/lib/libvapoursynth-nix-plugins${ext} \
100 $out/lib/libvapoursynth-nix-plugins${ext}
101 ln -s ${vapoursynth}/include $out/include
102 ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth
104 libvapoursynth-script${ext}.0.0.0 \
105 $out/lib/libvapoursynth-script${ext}
107 libvapoursynth-script${ext}.0.0.0 \
108 $out/lib/libvapoursynth-script${ext}.0
110 makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \
111 --prefix PYTHONPATH : $out/${python3.sitePackages}