Merge pull request #273158 from nbraud/mpvScripts/scope
mpvScripts: make into a scope
This commit is contained in:
commit
f8a8904e92
1 changed files with 80 additions and 66 deletions
|
@ -1,84 +1,98 @@
|
|||
{ lib
|
||||
, callPackage
|
||||
, config
|
||||
, newScope
|
||||
, runCommand
|
||||
}:
|
||||
|
||||
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
|
||||
scope = self: let
|
||||
inherit (self) callPackage;
|
||||
in lib.mapAttrs addTests {
|
||||
inherit (callPackage ./mpv.nix { })
|
||||
acompressor autocrop autodeint autoload;
|
||||
inherit (callPackage ./occivink.nix { })
|
||||
blacklistExtensions seekTo;
|
||||
|
||||
lib.recurseIntoAttrs
|
||||
(lib.mapAttrs addTests ({
|
||||
chapterskip = callPackage ./chapterskip.nix { inherit buildLua; };
|
||||
convert = callPackage ./convert.nix { inherit buildLua; };
|
||||
cutter = callPackage ./cutter.nix { inherit buildLua; };
|
||||
buildLua = callPackage ./buildLua.nix { };
|
||||
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 { };
|
||||
}
|
||||
// (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
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
(self:
|
||||
assert builtins.intersectAttrs self aliases == {};
|
||||
self // optionalAttrs config.allowAliases aliases)
|
||||
recurseIntoAttrs
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue