about summary refs log tree commit diff
path: root/pkgs/applications/video/mpv
diff options
context:
space:
mode:
authorMaciej Krüger <mkg20001@gmail.com>2023-11-08 19:42:57 +0100
committerGitHub <noreply@github.com>2023-11-08 19:42:57 +0100
commit2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d (patch)
treec8fbbc2a3333e4fddc870e73be005450f049525f /pkgs/applications/video/mpv
parentde7ab5c70d43cb13362de1168858aed8a189492d (diff)
parent7b792b0bcffb77795001dc0840d090e21a609a6b (diff)
downloadnixlib-2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d.tar
nixlib-2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d.tar.gz
nixlib-2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d.tar.bz2
nixlib-2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d.tar.lz
nixlib-2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d.tar.xz
nixlib-2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d.tar.zst
nixlib-2a4751dc3f6917fe7e9a1e3779dd3dc887cb780d.zip
Merge pull request #265676 from nbraud/mpvScripts/refactor
Diffstat (limited to 'pkgs/applications/video/mpv')
-rw-r--r--pkgs/applications/video/mpv/scripts/acompressor.nix22
-rw-r--r--pkgs/applications/video/mpv/scripts/buildLua.nix22
-rw-r--r--pkgs/applications/video/mpv/scripts/chapterskip.nix19
-rw-r--r--pkgs/applications/video/mpv/scripts/default.nix9
-rw-r--r--pkgs/applications/video/mpv/scripts/occivink.nix36
5 files changed, 51 insertions, 57 deletions
diff --git a/pkgs/applications/video/mpv/scripts/acompressor.nix b/pkgs/applications/video/mpv/scripts/acompressor.nix
index d10ef5f9df75..d82d12f163e7 100644
--- a/pkgs/applications/video/mpv/scripts/acompressor.nix
+++ b/pkgs/applications/video/mpv/scripts/acompressor.nix
@@ -1,27 +1,17 @@
-{ stdenvNoCC
+{ lib
+, buildLua
 , mpv-unwrapped
-, lib
 }:
 
-stdenvNoCC.mkDerivation rec {
+buildLua {
+  inherit (mpv-unwrapped) src version;
   pname = "mpv-acompressor";
-  version = mpv-unwrapped.version;
-
-  src = "${mpv-unwrapped.src.outPath}/TOOLS/lua/acompressor.lua";
-
-  dontBuild = true;
-  dontUnpack = true;
-
-  installPhase = ''
-    install -Dm644 ${src} $out/share/mpv/scripts/acompressor.lua
-  '';
-
-  passthru.scriptName = "acompressor.lua";
+  scriptPath = "TOOLS/lua/acompressor.lua";
 
   meta = with lib; {
+    inherit (mpv-unwrapped.meta) license;
     description = "Script to toggle and control ffmpeg's dynamic range compression filter.";
     homepage = "https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/acompressor.lua";
-    license = licenses.gpl2Plus;
     maintainers = with maintainers; [ nicoo ];
   };
 }
diff --git a/pkgs/applications/video/mpv/scripts/buildLua.nix b/pkgs/applications/video/mpv/scripts/buildLua.nix
new file mode 100644
index 000000000000..b86642305fc6
--- /dev/null
+++ b/pkgs/applications/video/mpv/scripts/buildLua.nix
@@ -0,0 +1,22 @@
+{ lib
+, stdenvNoCC }:
+
+let fileName = pathStr: lib.last (lib.splitString "/" pathStr);
+in
+lib.makeOverridable (
+  { pname, scriptPath ? "${pname}.lua", ... }@args:
+  stdenvNoCC.mkDerivation (lib.attrsets.recursiveUpdate {
+    dontBuild = true;
+    preferLocalBuild = true;
+
+    outputHashMode = "recursive";
+    installPhase = ''
+      runHook preInstall
+      install -m644 -Dt $out/share/mpv/scripts ${scriptPath}
+      runHook postInstall
+    '';
+
+    passthru.scriptName = fileName scriptPath;
+    meta.platforms = lib.platforms.all;
+  } args)
+)
diff --git a/pkgs/applications/video/mpv/scripts/chapterskip.nix b/pkgs/applications/video/mpv/scripts/chapterskip.nix
index c147da8d4598..bffc27bd1eac 100644
--- a/pkgs/applications/video/mpv/scripts/chapterskip.nix
+++ b/pkgs/applications/video/mpv/scripts/chapterskip.nix
@@ -1,11 +1,9 @@
 { lib
 , fetchFromGitHub
-, nix-update-script
-, stdenvNoCC }:
+, buildLua }:
 
-stdenvNoCC.mkDerivation {
+buildLua {
   pname = "chapterskip";
-  passthru.scriptName = "chapterskip.lua";
 
   version = "unstable-2022-09-08";
   src = fetchFromGitHub {
@@ -15,17 +13,8 @@ stdenvNoCC.mkDerivation {
     hash  = "sha256-OTrLQE3rYvPQamEX23D6HttNjx3vafWdTMxTiWpDy90=";
   };
 
-  dontBuild = true;
-  preferLocalBuild = true;
-  installPhase = "install -Dt $out/share/mpv/scripts chapterskip.lua";
-
-  passthru.updateScript = nix-update-script {
-    extraArgs = [ "--version=branch" ];
-  };
-
-  meta = with lib; {
+  meta = {
     homepage = "https://github.com/po5/chapterskip";
-    platforms = platforms.all;
-    maintainers = with maintainers; [ nicoo ];
+    maintainers = with lib.maintainers; [ nicoo ];
   };
 }
diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix
index 2866f80f5652..562e3de1645b 100644
--- a/pkgs/applications/video/mpv/scripts/default.nix
+++ b/pkgs/applications/video/mpv/scripts/default.nix
@@ -3,13 +3,14 @@
 , config
 }:
 
-lib.recurseIntoAttrs
+let buildLua = callPackage ./buildLua.nix { };
+in lib.recurseIntoAttrs
   ({
-    acompressor = callPackage ./acompressor.nix { };
+    acompressor = callPackage ./acompressor.nix { inherit buildLua; };
     autocrop = callPackage ./autocrop.nix { };
     autodeint = callPackage ./autodeint.nix { };
     autoload = callPackage ./autoload.nix { };
-    chapterskip = callPackage ./chapterskip.nix { };
+    chapterskip = callPackage ./chapterskip.nix { inherit buildLua; };
     convert = callPackage ./convert.nix { };
     inhibit-gnome = callPackage ./inhibit-gnome.nix { };
     mpris = callPackage ./mpris.nix { };
@@ -27,7 +28,7 @@ lib.recurseIntoAttrs
     webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { };
     cutter = callPackage ./cutter.nix { };
   }
-  // (callPackage ./occivink.nix { }))
+  // (callPackage ./occivink.nix { inherit buildLua; }))
   // lib.optionalAttrs config.allowAliases {
   youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14
 }
diff --git a/pkgs/applications/video/mpv/scripts/occivink.nix b/pkgs/applications/video/mpv/scripts/occivink.nix
index da723fd9102e..167e2fef6ac0 100644
--- a/pkgs/applications/video/mpv/scripts/occivink.nix
+++ b/pkgs/applications/video/mpv/scripts/occivink.nix
@@ -1,14 +1,17 @@
 { lib
-, stdenvNoCC
 , fetchFromGitHub
+, buildLua
 }:
 
 let
-  script = { n, ... }@p:
-    stdenvNoCC.mkDerivation (lib.attrsets.recursiveUpdate {
-      pname = "mpv_${n}";
-      passthru.scriptName = "${n}.lua";
-
+  camelToKebab = let
+    inherit (lib.strings) match stringAsChars toLower;
+    isUpper = match "[A-Z]";
+  in stringAsChars (c: if isUpper c != null then "-${toLower c}" else c);
+
+  mkScript = name: args:
+    buildLua (lib.attrsets.recursiveUpdate rec {
+      pname = camelToKebab name;
       src = fetchFromGitHub {
         owner = "occivink";
         repo = "mpv-scripts";
@@ -17,37 +20,26 @@ let
       };
       version = "unstable-2022-10-02";
 
-      dontBuild = true;
-      installPhase = ''
-        mkdir -p $out/share/mpv/scripts
-        cp -r scripts/${n}.lua $out/share/mpv/scripts/
-      '';
+      scriptPath = "scripts/${pname}.lua";
 
       meta = with lib; {
         homepage = "https://github.com/occivink/mpv-scripts";
         license = licenses.unlicense;
-        platforms = platforms.all;
         maintainers = with maintainers; [ nicoo ];
       };
-
-      outputHashAlgo = "sha256";
-      outputHashMode = "recursive";
-    } p);
+    } args);
 
 in
-{
+lib.mapAttrs (name: lib.makeOverridable (mkScript name)) {
 
   # Usage: `pkgs.mpv.override { scripts = [ pkgs.mpvScripts.seekTo ]; }`
-  seekTo = script {
-    n = "seek-to";
+  seekTo = {
     meta.description = "Mpv script for seeking to a specific position";
     outputHash = "sha256-3RlbtUivmeoR9TZ6rABiZSd5jd2lFv/8p/4irHMLshs=";
   };
 
-  blacklistExtensions = script {
-    n = "blacklist-extensions";
+  blacklistExtensions = {
     meta.description = "Automatically remove playlist entries based on their extension.";
     outputHash = "sha256-qw9lz8ofmvvh23F9aWLxiU4YofY+YflRETu+nxMhvVE=";
   };
-
 }