From 8438431b9f87e36df21da4ab4d025ba8b4eff937 Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 18 Oct 2023 11:38:25 +0000 Subject: [PATCH 1/3] mpvScripts.buildLua: Handle scripts packaged as directories --- .../video/mpv/scripts/buildLua.nix | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/buildLua.nix b/pkgs/applications/video/mpv/scripts/buildLua.nix index 769e11798a6a..046b0fa2ea96 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 ''; From 65b81db7bb98de7ac3ae7e4faa40089895f8370d Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 18 Oct 2023 09:01:51 +0000 Subject: [PATCH 2/3] mpvScripts.simple-mpv-webui: Refactor with `buildLua` --- pkgs/applications/video/mpv/scripts/default.nix | 2 +- .../video/mpv/scripts/simple-mpv-webui.nix | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 63f986c2c41a..9d16deb1c529 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -18,7 +18,7 @@ in lib.recurseIntoAttrs mpv-webm = callPackage ./mpv-webm.nix { }; mpvacious = callPackage ./mpvacious.nix { inherit buildLua; }; quality-menu = callPackage ./quality-menu.nix { inherit buildLua; }; - simple-mpv-webui = callPackage ./simple-mpv-webui.nix { }; + simple-mpv-webui = callPackage ./simple-mpv-webui.nix { inherit buildLua; }; sponsorblock = callPackage ./sponsorblock.nix { }; thumbfast = callPackage ./thumbfast.nix { inherit buildLua; }; thumbnail = callPackage ./thumbnail.nix { inherit buildLua; }; diff --git a/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix index 01f2c3a099fa..7920796b7840 100644 --- a/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix +++ b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix @@ -1,6 +1,6 @@ -{ lib, stdenvNoCC +{ lib, buildLua , fetchFromGitHub }: -stdenvNoCC.mkDerivation rec { +buildLua rec { pname = "simple-mpv-ui"; version = "2.1.0"; @@ -11,12 +11,8 @@ stdenvNoCC.mkDerivation rec { sha256 = "1z0y8sdv5mbxznxqh43w5592ym688vkvqg7w26p8cinrhf09pbw8"; }; - dontBuild = true; - installPhase = '' - mkdir -p $out/share/mpv/scripts - cp -r webui.lua webui-page $out/share/mpv/scripts/ - ''; - passthru.scriptName = "webui.lua"; + scriptPath = "webui.lua"; + postInstall = "cp -a webui-page $out/share/mpv/scripts/"; meta = with lib; { description = "A web based user interface with controls for the mpv mediaplayer"; @@ -30,4 +26,3 @@ stdenvNoCC.mkDerivation rec { license = licenses.mit; }; } - From 183a4ceba7ff7f3992ed6184c18d7b33e2edf40e Mon Sep 17 00:00:00 2001 From: nicoo Date: Thu, 9 Nov 2023 17:04:46 +0000 Subject: [PATCH 3/3] =?UTF-8?q?mpvScripts.simple-mpv-ui:=202.1.0=20?= =?UTF-8?q?=E2=86=92=203.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix index 7920796b7840..c3b53c618396 100644 --- a/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix +++ b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix @@ -2,17 +2,18 @@ , fetchFromGitHub }: buildLua rec { pname = "simple-mpv-ui"; - version = "2.1.0"; + version = "3.0.0"; src = fetchFromGitHub { owner = "open-dynaMIX"; repo = "simple-mpv-webui"; rev = "v${version}"; - sha256 = "1z0y8sdv5mbxznxqh43w5592ym688vkvqg7w26p8cinrhf09pbw8"; + hash = "sha256-I8lwpo3Hfpy3UnPMmHEJCdArVQnNL245NkxsYVmnMF0="; + sparseCheckout = [ "main.lua" "webui-page" ]; }; - scriptPath = "webui.lua"; - postInstall = "cp -a webui-page $out/share/mpv/scripts/"; + scriptPath = "."; + passthru.scriptName = "webui.lua"; meta = with lib; { description = "A web based user interface with controls for the mpv mediaplayer";