From a899b23bd3e4f6bd6f6d762dd2260952f1d72b9d Mon Sep 17 00:00:00 2001 From: nicoo Date: Tue, 17 Oct 2023 14:52:25 +0000 Subject: [PATCH] mpvScripts: refactor around `buildLua` helper --- .../video/mpv/scripts/acompressor.nix | 22 +++++----------- .../video/mpv/scripts/buildLua.nix | 18 +++++++++++++ .../video/mpv/scripts/chapterskip.nix | 19 +++----------- .../video/mpv/scripts/default.nix | 9 ++++--- .../video/mpv/scripts/occivink.nix | 26 +++++-------------- 5 files changed, 40 insertions(+), 54 deletions(-) create mode 100644 pkgs/applications/video/mpv/scripts/buildLua.nix diff --git a/pkgs/applications/video/mpv/scripts/acompressor.nix b/pkgs/applications/video/mpv/scripts/acompressor.nix index d10ef5f9df75..d82d12f163e7 100644 --- a/pkgs/applications/video/mpv/scripts/acompressor.nix +++ b/pkgs/applications/video/mpv/scripts/acompressor.nix @@ -1,27 +1,17 @@ -{ stdenvNoCC +{ lib +, buildLua , mpv-unwrapped -, lib }: -stdenvNoCC.mkDerivation rec { +buildLua { + inherit (mpv-unwrapped) src version; pname = "mpv-acompressor"; - version = mpv-unwrapped.version; - - src = "${mpv-unwrapped.src.outPath}/TOOLS/lua/acompressor.lua"; - - dontBuild = true; - dontUnpack = true; - - installPhase = '' - install -Dm644 ${src} $out/share/mpv/scripts/acompressor.lua - ''; - - passthru.scriptName = "acompressor.lua"; + scriptPath = "TOOLS/lua/acompressor.lua"; meta = with lib; { + inherit (mpv-unwrapped.meta) license; description = "Script to toggle and control ffmpeg's dynamic range compression filter."; homepage = "https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/acompressor.lua"; - license = licenses.gpl2Plus; maintainers = with maintainers; [ nicoo ]; }; } diff --git a/pkgs/applications/video/mpv/scripts/buildLua.nix b/pkgs/applications/video/mpv/scripts/buildLua.nix new file mode 100644 index 000000000000..79703d4cf1c4 --- /dev/null +++ b/pkgs/applications/video/mpv/scripts/buildLua.nix @@ -0,0 +1,18 @@ +{ lib +, stdenvNoCC }: + +let fileName = pathStr: lib.last (lib.splitString "/" pathStr); +in +lib.makeOverridable ( + { pname, scriptPath ? "${pname}.lua", ... }@args: + stdenvNoCC.mkDerivation (lib.attrsets.recursiveUpdate { + dontBuild = true; + preferLocalBuild = true; + + outputHashMode = "recursive"; + installPhase = "install -m644 -Dt $out/share/mpv/scripts ${scriptPath}"; + passthru.scriptName = fileName scriptPath; + + meta.platforms = lib.platforms.all; + } args) +) diff --git a/pkgs/applications/video/mpv/scripts/chapterskip.nix b/pkgs/applications/video/mpv/scripts/chapterskip.nix index c147da8d4598..bffc27bd1eac 100644 --- a/pkgs/applications/video/mpv/scripts/chapterskip.nix +++ b/pkgs/applications/video/mpv/scripts/chapterskip.nix @@ -1,11 +1,9 @@ { lib , fetchFromGitHub -, nix-update-script -, stdenvNoCC }: +, buildLua }: -stdenvNoCC.mkDerivation { +buildLua { pname = "chapterskip"; - passthru.scriptName = "chapterskip.lua"; version = "unstable-2022-09-08"; src = fetchFromGitHub { @@ -15,17 +13,8 @@ stdenvNoCC.mkDerivation { hash = "sha256-OTrLQE3rYvPQamEX23D6HttNjx3vafWdTMxTiWpDy90="; }; - dontBuild = true; - preferLocalBuild = true; - installPhase = "install -Dt $out/share/mpv/scripts chapterskip.lua"; - - passthru.updateScript = nix-update-script { - extraArgs = [ "--version=branch" ]; - }; - - meta = with lib; { + meta = { homepage = "https://github.com/po5/chapterskip"; - platforms = platforms.all; - maintainers = with maintainers; [ nicoo ]; + maintainers = with lib.maintainers; [ nicoo ]; }; } diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 2866f80f5652..562e3de1645b 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -3,13 +3,14 @@ , config }: -lib.recurseIntoAttrs +let buildLua = callPackage ./buildLua.nix { }; +in lib.recurseIntoAttrs ({ - acompressor = callPackage ./acompressor.nix { }; + acompressor = callPackage ./acompressor.nix { inherit buildLua; }; autocrop = callPackage ./autocrop.nix { }; autodeint = callPackage ./autodeint.nix { }; autoload = callPackage ./autoload.nix { }; - chapterskip = callPackage ./chapterskip.nix { }; + chapterskip = callPackage ./chapterskip.nix { inherit buildLua; }; convert = callPackage ./convert.nix { }; inhibit-gnome = callPackage ./inhibit-gnome.nix { }; mpris = callPackage ./mpris.nix { }; @@ -27,7 +28,7 @@ lib.recurseIntoAttrs webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; cutter = callPackage ./cutter.nix { }; } - // (callPackage ./occivink.nix { })) + // (callPackage ./occivink.nix { inherit buildLua; })) // lib.optionalAttrs config.allowAliases { youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 } diff --git a/pkgs/applications/video/mpv/scripts/occivink.nix b/pkgs/applications/video/mpv/scripts/occivink.nix index da723fd9102e..e0f07a10db95 100644 --- a/pkgs/applications/video/mpv/scripts/occivink.nix +++ b/pkgs/applications/video/mpv/scripts/occivink.nix @@ -1,14 +1,11 @@ { lib -, stdenvNoCC , fetchFromGitHub +, buildLua }: let - script = { n, ... }@p: - stdenvNoCC.mkDerivation (lib.attrsets.recursiveUpdate { - pname = "mpv_${n}"; - passthru.scriptName = "${n}.lua"; - + script = { pname, ...}@args: + buildLua (lib.attrsets.recursiveUpdate { src = fetchFromGitHub { owner = "occivink"; repo = "mpv-scripts"; @@ -17,37 +14,28 @@ let }; version = "unstable-2022-10-02"; - dontBuild = true; - installPhase = '' - mkdir -p $out/share/mpv/scripts - cp -r scripts/${n}.lua $out/share/mpv/scripts/ - ''; + scriptPath = "scripts/${pname}.lua"; meta = with lib; { homepage = "https://github.com/occivink/mpv-scripts"; license = licenses.unlicense; - platforms = platforms.all; maintainers = with maintainers; [ nicoo ]; }; - - outputHashAlgo = "sha256"; - outputHashMode = "recursive"; - } p); + } args); in { # Usage: `pkgs.mpv.override { scripts = [ pkgs.mpvScripts.seekTo ]; }` seekTo = script { - n = "seek-to"; + pname = "seek-to"; meta.description = "Mpv script for seeking to a specific position"; outputHash = "sha256-3RlbtUivmeoR9TZ6rABiZSd5jd2lFv/8p/4irHMLshs="; }; blacklistExtensions = script { - n = "blacklist-extensions"; + pname = "blacklist-extensions"; meta.description = "Automatically remove playlist entries based on their extension."; outputHash = "sha256-qw9lz8ofmvvh23F9aWLxiU4YofY+YflRETu+nxMhvVE="; }; - }