Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, python3, buildEnv, writeText, runCommandCC, stdenv, runCommand 2, vapoursynth, makeWrapper, withPlugins }: 3 4plugins: let 5 pythonEnvironment = python3.buildEnv.override { 6 extraLibs = plugins; 7 }; 8 9 getRecursivePropagatedBuildInputs = pkgs: lib.flatten 10 (map 11 (pkg: let cleanPropagatedBuildInputs = lib.filter lib.isDerivation pkg.propagatedBuildInputs; 12 in cleanPropagatedBuildInputs ++ (getRecursivePropagatedBuildInputs cleanPropagatedBuildInputs)) 13 pkgs); 14 15 deepPlugins = lib.unique (plugins ++ (getRecursivePropagatedBuildInputs plugins)); 16 17 pluginsEnv = buildEnv { 18 name = "vapoursynth-plugins-env"; 19 pathsToLink = [ "/lib/vapoursynth" ]; 20 paths = deepPlugins; 21 }; 22 23 pluginLoader = let 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} 27 } 28 ''; 29 in 30 runCommandCC "vapoursynth-plugin-loader" { 31 executable = true; 32 preferLocalBuild = true; 33 allowSubstitutes = false; 34 } '' 35 mkdir -p $out/lib 36 $CC -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}" 37 ''; 38 39 ext = stdenv.targetPlatform.extensions.sharedLibrary; 40in 41runCommand "${vapoursynth.name}-with-plugins" { 42 nativeBuildInputs = [ makeWrapper ]; 43 passthru = { 44 inherit python3; 45 inherit (vapoursynth) src version; 46 withPlugins = plugins': withPlugins (plugins ++ plugins'); 47 }; 48} '' 49 mkdir -p \ 50 $out/bin \ 51 $out/lib/pkgconfig \ 52 $out/lib/vapoursynth \ 53 $out/${python3.sitePackages} 54 55 for textFile in \ 56 lib/pkgconfig/vapoursynth{,-script}.pc \ 57 lib/libvapoursynth.la \ 58 lib/libvapoursynth-script.la \ 59 ${python3.sitePackages}/vapoursynth.la 60 do 61 substitute ${vapoursynth}/$textFile $out/$textFile \ 62 --replace "${vapoursynth}" "$out" 63 done 64 65 for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do 66 ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"} 67 done 68 69 for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do 70 ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"} 71 done 72 73 for binaryFile in \ 74 lib/libvapoursynth${ext} \ 75 lib/libvapoursynth-script${ext}.0.0.0 76 do 77 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile) 78 new_rpath="$old_rpath:$out/lib" 79 patchelf \ 80 --set-rpath "$new_rpath" \ 81 --output $out/$binaryFile \ 82 ${vapoursynth}/$binaryFile 83 patchelf \ 84 --add-needed libvapoursynth-nix-plugins${ext} \ 85 $out/$binaryFile 86 done 87 88 for binaryFile in \ 89 ${python3.sitePackages}/vapoursynth${ext} \ 90 bin/.vspipe-wrapped 91 do 92 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile) 93 new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}" 94 patchelf \ 95 --set-rpath "$new_rpath" \ 96 --output $out/$binaryFile \ 97 ${vapoursynth}/$binaryFile 98 done 99 100 ln -s \ 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 105 ln -s \ 106 libvapoursynth-script${ext}.0.0.0 \ 107 $out/lib/libvapoursynth-script${ext} 108 ln -s \ 109 libvapoursynth-script${ext}.0.0.0 \ 110 $out/lib/libvapoursynth-script${ext}.0 111 112 makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \ 113 --prefix PYTHONPATH : $out/${python3.sitePackages} 114''