about summary refs log tree commit diff
path: root/pkgs/applications/video/mpv/scripts/buildLua.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/applications/video/mpv/scripts/buildLua.nix')
-rw-r--r--pkgs/applications/video/mpv/scripts/buildLua.nix30
1 files changed, 14 insertions, 16 deletions
diff --git a/pkgs/applications/video/mpv/scripts/buildLua.nix b/pkgs/applications/video/mpv/scripts/buildLua.nix
index 046b0fa2ea96..4c1e1957c097 100644
--- a/pkgs/applications/video/mpv/scripts/buildLua.nix
+++ b/pkgs/applications/video/mpv/scripts/buildLua.nix
@@ -5,31 +5,29 @@ 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";
+
+  # similar to `lib.extends`, but with inverted precedence and recursive update
+  extendedBy = args: orig: self:
+    let super = args self;
+    in lib.recursiveUpdate (orig super) super
+  ;
 in
-lib.makeOverridable (
+
+lib.makeOverridable (args: stdenvNoCC.mkDerivation (extendedBy
+  (if lib.isFunction args then args else (_: args)) (
   { pname
   , extraScripts ? []
   , ... }@args:
   let
     # either passthru.scriptName, inferred from scriptPath, or from pname
     scriptName = (args.passthru or {}).scriptName or (
-      if args ? scriptPath && nameFromPath args.scriptPath != null
-      then nameFromPath args.scriptPath
+      if args ? scriptPath
+      then fileName args.scriptPath
       else "${pname}.lua"
     );
     scriptPath = args.scriptPath or "./${scriptName}";
-  in
-  stdenvNoCC.mkDerivation (lib.attrsets.recursiveUpdate {
+  in {
     dontBuild = true;
     preferLocalBuild = true;
 
@@ -59,5 +57,5 @@ lib.makeOverridable (
 
     passthru = { inherit scriptName; };
     meta.platforms = lib.platforms.all;
-  } args)
-)
+  })
+))