about summary refs log tree commit diff
path: root/pkgs/by-name/va
diff options
context:
space:
mode:
authorMikael Voss2024-08-04 11:42:55 +0200
committerMikael Voss2024-08-04 11:54:59 +0200
commit2c487f5608a00ad2a39b8a098935a9af493b7f7c (patch)
tree0d3da6dc49e4140a48d01da81ad453032c00e260 /pkgs/by-name/va
parent3d87b65e3ffaf95b8d98fe26f0f53d75f58b6bf3 (diff)
vapoursynth: Reformat and move according to guidelines
Diffstat (limited to 'pkgs/by-name/va')
-rw-r--r--pkgs/by-name/va/vapoursynth/editor.nix80
-rw-r--r--pkgs/by-name/va/vapoursynth/nix-plugin-loader.patch28
-rw-r--r--pkgs/by-name/va/vapoursynth/package.nix107
-rw-r--r--pkgs/by-name/va/vapoursynth/plugin-interface.nix140
4 files changed, 355 insertions, 0 deletions
diff --git a/pkgs/by-name/va/vapoursynth/editor.nix b/pkgs/by-name/va/vapoursynth/editor.nix
new file mode 100644
index 000000000000..76f11ddf9788
--- /dev/null
+++ b/pkgs/by-name/va/vapoursynth/editor.nix
@@ -0,0 +1,80 @@
+{
+  lib,
+  mkDerivation,
+  fetchFromGitHub,
+  makeWrapper,
+  runCommand,
+  python3,
+  vapoursynth,
+  qmake,
+  qtbase,
+  qtwebsockets,
+}:
+
+let
+  unwrapped = mkDerivation rec {
+    pname = "vapoursynth-editor";
+    version = "R19-mod-4";
+
+    src = fetchFromGitHub {
+      owner = "YomikoR";
+      repo = pname;
+      rev = lib.toLower version;
+      sha256 = "sha256-+/9j9DJDGXbuTvE8ZXIu6wjcof39SyatS36Q6y9hLPg=";
+    };
+
+    nativeBuildInputs = [ qmake ];
+    buildInputs = [
+      qtbase
+      vapoursynth
+      qtwebsockets
+    ];
+
+    dontWrapQtApps = true;
+
+    preConfigure = "cd pro";
+
+    preFixup = ''
+      cd ../build/release*
+      mkdir -p $out/bin
+      for bin in vsedit{,-job-server{,-watcher}}; do
+          mv $bin $out/bin
+          wrapQtApp $out/bin/$bin
+      done
+    '';
+
+    passthru = {
+      inherit withPlugins;
+    };
+
+    meta = with lib; {
+      description = "Cross-platform editor for VapourSynth scripts";
+      homepage = "https://github.com/YomikoR/VapourSynth-Editor";
+      license = licenses.mit;
+      maintainers = [ ];
+      platforms = platforms.all;
+    };
+  };
+
+  withPlugins =
+    plugins:
+    let
+      vapoursynthWithPlugins = vapoursynth.withPlugins plugins;
+    in
+    runCommand "${unwrapped.name}-with-plugins"
+      {
+        nativeBuildInputs = [ makeWrapper ];
+        passthru = {
+          withPlugins = plugins': withPlugins (plugins ++ plugins');
+        };
+      }
+      ''
+        mkdir -p $out/bin
+        for bin in vsedit{,-job-server{,-watcher}}; do
+            makeWrapper ${unwrapped}/bin/$bin $out/bin/$bin \
+                --prefix PYTHONPATH : ${vapoursynthWithPlugins}/${python3.sitePackages} \
+                --prefix LD_LIBRARY_PATH : ${vapoursynthWithPlugins}/lib
+        done
+      '';
+in
+withPlugins [ ]
diff --git a/pkgs/by-name/va/vapoursynth/nix-plugin-loader.patch b/pkgs/by-name/va/vapoursynth/nix-plugin-loader.patch
new file mode 100644
index 000000000000..e06c9a6cf6b8
--- /dev/null
+++ b/pkgs/by-name/va/vapoursynth/nix-plugin-loader.patch
@@ -0,0 +1,28 @@
+diff --git a/src/core/vscore.cpp b/src/core/vscore.cpp
+index 73e2eafc..66a01326 100644
+--- a/src/core/vscore.cpp
++++ b/src/core/vscore.cpp
+@@ -1779,6 +1779,12 @@ void VSCore::isPortableInit() {
+ }
+ #endif
+ 
++void __attribute__((weak)) VSLoadPluginsNix(void (*load)(VSCore *core, const std::filesystem::path &), VSCore *);
++
++static void VSLoadPluginsNixCallback(VSCore *core, const std::filesystem::path &path) {
++    core->loadAllPluginsInPath(path);
++}
++
+ VSCore::VSCore(int flags) :
+     numFilterInstances(1),
+     numFunctionInstances(0),
+@@ -1890,6 +1896,10 @@ VSCore::VSCore(int flags) :
+ #endif
+     }
+ 
++    if (VSLoadPluginsNix != nullptr) {
++        VSLoadPluginsNix(VSLoadPluginsNixCallback, this);
++    };
++
+     VSMap *settings = readSettings(configFile);
+     const char *error = vs_internal_vsapi.mapGetError(settings);
+     if (error) {
diff --git a/pkgs/by-name/va/vapoursynth/package.nix b/pkgs/by-name/va/vapoursynth/package.nix
new file mode 100644
index 000000000000..bd67cb4485cc
--- /dev/null
+++ b/pkgs/by-name/va/vapoursynth/package.nix
@@ -0,0 +1,107 @@
+{
+  lib,
+  stdenv,
+  fetchFromGitHub,
+  pkg-config,
+  autoreconfHook,
+  makeWrapper,
+  runCommandCC,
+  runCommand,
+  vapoursynth,
+  writeText,
+  buildEnv,
+  zimg,
+  libass,
+  python3,
+  libiconv,
+  testers,
+  ApplicationServices,
+}:
+
+stdenv.mkDerivation rec {
+  pname = "vapoursynth";
+  version = "69";
+
+  src = fetchFromGitHub {
+    owner = "vapoursynth";
+    repo = "vapoursynth";
+    rev = "R${version}";
+    hash = "sha256-T2bCVNH0dLM9lFYChXzvD6AJM3xEtOVCb2tI10tIXJs=";
+  };
+
+  patches = [ ./nix-plugin-loader.patch ];
+
+  nativeBuildInputs = [
+    pkg-config
+    autoreconfHook
+    makeWrapper
+  ];
+  buildInputs =
+    [
+      zimg
+      libass
+      (python3.withPackages (
+        ps: with ps; [
+          sphinx
+          cython
+        ]
+      ))
+    ]
+    ++ lib.optionals stdenv.isDarwin [
+      libiconv
+      ApplicationServices
+    ];
+
+  enableParallelBuilding = true;
+
+  passthru = rec {
+    # If vapoursynth is added to the build inputs of mpv and then
+    # used in the wrapping of it, we want to know once inside the
+    # wrapper, what python3 version was used to build vapoursynth so
+    # the right python3.sitePackages will be used there.
+    inherit python3;
+
+    withPlugins = import ./plugin-interface.nix {
+      inherit
+        lib
+        python3
+        buildEnv
+        writeText
+        runCommandCC
+        stdenv
+        runCommand
+        vapoursynth
+        makeWrapper
+        withPlugins
+        ;
+    };
+
+    tests.version = testers.testVersion {
+      package = vapoursynth;
+      # Check Core version to prevent false positive with API version
+      version = "Core R${version}";
+    };
+  };
+
+  postInstall = ''
+    wrapProgram $out/bin/vspipe \
+        --prefix PYTHONPATH : $out/${python3.sitePackages}
+
+    # VapourSynth does not include any plugins by default
+    # and emits a warning when the system plugin directory does not exist.
+    mkdir $out/lib/vapoursynth
+  '';
+
+  meta = with lib; {
+    broken = stdenv.isDarwin; # see https://github.com/NixOS/nixpkgs/pull/189446 for partial fix
+    description = "Video processing framework with the future in mind";
+    homepage = "http://www.vapoursynth.com/";
+    license = licenses.lgpl21;
+    platforms = platforms.x86_64;
+    maintainers = with maintainers; [
+      rnhmjoj
+      sbruder
+    ];
+    mainProgram = "vspipe";
+  };
+}
diff --git a/pkgs/by-name/va/vapoursynth/plugin-interface.nix b/pkgs/by-name/va/vapoursynth/plugin-interface.nix
new file mode 100644
index 000000000000..c240b205ac1c
--- /dev/null
+++ b/pkgs/by-name/va/vapoursynth/plugin-interface.nix
@@ -0,0 +1,140 @@
+{
+  lib,
+  python3,
+  buildEnv,
+  writeText,
+  runCommandCC,
+  stdenv,
+  runCommand,
+  vapoursynth,
+  makeWrapper,
+  withPlugins,
+}:
+
+plugins:
+let
+  pythonEnvironment = python3.buildEnv.override { extraLibs = plugins; };
+
+  getRecursivePropagatedBuildInputs =
+    pkgs:
+    lib.flatten (
+      map (
+        pkg:
+        let
+          cleanPropagatedBuildInputs = lib.filter lib.isDerivation pkg.propagatedBuildInputs;
+        in
+        cleanPropagatedBuildInputs ++ (getRecursivePropagatedBuildInputs cleanPropagatedBuildInputs)
+      ) pkgs
+    );
+
+  deepPlugins = lib.unique (plugins ++ (getRecursivePropagatedBuildInputs plugins));
+
+  pluginsEnv = buildEnv {
+    name = "vapoursynth-plugins-env";
+    pathsToLink = [ "/lib/vapoursynth" ];
+    paths = deepPlugins;
+  };
+
+  pluginLoader =
+    let
+      source = writeText "vapoursynth-nix-plugins.cpp" ''
+        #include <filesystem>
+
+        struct VSCore;
+
+        void VSLoadPluginsNix(void (*load)(VSCore *, const std::filesystem::path &), VSCore *core) {
+        ${lib.concatMapStrings (
+          path: ''load(core, std::filesystem::u8path("${path}/lib/vapoursynth"));''
+        ) deepPlugins}
+        }
+      '';
+    in
+    runCommandCC "vapoursynth-plugin-loader"
+      {
+        executable = true;
+        preferLocalBuild = true;
+        allowSubstitutes = false;
+      }
+      ''
+        mkdir -p $out/lib
+        $CXX -std=c++17 -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
+      '';
+
+  ext = stdenv.hostPlatform.extensions.sharedLibrary;
+in
+runCommand "${vapoursynth.name}-with-plugins"
+  {
+    nativeBuildInputs = [ makeWrapper ];
+    passthru = {
+      inherit python3;
+      inherit (vapoursynth) src version;
+      withPlugins = plugins': withPlugins (plugins ++ plugins');
+    };
+  }
+  ''
+    mkdir -p \
+      $out/bin \
+      $out/lib/pkgconfig \
+      $out/lib/vapoursynth \
+      $out/${python3.sitePackages}
+
+    for textFile in \
+        lib/pkgconfig/vapoursynth{,-script}.pc \
+        lib/libvapoursynth.la \
+        lib/libvapoursynth-script.la \
+        ${python3.sitePackages}/vapoursynth.la
+    do
+        substitute ${vapoursynth}/$textFile $out/$textFile \
+            --replace "${vapoursynth}" "$out"
+    done
+
+    for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do
+        ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"}
+    done
+
+    for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do
+        ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"}
+    done
+
+    for binaryFile in \
+        lib/libvapoursynth${ext} \
+        lib/libvapoursynth-script${ext}.0.0.0
+    do
+      old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
+      new_rpath="$old_rpath:$out/lib"
+      patchelf \
+          --set-rpath "$new_rpath" \
+          --output $out/$binaryFile \
+          ${vapoursynth}/$binaryFile
+      patchelf \
+          --add-needed libvapoursynth-nix-plugins${ext} \
+          $out/$binaryFile
+    done
+
+    for binaryFile in \
+        ${python3.sitePackages}/vapoursynth${ext} \
+        bin/.vspipe-wrapped
+    do
+        old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
+        new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}"
+        patchelf \
+            --set-rpath "$new_rpath" \
+            --output $out/$binaryFile \
+            ${vapoursynth}/$binaryFile
+    done
+
+    ln -s \
+        ${pluginLoader}/lib/libvapoursynth-nix-plugins${ext} \
+        $out/lib/libvapoursynth-nix-plugins${ext}
+    ln -s ${vapoursynth}/include $out/include
+    ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth
+    ln -s \
+        libvapoursynth-script${ext}.0.0.0 \
+        $out/lib/libvapoursynth-script${ext}
+    ln -s \
+        libvapoursynth-script${ext}.0.0.0 \
+        $out/lib/libvapoursynth-script${ext}.0
+
+    makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \
+        --prefix PYTHONPATH : $out/${python3.sitePackages}
+  ''