about summary refs log tree commit diff
path: root/pkgs/applications/video/mpv/scripts/default.nix
blob: ce5188c09d2948ac80b6ffe701417fa1c4bbf0d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{ lib
, config
, newScope
, runCommand
}:

let
  unionOfDisjoints = lib.fold lib.attrsets.unionOfDisjoint {};

  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 {})

      {
        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
          }

          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
        '';
      })
    ]; }; });

  scope = self: let
    inherit (self) callPackage;
  in lib.mapAttrs addTests {
    inherit (callPackage ./mpv.nix { })
      acompressor autocrop autodeint autoload;
    inherit (callPackage ./occivink.nix { })
      blacklistExtensions seekTo;

    buildLua = callPackage ./buildLua.nix { };
    chapterskip = callPackage ./chapterskip.nix { };
    convert = callPackage ./convert.nix { };
    cutter = callPackage ./cutter.nix { };
    dynamic-crop = callPackage ./dynamic-crop.nix { };
    inhibit-gnome = callPackage ./inhibit-gnome.nix { };
    memo = callPackage ./memo.nix { };
    manga-reader = callPackage ./manga-reader.nix { };
    modernx = callPackage ./modernx.nix { };
    modernx-zydezu = callPackage ./modernx-zydezu.nix { };
    mpris = callPackage ./mpris.nix { };
    mpv-cheatsheet = callPackage ./mpv-cheatsheet.nix { };
    mpv-notify-send = callPackage ./mpv-notify-send.nix { };
    mpv-osc-modern = callPackage ./mpv-osc-modern.nix { };
    mpv-playlistmanager = callPackage ./mpv-playlistmanager.nix { };
    mpv-slicing = callPackage ./mpv-slicing.nix { };
    mpv-webm = callPackage ./mpv-webm.nix { };
    mpvacious = callPackage ./mpvacious.nix { };
    quack = callPackage ./quack.nix { };
    quality-menu = callPackage ./quality-menu.nix { };
    reload = callPackage ./reload.nix { };
    simple-mpv-webui = callPackage ./simple-mpv-webui.nix { };
    sponsorblock = callPackage ./sponsorblock.nix { };
    sponsorblock-minimal = callPackage ./sponsorblock-minimal.nix { };
    thumbfast = callPackage ./thumbfast.nix { };
    thumbnail = callPackage ./thumbnail.nix { };
    uosc = callPackage ./uosc.nix { };
    videoclip = callPackage ./videoclip.nix { };
    visualizer = callPackage ./visualizer.nix { };
    vr-reversal = callPackage ./vr-reversal.nix { };
    webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { };
    youtube-upnext = callPackage ./youtube-upnext.nix { };
  };

  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
]