From 81d6df0268747d1a32ea85d37b4276fd23a9795d Mon Sep 17 00:00:00 2001 From: nicoo Date: Sat, 9 Dec 2023 15:43:58 +0000 Subject: [PATCH 1/5] mpvScripts: Avoid mixing `//` and `callPackage` This will avoid an infinite recursion issue when turned into a scope --- pkgs/applications/video/mpv/scripts/default.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 3520138a7d60..a3de7e315a2b 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -58,6 +58,11 @@ in lib.recurseIntoAttrs (lib.mapAttrs addTests ({ + inherit (callPackage ./mpv.nix { inherit buildLua; }) + acompressor autocrop autodeint autoload; + inherit (callPackage ./occivink.nix { inherit buildLua; }) + blacklistExtensions seekTo; + chapterskip = callPackage ./chapterskip.nix { inherit buildLua; }; convert = callPackage ./convert.nix { inherit buildLua; }; cutter = callPackage ./cutter.nix { inherit buildLua; }; @@ -76,9 +81,7 @@ lib.recurseIntoAttrs visualizer = callPackage ./visualizer.nix { inherit buildLua; }; vr-reversal = callPackage ./vr-reversal.nix { }; webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; - } - // (callPackage ./mpv.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 6b186414ded05f306218883a861f958386450252 Mon Sep 17 00:00:00 2001 From: nicoo Date: Sat, 9 Dec 2023 15:44:44 +0000 Subject: [PATCH 2/5] mpvScripts.buildLua: Expose to nixpkgs users --- .../video/mpv/scripts/default.nix | 91 ++++++++++--------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index a3de7e315a2b..3c1af55a2921 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -5,64 +5,65 @@ }: let - buildLua = callPackage ./buildLua.nix { }; - unionOfDisjoints = lib.fold lib.attrsets.unionOfDisjoint {}; - addTests = name: drv: let - inherit (drv) scriptName; - scriptPath = "share/mpv/scripts/${scriptName}"; - fullScriptPath = "${drv}/${scriptPath}"; + addTests = name: drv: + if ! lib.isDerivation drv then + drv + else let + inherit (drv) scriptName; + scriptPath = "share/mpv/scripts/${scriptName}"; + fullScriptPath = "${drv}/${scriptPath}"; + in drv.overrideAttrs (old: { passthru = (old.passthru or {}) // { tests = unionOfDisjoints [ + (old.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" { + 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 - ''; - } + # 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 + } - # 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 - } - - 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 - (lib.mapAttrs addTests ({ + (lib.mapAttrs addTests (rec { inherit (callPackage ./mpv.nix { inherit buildLua; }) acompressor autocrop autodeint autoload; inherit (callPackage ./occivink.nix { inherit buildLua; }) blacklistExtensions seekTo; + buildLua = callPackage ./buildLua.nix { }; chapterskip = callPackage ./chapterskip.nix { inherit buildLua; }; convert = callPackage ./convert.nix { inherit buildLua; }; cutter = callPackage ./cutter.nix { inherit buildLua; }; From 614afa6014f7d289f606c46c6840c81976948a3a Mon Sep 17 00:00:00 2001 From: nicoo Date: Sat, 9 Dec 2023 15:49:35 +0000 Subject: [PATCH 3/5] mpvScripts: Make into a scope --- .../video/mpv/scripts/default.nix | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 3c1af55a2921..98860e1f2cba 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -1,6 +1,6 @@ { lib -, callPackage , config +, newScope , runCommand }: @@ -56,33 +56,34 @@ let ]; }; }); in -lib.recurseIntoAttrs - (lib.mapAttrs addTests (rec { - inherit (callPackage ./mpv.nix { inherit buildLua; }) +lib.recurseIntoAttrs (lib.makeScope newScope (self: + let inherit (self) callPackage; + in lib.mapAttrs addTests { + inherit (callPackage ./mpv.nix { }) acompressor autocrop autodeint autoload; - inherit (callPackage ./occivink.nix { inherit buildLua; }) + inherit (callPackage ./occivink.nix { }) blacklistExtensions seekTo; buildLua = callPackage ./buildLua.nix { }; - chapterskip = callPackage ./chapterskip.nix { inherit buildLua; }; - convert = callPackage ./convert.nix { inherit buildLua; }; - cutter = callPackage ./cutter.nix { inherit buildLua; }; + chapterskip = callPackage ./chapterskip.nix { }; + convert = callPackage ./convert.nix { }; + cutter = callPackage ./cutter.nix { }; inhibit-gnome = callPackage ./inhibit-gnome.nix { }; mpris = callPackage ./mpris.nix { }; - mpv-playlistmanager = callPackage ./mpv-playlistmanager.nix { inherit buildLua; }; - mpv-webm = callPackage ./mpv-webm.nix { inherit buildLua; }; - mpvacious = callPackage ./mpvacious.nix { inherit buildLua; }; - quality-menu = callPackage ./quality-menu.nix { inherit buildLua; }; - simple-mpv-webui = callPackage ./simple-mpv-webui.nix { inherit buildLua; }; + mpv-playlistmanager = callPackage ./mpv-playlistmanager.nix { }; + mpv-webm = callPackage ./mpv-webm.nix { }; + mpvacious = callPackage ./mpvacious.nix { }; + quality-menu = callPackage ./quality-menu.nix { }; + simple-mpv-webui = callPackage ./simple-mpv-webui.nix { }; sponsorblock = callPackage ./sponsorblock.nix { }; - sponsorblock-minimal = callPackage ./sponsorblock-minimal.nix { inherit buildLua; }; - thumbfast = callPackage ./thumbfast.nix { inherit buildLua; }; - thumbnail = callPackage ./thumbnail.nix { inherit buildLua; }; - uosc = callPackage ./uosc.nix { inherit buildLua; }; - visualizer = callPackage ./visualizer.nix { inherit buildLua; }; + sponsorblock-minimal = callPackage ./sponsorblock-minimal.nix { }; + thumbfast = callPackage ./thumbfast.nix { }; + thumbnail = callPackage ./thumbnail.nix { }; + uosc = callPackage ./uosc.nix { }; + visualizer = callPackage ./visualizer.nix { }; vr-reversal = callPackage ./vr-reversal.nix { }; webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; - })) + } // lib.optionalAttrs config.allowAliases { youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 -} + })) From 08de7bd96147bca47ee7428c620707cbb34cef9f Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 27 Dec 2023 22:59:08 +0000 Subject: [PATCH 4/5] mpvScripts: Refactor `default.nix` It seems a bit easier to follow what is going on --- .../video/mpv/scripts/default.nix | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 98860e1f2cba..2c310cd410b6 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -54,10 +54,9 @@ let ''; }) ]; }; }); -in -lib.recurseIntoAttrs (lib.makeScope newScope (self: - let inherit (self) callPackage; + scope = self: let + inherit (self) callPackage; in lib.mapAttrs addTests { inherit (callPackage ./mpv.nix { }) acompressor autocrop autodeint autoload; @@ -83,7 +82,15 @@ lib.recurseIntoAttrs (lib.makeScope newScope (self: visualizer = callPackage ./visualizer.nix { }; vr-reversal = callPackage ./vr-reversal.nix { }; webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; - } - // lib.optionalAttrs config.allowAliases { - youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 - })) + }; + + aliases = lib.optionalAttrs config.allowAliases { + youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 + }; +in + +with lib; pipe scope [ + (makeScope newScope) + (attrsets.unionOfDisjoint aliases) + recurseIntoAttrs +] From ef51456d0f2b01674d62f658ff5f5b286e27d24b Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 27 Dec 2023 23:08:17 +0000 Subject: [PATCH 5/5] mpvScripts: Immediately error on collisions between `scope` and `aliases` This makes mistakes more obvious, and ensures the error happens independently of config.allowAliases, so any build will catch it. --- pkgs/applications/video/mpv/scripts/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/video/mpv/scripts/default.nix b/pkgs/applications/video/mpv/scripts/default.nix index 2c310cd410b6..158a7c491007 100644 --- a/pkgs/applications/video/mpv/scripts/default.nix +++ b/pkgs/applications/video/mpv/scripts/default.nix @@ -84,13 +84,15 @@ let webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; }; - aliases = lib.optionalAttrs config.allowAliases { + aliases = { youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 }; in with lib; pipe scope [ (makeScope newScope) - (attrsets.unionOfDisjoint aliases) + (self: + assert builtins.intersectAttrs self aliases == {}; + self // optionalAttrs config.allowAliases aliases) recurseIntoAttrs ]