1 # Arguments that this derivation gets when it is created with `callPackage`
12 # the unwrapped mpv derivation - 1st argument to `wrapMpv`
16 # arguments to the function (exposed as `wrapMpv` in all-packages.nix)
18 extraMakeWrapperArgs ? [],
19 youtubeSupport ? true,
20 # a set of derivations (probably from `mpvScripts`) where each is
21 # expected to have a `scriptName` passthru attribute that points to the
22 # name of the script that would reside in the script's derivation's
23 # `$out/share/mpv/scripts/`.
24 # A script can optionally also provide an `extraWrapperArgs` passthru attribute.
26 extraUmpvWrapperArgs ? []
29 binPath = lib.makeBinPath ([
31 ] ++ lib.optionals youtubeSupport [
33 ] ++ lib.optionals mpv.vapoursynthSupport [
34 mpv.vapoursynth.python3
36 # All arguments besides the input and output binaries (${mpv}/bin/mpv and
37 # $out/bin/mpv). These are used by the darwin specific makeWrapper call
38 # used to wrap $out/Applications/mpv.app/Contents/MacOS/mpv as well.
39 mostMakeWrapperArgs = lib.strings.escapeShellArgs ([ "--inherit-argv0"
40 # These are always needed (TODO: Explain why)
41 "--prefix" "LUA_CPATH" ";" "${mpv.luaEnv}/lib/lua/${mpv.lua.luaversion}/?.so"
42 "--prefix" "LUA_PATH" ";" "${mpv.luaEnv}/share/lua/${mpv.lua.luaversion}/?.lua"
43 ] ++ lib.optionals mpv.vapoursynthSupport [
44 "--prefix" "PYTHONPATH" ":" "${mpv.vapoursynth}/${mpv.vapoursynth.python3.sitePackages}"
45 ] ++ lib.optionals (binPath != "") [
46 "--prefix" "PATH" ":" binPath
47 ] ++ (lib.lists.flatten (map
48 # For every script in the `scripts` argument, add the necessary flags to the wrapper
52 # Here we rely on the existence of the `scriptName` passthru
53 # attribute of the script derivation from the `scripts`
54 "--script=${script}/share/mpv/scripts/${script.scriptName}"
56 # scripts can also set the `extraWrapperArgs` passthru
57 ++ (script.extraWrapperArgs or [])
59 )) ++ extraMakeWrapperArgs)
61 umpvWrapperArgs = lib.strings.escapeShellArgs ([
63 "--set" "MPV" "${placeholder "out"}/bin/mpv"
64 ] ++ extraUmpvWrapperArgs)
68 name = "mpv-with-scripts-${mpv.version}";
70 # TODO: don't link all mpv outputs and convert package to mpv-unwrapped?
73 nativeBuildInputs = [ makeWrapper ];
75 passthru.unwrapped = mpv;
77 passthru.tests.mpv-scripts-should-not-collide = buildEnv {
78 name = "mpv-scripts-env";
79 paths = lib.pipe mpvScripts [
80 # filters "override" "overrideDerivation" "recurseForDerivations"
81 (lib.filterAttrs (key: script: lib.isDerivation script))
82 # replaces unfree and meta.broken scripts with decent placeholders
83 (lib.mapAttrsToList (key: script:
84 if (builtins.tryEval script.outPath).success
86 else writeTextDir "share/mpv/scripts/${script.scriptName}" "placeholder of ${script.name}"
92 # wrapProgram can't operate on symlinks
94 makeWrapper "${mpv}/bin/mpv" "$out/bin/mpv" ${mostMakeWrapperArgs}
96 makeWrapper "${mpv}/bin/umpv" "$out/bin/umpv" ${umpvWrapperArgs}
97 '' + lib.optionalString stdenv.isDarwin ''
98 # wrapProgram can't operate on symlinks
99 rm "$out/Applications/mpv.app/Contents/MacOS/mpv"
100 makeWrapper "${mpv}/Applications/mpv.app/Contents/MacOS/mpv" "$out/Applications/mpv.app/Contents/MacOS/mpv" ${mostMakeWrapperArgs}
104 inherit (mpv.meta) homepage description longDescription maintainers;
109 lib.makeOverridable wrapper