nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 21.11 113 lines 3.5 kB view raw
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 withPlugins = plugins': withPlugins (plugins ++ plugins'); 46 }; 47} '' 48 mkdir -p \ 49 $out/bin \ 50 $out/lib/pkgconfig \ 51 $out/lib/vapoursynth \ 52 $out/${python3.sitePackages} 53 54 for textFile in \ 55 lib/pkgconfig/vapoursynth{,-script}.pc \ 56 lib/libvapoursynth.la \ 57 lib/libvapoursynth-script.la \ 58 ${python3.sitePackages}/vapoursynth.la 59 do 60 substitute ${vapoursynth}/$textFile $out/$textFile \ 61 --replace "${vapoursynth}" "$out" 62 done 63 64 for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do 65 ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"} 66 done 67 68 for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do 69 ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"} 70 done 71 72 for binaryFile in \ 73 lib/libvapoursynth${ext} \ 74 lib/libvapoursynth-script${ext}.0.0.0 75 do 76 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile) 77 new_rpath="$old_rpath:$out/lib" 78 patchelf \ 79 --set-rpath "$new_rpath" \ 80 --output $out/$binaryFile \ 81 ${vapoursynth}/$binaryFile 82 patchelf \ 83 --add-needed libvapoursynth-nix-plugins${ext} \ 84 $out/$binaryFile 85 done 86 87 for binaryFile in \ 88 ${python3.sitePackages}/vapoursynth${ext} \ 89 bin/.vspipe-wrapped 90 do 91 old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile) 92 new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}" 93 patchelf \ 94 --set-rpath "$new_rpath" \ 95 --output $out/$binaryFile \ 96 ${vapoursynth}/$binaryFile 97 done 98 99 ln -s \ 100 ${pluginLoader}/lib/libvapoursynth-nix-plugins${ext} \ 101 $out/lib/libvapoursynth-nix-plugins${ext} 102 ln -s ${vapoursynth}/include $out/include 103 ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth 104 ln -s \ 105 libvapoursynth-script${ext}.0.0.0 \ 106 $out/lib/libvapoursynth-script${ext} 107 ln -s \ 108 libvapoursynth-script${ext}.0.0.0 \ 109 $out/lib/libvapoursynth-script${ext}.0 110 111 makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \ 112 --prefix PYTHONPATH : $out/${python3.sitePackages} 113''