about summary refs log tree commit diff
path: root/pkgs/applications/video/mpv
diff options
context:
space:
mode:
authornicoo <nicoo@mur.at>2023-12-09 15:44:44 +0000
committernicoo <nicoo@mur.at>2023-12-29 11:03:05 +0000
commit6b186414ded05f306218883a861f958386450252 (patch)
tree548b616502c0dbd01f9fe8eb0b506d811810f82f /pkgs/applications/video/mpv
parent81d6df0268747d1a32ea85d37b4276fd23a9795d (diff)
downloadnixlib-6b186414ded05f306218883a861f958386450252.tar
nixlib-6b186414ded05f306218883a861f958386450252.tar.gz
nixlib-6b186414ded05f306218883a861f958386450252.tar.bz2
nixlib-6b186414ded05f306218883a861f958386450252.tar.lz
nixlib-6b186414ded05f306218883a861f958386450252.tar.xz
nixlib-6b186414ded05f306218883a861f958386450252.tar.zst
nixlib-6b186414ded05f306218883a861f958386450252.zip
mpvScripts.buildLua: Expose to nixpkgs users
Diffstat (limited to 'pkgs/applications/video/mpv')
-rw-r--r--pkgs/applications/video/mpv/scripts/default.nix91
1 files changed, 46 insertions, 45 deletions
diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix
index a3de7e315a2b..3c1af55a2921 100644
--- a/pkgs/applications/video/mpv/scripts/default.nix
+++ b/pkgs/applications/video/mpv/scripts/default.nix
@@ -5,64 +5,65 @@
 }:
 
 let
-  buildLua = callPackage ./buildLua.nix { };
-
   unionOfDisjoints = lib.fold lib.attrsets.unionOfDisjoint {};
 
-  addTests = name: drv: let
-    inherit (drv) scriptName;
-    scriptPath = "share/mpv/scripts/${scriptName}";
-    fullScriptPath = "${drv}/${scriptPath}";
-
-  in drv.overrideAttrs (old: { passthru = (old.passthru or {}) // { tests = unionOfDisjoints [
-    (old.passthru.tests or {})
+  addTests = name: drv:
+    if ! lib.isDerivation drv then
+      drv
+    else let
+      inherit (drv) scriptName;
+      scriptPath = "share/mpv/scripts/${scriptName}";
+      fullScriptPath = "${drv}/${scriptPath}";
+    in drv.overrideAttrs (old: { passthru = (old.passthru or {}) // { tests = unionOfDisjoints [
+      (old.passthru.tests or {})
 
-    {
-      scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" {
-        meta.maintainers = with lib.maintainers; [ nicoo ];
-        preferLocalBuild = true;
-      } ''
-        if [ -e "${fullScriptPath}" ]; then
-          touch $out
-        else
-          echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2
-          exit 1
-        fi
-      '';
-    }
+      {
+        scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" {
+          meta.maintainers = with lib.maintainers; [ nicoo ];
+          preferLocalBuild = true;
+        } ''
+          if [ -e "${fullScriptPath}" ]; then
+            touch $out
+          else
+            echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2
+            exit 1
+          fi
+        '';
+      }
 
-    # can't check whether `fullScriptPath` is a directory, in pure-evaluation mode
-    (with lib; optionalAttrs (! any (s: hasSuffix s drv.passthru.scriptName) [ ".js" ".lua" ".so" ]) {
-      single-main-in-script-dir = runCommand "mpvScripts.${name}.passthru.tests.single-main-in-script-dir" {
-        meta.maintainers = with lib.maintainers; [ nicoo ];
-        preferLocalBuild = true;
-      } ''
-        die() {
-          echo "$@" >&2
-          exit 1
-        }
+      # can't check whether `fullScriptPath` is a directory, in pure-evaluation mode
+      (with lib; optionalAttrs (! any (s: hasSuffix s drv.passthru.scriptName) [ ".js" ".lua" ".so" ]) {
+        single-main-in-script-dir = runCommand "mpvScripts.${name}.passthru.tests.single-main-in-script-dir" {
+          meta.maintainers = with lib.maintainers; [ nicoo ];
+          preferLocalBuild = true;
+        } ''
+          die() {
+            echo "$@" >&2
+            exit 1
+          }
 
-        cd "${drv}/${scriptPath}"  # so the glob expands to filenames only
-        mains=( main.* )
-        if [ "''${#mains[*]}" -eq 1 ]; then
-          touch $out
-        elif [ "''${#mains[*]}" -eq 0 ]; then
-          die "'${scriptPath}' contains no 'main.*' file"
-        else
-          die "'${scriptPath}' contains multiple 'main.*' files:" "''${mains[*]}"
-        fi
-      '';
-    })
-  ]; }; });
+          cd "${drv}/${scriptPath}"  # so the glob expands to filenames only
+          mains=( main.* )
+          if [ "''${#mains[*]}" -eq 1 ]; then
+            touch $out
+          elif [ "''${#mains[*]}" -eq 0 ]; then
+            die "'${scriptPath}' contains no 'main.*' file"
+          else
+            die "'${scriptPath}' contains multiple 'main.*' files:" "''${mains[*]}"
+          fi
+        '';
+      })
+    ]; }; });
 in
 
 lib.recurseIntoAttrs
-  (lib.mapAttrs addTests ({
+  (lib.mapAttrs addTests (rec {
     inherit (callPackage ./mpv.nix { inherit buildLua; })
       acompressor autocrop autodeint autoload;
     inherit (callPackage ./occivink.nix { inherit buildLua; })
       blacklistExtensions seekTo;
 
+    buildLua = callPackage ./buildLua.nix { };
     chapterskip = callPackage ./chapterskip.nix { inherit buildLua; };
     convert = callPackage ./convert.nix { inherit buildLua; };
     cutter = callPackage ./cutter.nix { inherit buildLua; };