From 6444a0957bd825e454382d5e7211865afe8ab534 Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 29 Nov 2023 15:34:51 +0000 Subject: [PATCH 1/4] mpvScripts.buildLua: Generate the correct `scriptName` for directories `wrapMpv` expects the literal file/directory name. Bug introduced in 8438431b9f87e36df21da4ab4d025ba8b4eff937. --- pkgs/applications/video/mpv/scripts/buildLua.nix | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/buildLua.nix b/pkgs/applications/video/mpv/scripts/buildLua.nix index 046b0fa2ea96..728cb1c41556 100644 --- a/pkgs/applications/video/mpv/scripts/buildLua.nix +++ b/pkgs/applications/video/mpv/scripts/buildLua.nix @@ -5,15 +5,6 @@ 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 ( @@ -23,8 +14,8 @@ lib.makeOverridable ( 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}"; From ce2dcc6dcb6bdbb6c1be5799ac14aa4874a8739c Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 29 Nov 2023 12:47:14 +0000 Subject: [PATCH 2/4] mpvScripts.buildLua: Handle explicitly-recursive attrsets No rebuild needed, so this did not change existing uses of `buildLua`. --- .../applications/video/mpv/scripts/buildLua.nix | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/buildLua.nix b/pkgs/applications/video/mpv/scripts/buildLua.nix index 728cb1c41556..4c1e1957c097 100644 --- a/pkgs/applications/video/mpv/scripts/buildLua.nix +++ b/pkgs/applications/video/mpv/scripts/buildLua.nix @@ -6,8 +6,16 @@ let escapedList = with lib; concatMapStringsSep " " (s: "'${escape [ "'" ] s}'"); fileName = pathStr: lib.last (lib.splitString "/" pathStr); 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: @@ -19,8 +27,7 @@ lib.makeOverridable ( else "${pname}.lua" ); scriptPath = args.scriptPath or "./${scriptName}"; - in - stdenvNoCC.mkDerivation (lib.attrsets.recursiveUpdate { + in { dontBuild = true; preferLocalBuild = true; @@ -50,5 +57,5 @@ lib.makeOverridable ( passthru = { inherit scriptName; }; meta.platforms = lib.platforms.all; - } args) -) + }) +)) From 492f662817bfd1191b409fb7ee09cf6af847361b Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 29 Nov 2023 13:24:05 +0000 Subject: [PATCH 3/4] mpvScripts.uosc: refactor with `buildLua` --- pkgs/applications/video/mpv/scripts/default.nix | 2 +- pkgs/applications/video/mpv/scripts/uosc.nix | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index fb75464ab98e..4083c52b3d90 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -22,7 +22,7 @@ in lib.recurseIntoAttrs sponsorblock = callPackage ./sponsorblock.nix { }; thumbfast = callPackage ./thumbfast.nix { inherit buildLua; }; thumbnail = callPackage ./thumbnail.nix { inherit buildLua; }; - uosc = callPackage ./uosc.nix { }; + uosc = callPackage ./uosc.nix { inherit buildLua; }; visualizer = callPackage ./visualizer.nix { }; vr-reversal = callPackage ./vr-reversal.nix { }; webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; diff --git a/pkgs/applications/video/mpv/scripts/uosc.nix b/pkgs/applications/video/mpv/scripts/uosc.nix index b88cd2c5b968..311b31549ca7 100644 --- a/pkgs/applications/video/mpv/scripts/uosc.nix +++ b/pkgs/applications/video/mpv/scripts/uosc.nix @@ -1,6 +1,6 @@ -{ stdenvNoCC, lib, fetchFromGitHub, makeFontsConf }: +{ buildLua, lib, fetchFromGitHub, makeFontsConf }: -stdenvNoCC.mkDerivation (finalAttrs: { +buildLua (finalAttrs: { pname = "uosc"; version = "4.7.0"; @@ -16,19 +16,12 @@ stdenvNoCC.mkDerivation (finalAttrs: { --replace "mp.find_config_file('scripts')" "\"$out/share/mpv/scripts\"" ''; - dontBuild = true; - - installPhase = '' - runHook preInstall - - mkdir -p $out/share/mpv/ - cp -r scripts $out/share/mpv + scriptPath = "scripts/uosc.lua"; + postInstall = '' + cp -r scripts/uosc_shared $out/share/mpv/ cp -r fonts $out/share - - runHook postInstall ''; - passthru.scriptName = "uosc.lua"; # the script uses custom "texture" fonts as the background for ui elements. # In order for mpv to find them, we need to adjust the fontconfig search path. passthru.extraWrapperArgs = [ From cf861f91752b0d2a81e96f22dee187eccf740f0c Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 29 Nov 2023 13:40:21 +0000 Subject: [PATCH 4/4] =?UTF-8?q?mpvScripts.uosc:=204.7.0=20=E2=86=92=205.1.?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/applications/video/mpv/scripts/uosc.nix | 39 ++++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/uosc.nix b/pkgs/applications/video/mpv/scripts/uosc.nix index 311b31549ca7..4c434d49f368 100644 --- a/pkgs/applications/video/mpv/scripts/uosc.nix +++ b/pkgs/applications/video/mpv/scripts/uosc.nix @@ -1,35 +1,50 @@ -{ buildLua, lib, fetchFromGitHub, makeFontsConf }: +{ lib +, fetchFromGitHub +, fetchpatch +, makeFontsConf +, buildLua +, buildGoModule +}: buildLua (finalAttrs: { pname = "uosc"; - version = "4.7.0"; + version = "5.1.1"; + scriptPath = "src/uosc"; src = fetchFromGitHub { owner = "tomasklaen"; repo = "uosc"; rev = finalAttrs.version; - hash = "sha256-JqlBjhwRgmXl6XfHYTwtNWZj656EDHjcdWOlCgihF5I="; + hash = "sha256-+4k8T1yX3IRXK3XkUShsuJSH9w1Zla7CaRENcIqX4iM="; }; - postPatch = '' - substituteInPlace scripts/uosc.lua \ - --replace "mp.find_config_file('scripts')" "\"$out/share/mpv/scripts\"" - ''; + tools = buildGoModule { + pname = "uosc-bin"; + inherit (finalAttrs) version src; + vendorHash = "sha256-nkY0z2GiDxfNs98dpe+wZNI3dAXcuHaD/nHiZ2XnZ1Y="; + }; - scriptPath = "scripts/uosc.lua"; - postInstall = '' - cp -r scripts/uosc_shared $out/share/mpv/ - cp -r fonts $out/share - ''; + # Patch lua script to get the path to its `ziggy` binary form the environment + patches = [ + # uosc#814: Support overriding `ziggy_path` via environment variable + (fetchpatch { + url = "https://github.com/tomasklaen/uosc/commit/4fdf68a1bcb510824d66f35ecc7672a6452a44b2.patch"; + hash = "sha256-igUqFf8e7LVIIjGxACdIWAeZxjF/yqaCL4QRXrzNQXk="; + }) + ]; # the script uses custom "texture" fonts as the background for ui elements. # In order for mpv to find them, we need to adjust the fontconfig search path. + postInstall = "cp -r src/fonts $out/share"; passthru.extraWrapperArgs = [ "--set" "FONTCONFIG_FILE" (toString (makeFontsConf { fontDirectories = [ "${finalAttrs.finalPackage}/share/fonts" ]; })) + "--set" + "MPV_UOSC_ZIGGY" + (lib.getExe' finalAttrs.tools "ziggy") ]; meta = with lib; {