4 # Escape strings for embedding in shell scripts
5 escaped = s: "'${lib.escape [ "'" ] s}'";
6 escapedList = lib.concatMapStringsSep " " escaped;
8 fileName = pathStr: lib.last (lib.splitString "/" pathStr);
9 scriptsDir = "$out/share/mpv/scripts";
11 # similar to `lib.extends`, but with inverted precedence and recursive update
17 lib.recursiveUpdate (orig super) super;
22 stdenvNoCC.mkDerivation (
23 extendedBy (if lib.isFunction args then args else (_: args)) (
33 groups = match "mpv[-_](.*)" pname;
35 if groups != null then head groups else pname;
36 # either passthru.scriptName, inferred from scriptPath, or from pname
38 (args.passthru or { }).scriptName
39 or (if args ? scriptPath then fileName args.scriptPath else "${strippedName}.lua");
40 scriptPath = args.scriptPath or "./${scriptName}";
44 preferLocalBuild = true;
46 # Prevent `patch` from emitting `.orig` files (that end up in the output)
48 "--no-backup-if-mismatch"
52 outputHashMode = "recursive";
56 if [ -d "${scriptPath}" ]; then
57 [ -f "${scriptPath}/main.lua" ] || {
58 echo "Script directory '${scriptPath}' does not contain 'main.lua'" >&2
61 [ ${with builtins; toString (length extraScripts)} -eq 0 ] || {
62 echo "mpvScripts.buildLua does not support 'extraScripts'" \
63 "when 'scriptPath' is a directory" >&2
66 mkdir -p "${scriptsDir}"
67 cp -a "${scriptPath}" "${scriptsDir}/${scriptName}"
69 install -m644 -Dt "${scriptsDir}" ${escaped scriptPath}
70 ${lib.optionalString (
72 ) ''cp -at "${scriptsDir}/" ${escapedList extraScripts}''}
83 platforms = lib.platforms.all;
88 if (args.meta or { }) ? description then
89 builtins.unsafeGetAttrPos "description" args.meta
91 builtins.unsafeGetAttrPos "pname" args;
93 lib.optionalAttrs (pos != null) { position = "${pos.file}:${toString pos.line}"; }