From 1bb85ca0d483ea7c3fbbcba7d12ce57d57c70e90 Mon Sep 17 00:00:00 2001 From: nicoo Date: Mon, 4 Dec 2023 15:23:11 +0000 Subject: [PATCH 1/6] mpvScripts: Add test validating `scriptName` --- .../video/mpv/scripts/default.nix | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 4083c52b3d90..67baba53983d 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -1,11 +1,32 @@ { lib , callPackage , config +, runCommand }: -let buildLua = callPackage ./buildLua.nix { }; -in lib.recurseIntoAttrs - ({ +let + buildLua = callPackage ./buildLua.nix { }; + + addTests = name: drv: drv.override { passthru.tests = lib.attrsets.unionOfDisjoint (drv.passthru.tests or {}) { + scriptName-is-valid = let + inherit (drv) scriptName; + scriptPath = "${drv}/share/mpv/scripts/${scriptName}"; + in runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" { + meta.maintainers = with lib.maintainers; [ nicoo ]; + preferLocalBuild = true; + } '' + if [ -e "${scriptPath}" ]; then + touch $out + else + echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2 + exit 1 + fi + ''; + }; }; +in + +lib.recurseIntoAttrs + (lib.mapAttrs addTests ({ acompressor = callPackage ./acompressor.nix { inherit buildLua; }; autocrop = callPackage ./autocrop.nix { }; autodeint = callPackage ./autodeint.nix { }; @@ -28,7 +49,7 @@ in lib.recurseIntoAttrs webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; cutter = callPackage ./cutter.nix { }; } - // (callPackage ./occivink.nix { inherit buildLua; })) + // (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 } From f4e390dc8a336cb32bdc9e8bba7cb3b195e9b237 Mon Sep 17 00:00:00 2001 From: nicoo Date: Mon, 4 Dec 2023 16:43:38 +0000 Subject: [PATCH 2/6] mpvScripts: Test that dir-packaged scripts contain exactly one `main.*` --- .../video/mpv/scripts/default.nix | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 67baba53983d..11d9c2e934a9 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -7,21 +7,53 @@ let buildLua = callPackage ./buildLua.nix { }; - addTests = name: drv: drv.override { passthru.tests = lib.attrsets.unionOfDisjoint (drv.passthru.tests or {}) { - scriptName-is-valid = let - inherit (drv) scriptName; - scriptPath = "${drv}/share/mpv/scripts/${scriptName}"; - in runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" { + inherit (lib.attrsets) filterAttrs optionalAttrs recursiveUpdate unionOfDisjoint; + + addTests = name: drv: let + inherit (drv) scriptName; + scriptPath = "share/mpv/scripts/${scriptName}"; + fullScriptPath = "${drv}/${scriptPath}"; + + in drv.override { passthru.tests = unionOfDisjoint (drv.passthru.tests or {}) { + + scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" { meta.maintainers = with lib.maintainers; [ nicoo ]; preferLocalBuild = true; } '' - if [ -e "${scriptPath}" ]; then + if [ -e "${fullScriptPath}" ]; then touch $out else echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2 exit 1 fi ''; + + # TODO(nicoo): Avoid emitting the test for scripts that aren't dir-packaged + single-main-in-script-dir = runCommand "mpvScripts.${name}.passthru.tests.single-main-in-script-dir" { + meta.maintainers = with lib.maintainers; [ nicoo ]; + preferLocalBuild = true; + } '' + die() { + echo "$@" >&2 + exit 1 + } + + if ! [ -d "${fullScriptPath}" ]; then + echo "This script isn't dir-packaged" >&2 + touch $out + exit 0 + fi + + cd "${drv}/${scriptPath}" # so the glob expands to filenames only + mains=( main.* ) + if [ "''${#mains[*]}" -eq 1 ]; then + touch $out + elif [ "''${#mains[*]}" -eq 0 ]; then + die "'${scriptPath}' contains no 'main.*' file" + else + die "'${scriptPath}' contains multiple 'main.*' files:" "''${mains[*]}" + fi + ''; }; }; in @@ -50,6 +82,6 @@ lib.recurseIntoAttrs cutter = callPackage ./cutter.nix { }; } // (callPackage ./occivink.nix { inherit buildLua; }))) - // lib.optionalAttrs config.allowAliases { + // optionalAttrs config.allowAliases { youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 } From ad95e2989d252a15dd8a3af78ba3f92f9221e8be Mon Sep 17 00:00:00 2001 From: nicoo Date: Tue, 12 Dec 2023 10:19:25 +0000 Subject: [PATCH 3/6] mpvScripts.mpvacious: Fix `scriptName` --- pkgs/applications/video/mpv/scripts/mpvacious.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/applications/video/mpv/scripts/mpvacious.nix b/pkgs/applications/video/mpv/scripts/mpvacious.nix index 93e1402289cd..9c1c6ce80f62 100644 --- a/pkgs/applications/video/mpv/scripts/mpvacious.nix +++ b/pkgs/applications/video/mpv/scripts/mpvacious.nix @@ -32,6 +32,8 @@ buildLua rec { runHook postInstall ''; + passthru.scriptName = "mpvacious"; + meta = with lib; { description = "Adds mpv keybindings to create Anki cards from movies and TV shows"; homepage = "https://github.com/Ajatt-Tools/mpvacious"; From 14f0b7d7444aa6e1ffd589787b409173b7660fc8 Mon Sep 17 00:00:00 2001 From: nicoo Date: Tue, 12 Dec 2023 10:19:43 +0000 Subject: [PATCH 4/6] mpvScripts.simple-mpv-webui: Fix `scriptName` --- pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix index c3b53c618396..b1f3f4595632 100644 --- a/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix +++ b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix @@ -13,7 +13,7 @@ buildLua rec { }; scriptPath = "."; - passthru.scriptName = "webui.lua"; + passthru.scriptName = "webui"; meta = with lib; { description = "A web based user interface with controls for the mpv mediaplayer"; From f203a40a13c16b76b1937f23cdbaa478a97549af Mon Sep 17 00:00:00 2001 From: nicoo Date: Tue, 12 Dec 2023 10:51:43 +0000 Subject: [PATCH 5/6] mpvScripts: Only emit `tests.single-main-in-script-dir` for dir-packaged scripts --- .../video/mpv/scripts/default.nix | 79 +++++++++---------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 11d9c2e934a9..c4210a0ecf1e 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -7,54 +7,53 @@ let buildLua = callPackage ./buildLua.nix { }; - inherit (lib.attrsets) filterAttrs optionalAttrs recursiveUpdate unionOfDisjoint; + unionOfDisjoints = lib.fold lib.attrsets.unionOfDisjoint {}; addTests = name: drv: let inherit (drv) scriptName; scriptPath = "share/mpv/scripts/${scriptName}"; fullScriptPath = "${drv}/${scriptPath}"; - in drv.override { passthru.tests = unionOfDisjoint (drv.passthru.tests or {}) { + in drv.override { passthru.tests = unionOfDisjoints [ + (drv.passthru.tests or {}) - scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" { - meta.maintainers = with lib.maintainers; [ nicoo ]; - preferLocalBuild = true; - } '' - if [ -e "${fullScriptPath}" ]; then - touch $out - else - echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2 - exit 1 - fi - ''; + { + scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" { + meta.maintainers = with lib.maintainers; [ nicoo ]; + preferLocalBuild = true; + } '' + if [ -e "${fullScriptPath}" ]; then + touch $out + else + echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2 + exit 1 + fi + ''; + } - # TODO(nicoo): Avoid emitting the test for scripts that aren't dir-packaged - single-main-in-script-dir = runCommand "mpvScripts.${name}.passthru.tests.single-main-in-script-dir" { - meta.maintainers = with lib.maintainers; [ nicoo ]; - preferLocalBuild = true; - } '' - die() { - echo "$@" >&2 - exit 1 - } + # can't check whether `fullScriptPath` is a directory, in pure-evaluation mode + (with lib; optionalAttrs (! any (s: hasSuffix s drv.passthru.scriptName) [ ".js" ".lua" ".so" ]) { + single-main-in-script-dir = runCommand "mpvScripts.${name}.passthru.tests.single-main-in-script-dir" { + meta.maintainers = with lib.maintainers; [ nicoo ]; + preferLocalBuild = true; + } '' + die() { + echo "$@" >&2 + exit 1 + } - if ! [ -d "${fullScriptPath}" ]; then - echo "This script isn't dir-packaged" >&2 - touch $out - exit 0 - fi - - cd "${drv}/${scriptPath}" # so the glob expands to filenames only - mains=( main.* ) - if [ "''${#mains[*]}" -eq 1 ]; then - touch $out - elif [ "''${#mains[*]}" -eq 0 ]; then - die "'${scriptPath}' contains no 'main.*' file" - else - die "'${scriptPath}' contains multiple 'main.*' files:" "''${mains[*]}" - fi - ''; - }; }; + cd "${drv}/${scriptPath}" # so the glob expands to filenames only + mains=( main.* ) + if [ "''${#mains[*]}" -eq 1 ]; then + touch $out + elif [ "''${#mains[*]}" -eq 0 ]; then + die "'${scriptPath}' contains no 'main.*' file" + else + die "'${scriptPath}' contains multiple 'main.*' files:" "''${mains[*]}" + fi + ''; + }) + ]; }; in lib.recurseIntoAttrs @@ -82,6 +81,6 @@ lib.recurseIntoAttrs cutter = callPackage ./cutter.nix { }; } // (callPackage ./occivink.nix { inherit buildLua; }))) - // optionalAttrs config.allowAliases { + // lib.optionalAttrs config.allowAliases { youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 } From 764f54631c8fd60ffa965dc8065124353fa1c965 Mon Sep 17 00:00:00 2001 From: nicoo Date: Sun, 24 Dec 2023 11:07:38 +0000 Subject: [PATCH 6/6] mpvScripts: use `overrideAttrs` instead of `override` --- pkgs/applications/video/mpv/scripts/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index c4210a0ecf1e..d1f35882afb1 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -14,8 +14,8 @@ let scriptPath = "share/mpv/scripts/${scriptName}"; fullScriptPath = "${drv}/${scriptPath}"; - in drv.override { passthru.tests = unionOfDisjoints [ - (drv.passthru.tests or {}) + in drv.overrideAttrs (old: { passthru = (old.passthru or {}) // { tests = unionOfDisjoints [ + (old.passthru.tests or {}) { scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" { @@ -53,7 +53,7 @@ let fi ''; }) - ]; }; + ]; }; }); in lib.recurseIntoAttrs