Merge pull request #266926 from nbraud/mpvScripts/buildLua/extraScripts

mpvScripts.buildLua: Add `extraScripts` parameter, infer `scriptName` better
This commit is contained in:
Maciej Krüger 2023-11-22 14:13:57 +01:00 committed by GitHub
commit faf93f9750
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View file

@ -1,10 +1,24 @@
{ lib
, stdenvNoCC }:
let fileName = pathStr: lib.last (lib.splitString "/" pathStr);
let
escapedList = with lib; concatMapStringsSep " " (s: "'${escape [ "'" ] s}'");
fileName = pathStr: lib.last (lib.splitString "/" pathStr);
scriptsDir = "$out/share/mpv/scripts";
in
lib.makeOverridable (
{ pname, scriptPath ? "${pname}.lua", ... }@args:
{ pname
, extraScripts ? []
, ... }@args:
let
# either passthru.scriptName, inferred from scriptPath, or from pname
scriptName = (args.passthru or {}).scriptName or (
if args ? scriptPath
then fileName args.scriptPath
else "${pname}.lua"
);
scriptPath = args.scriptPath or "./${scriptName}";
in
stdenvNoCC.mkDerivation (lib.attrsets.recursiveUpdate {
dontBuild = true;
preferLocalBuild = true;
@ -12,11 +26,12 @@ lib.makeOverridable (
outputHashMode = "recursive";
installPhase = ''
runHook preInstall
install -m644 -Dt $out/share/mpv/scripts ${scriptPath}
install -m644 -Dt "${scriptsDir}" \
${escapedList ([ scriptPath ] ++ extraScripts)}
runHook postInstall
'';
passthru.scriptName = fileName scriptPath;
passthru = { inherit scriptName; };
meta.platforms = lib.platforms.all;
} args)
)

View file

@ -15,8 +15,8 @@ buildLua rec {
hash = "sha256-yrcTxqpLnOI1Tq3khhflO3wzhyeTPuvKifyH5/P57Ns=";
};
passthru.scriptName = "quality-menu.lua";
scriptPath = if oscSupport then "*.lua" else passthru.scriptName;
scriptPath = "quality-menu.lua";
extraScripts = lib.optional oscSupport "quality-menu-osc.lua";
meta = with lib; {
description = "A userscript for MPV that allows you to change youtube video quality (ytdl-format) on the fly";

View file

@ -15,7 +15,9 @@ buildLua rec {
postPatch = "patchShebangs concat_files.py";
dontBuild = false;
scriptPath = "mpv_thumbnail_script_{client_osc,server}.lua";
scriptPath = "mpv_thumbnail_script_client_osc.lua";
extraScripts = [ "mpv_thumbnail_script_server.lua" ];
passthru.scriptName = "mpv_thumbnail_script_{client_osc,server}.lua";
meta = with lib; {
description = "A lua script to show preview thumbnails in mpv's OSC seekbar";