about summary refs log tree commit diff
path: root/pkgs/applications/video/mpv/scripts/buildLua.nix
diff options
context:
space:
mode:
authornicoo <nicoo@mur.at>2023-10-18 11:38:25 +0000
committernicoo <nicoo@mur.at>2023-11-22 22:51:02 +0000
commit8438431b9f87e36df21da4ab4d025ba8b4eff937 (patch)
tree92472dbae333586cc9fa956ff02545c050f4fbd1 /pkgs/applications/video/mpv/scripts/buildLua.nix
parente4baad1ea299fc9488bc10d0b506389b9ed7c3f2 (diff)
mpvScripts.buildLua: Handle scripts packaged as directories
Diffstat (limited to 'pkgs/applications/video/mpv/scripts/buildLua.nix')
-rw-r--r--pkgs/applications/video/mpv/scripts/buildLua.nix34
1 files changed, 30 insertions, 4 deletions
diff --git a/pkgs/applications/video/mpv/scripts/buildLua.nix b/pkgs/applications/video/mpv/scripts/buildLua.nix
index 769e11798a6af..046b0fa2ea969 100644
--- a/pkgs/applications/video/mpv/scripts/buildLua.nix
+++ b/pkgs/applications/video/mpv/scripts/buildLua.nix
@@ -2,8 +2,18 @@
 , stdenvNoCC }:
 
 let
+  inherit (lib) hasPrefix hasSuffix removeSuffix;
   escapedList = with lib; concatMapStringsSep " " (s: "'${escape [ "'" ] s}'");
   fileName = pathStr: lib.last (lib.splitString "/" pathStr);
+  nameFromPath = pathStr:
+    let fN = fileName pathStr; in
+    if hasSuffix ".lua" fN then
+      fN
+    else if !(hasPrefix "." fN) then
+      "${fN}.lua"
+    else
+      null
+  ;
   scriptsDir = "$out/share/mpv/scripts";
 in
 lib.makeOverridable (
@@ -13,8 +23,8 @@ lib.makeOverridable (
   let
     # either passthru.scriptName, inferred from scriptPath, or from pname
     scriptName = (args.passthru or {}).scriptName or (
-      if args ? scriptPath
-      then fileName args.scriptPath
+      if args ? scriptPath && nameFromPath args.scriptPath != null
+      then nameFromPath args.scriptPath
       else "${pname}.lua"
     );
     scriptPath = args.scriptPath or "./${scriptName}";
@@ -26,8 +36,24 @@ lib.makeOverridable (
     outputHashMode = "recursive";
     installPhase = ''
       runHook preInstall
-      install -m644 -Dt "${scriptsDir}" \
-        ${escapedList ([ scriptPath ] ++ extraScripts)}
+
+      if [ -d "${scriptPath}" ]; then
+        [ -f "${scriptPath}/main.lua" ] || {
+          echo "Script directory '${scriptPath}' does not contain 'main.lua'" >&2
+          exit 1
+        }
+        [ ${with builtins; toString (length extraScripts)} -eq 0 ] || {
+          echo "mpvScripts.buildLua does not support 'extraScripts'" \
+               "when 'scriptPath' is a directory"
+          exit 1
+        }
+        mkdir -p "${scriptsDir}"
+        cp -a "${scriptPath}" "${scriptsDir}/${lib.removeSuffix ".lua" scriptName}"
+      else
+        install -m644 -Dt "${scriptsDir}" \
+          ${escapedList ([ scriptPath ] ++ extraScripts)}
+      fi
+
       runHook postInstall
     '';