Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 python3,
4 buildEnv,
5 runCommandCC,
6 stdenv,
7 runCommand,
8 vapoursynth,
9 makeWrapper,
10 withPlugins,
11}:
12
13plugins:
14let
15 pythonEnvironment = python3.buildEnv.override { extraLibs = plugins; };
16
17 getRecursivePropagatedBuildInputs =
18 pkgs:
19 lib.flatten (
20 map (
21 pkg:
22 let
23 cleanPropagatedBuildInputs = lib.filter lib.isDerivation pkg.propagatedBuildInputs;
24 in
25 cleanPropagatedBuildInputs ++ (getRecursivePropagatedBuildInputs cleanPropagatedBuildInputs)
26 ) pkgs
27 );
28
29 deepPlugins = lib.unique (plugins ++ (getRecursivePropagatedBuildInputs plugins));
30
31 pluginsEnv = buildEnv {
32 name = "vapoursynth-plugins-env";
33 pathsToLink = [ "/lib/vapoursynth" ];
34 paths = deepPlugins;
35 };
36
37 # Override default plugin path through nixPluginDir symbol
38 nixPlugins =
39 runCommandCC "libvapoursynth-nix-plugins${ext}"
40 {
41 executable = true;
42 preferLocalBuild = true;
43 allowSubstitutes = false;
44 src = ''
45 char const nixPluginDir[] = "${pluginsEnv}/lib/vapoursynth";
46 '';
47 }
48 ''
49 $CC -x c -shared -fPIC - -o "$out" <<<"$src"
50 '';
51
52 ext = stdenv.hostPlatform.extensions.sharedLibrary;
53in
54if stdenv.hostPlatform.isDarwin then
55 vapoursynth.overrideAttrs (previousAttrs: {
56 pname = "vapoursynth-with-plugins";
57 configureFlags = (previousAttrs.configureFlags or [ ]) ++ [
58 "--with-plugindir=${pluginsEnv}/lib/vapoursynth"
59 ];
60 })
61else
62 runCommand "${vapoursynth.name}-with-plugins"
63 {
64 nativeBuildInputs = [ makeWrapper ];
65 passthru = {
66 inherit python3;
67 inherit (vapoursynth) src version;
68 withPlugins = plugins': withPlugins (plugins ++ plugins');
69 };
70 }
71 ''
72 mkdir -p \
73 $out/bin \
74 $out/lib/pkgconfig \
75 $out/lib/vapoursynth \
76 $out/${python3.sitePackages}
77
78 for textFile in \
79 lib/pkgconfig/vapoursynth{,-script}.pc \
80 lib/libvapoursynth.la \
81 lib/libvapoursynth-script.la \
82 ${python3.sitePackages}/vapoursynth.la
83 do
84 substitute ${vapoursynth}/$textFile $out/$textFile \
85 --replace "${vapoursynth}" "$out"
86 done
87
88 for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do
89 ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"}
90 done
91
92 for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do
93 ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"}
94 done
95
96 for binaryFile in \
97 lib/libvapoursynth${ext} \
98 lib/libvapoursynth-script${ext}.0.0.0
99 do
100 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
101 new_rpath="$old_rpath:$out/lib"
102 patchelf \
103 --set-rpath "$new_rpath" \
104 --output $out/$binaryFile \
105 ${vapoursynth}/$binaryFile
106 patchelf \
107 --add-needed libvapoursynth-nix-plugins${ext} \
108 $out/$binaryFile
109 done
110
111 for binaryFile in \
112 ${python3.sitePackages}/vapoursynth${ext} \
113 bin/.vspipe-wrapped
114 do
115 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
116 new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}"
117 patchelf \
118 --set-rpath "$new_rpath" \
119 --output $out/$binaryFile \
120 ${vapoursynth}/$binaryFile
121 done
122
123 ln -s ${nixPlugins} $out/lib/libvapoursynth-nix-plugins${ext}
124 ln -s ${vapoursynth}/include $out/include
125 ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth
126 ln -s \
127 libvapoursynth-script${ext}.0.0.0 \
128 $out/lib/libvapoursynth-script${ext}
129 ln -s \
130 libvapoursynth-script${ext}.0.0.0 \
131 $out/lib/libvapoursynth-script${ext}.0
132
133 makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \
134 --prefix PYTHONPATH : $out/${python3.sitePackages}
135 ''