1 # Arguments that this derivation gets when it is created with `callPackage`
11 # the unwrapped mpv derivation
15 # arguments to the function (exposed as `mpv-unwrapped.wrapper` in top-level)
19 extraMakeWrapperArgs ? [ ],
20 youtubeSupport ? true,
21 # a set of derivations (probably from `mpvScripts`) where each is expected
22 # to have a `scriptName` passthru attribute that points to the name of the
23 # script that would reside in the script's derivation's
24 # `$out/share/mpv/scripts/`.
26 # A script can optionally also provide `passthru.extraWrapperArgs`
29 extraUmpvWrapperArgs ? [ ],
32 binPath = lib.makeBinPath (
36 ++ lib.optionals youtubeSupport [
39 ++ lib.optionals mpv.vapoursynthSupport [
40 mpv.vapoursynth.python3
43 # All arguments besides the input and output binaries (${mpv}/bin/mpv and
44 # $out/bin/mpv). These are used by the darwin specific makeWrapper call
45 # used to wrap $out/Applications/mpv.app/Contents/MacOS/mpv as well.
46 mostMakeWrapperArgs = lib.strings.escapeShellArgs (
49 # These are always needed (TODO: Explain why)
53 "${mpv.luaEnv}/lib/lua/${mpv.lua.luaversion}/?.so"
57 "${mpv.luaEnv}/share/lua/${mpv.lua.luaversion}/?.lua"
59 ++ lib.optionals mpv.vapoursynthSupport [
63 "${mpv.vapoursynth}/${mpv.vapoursynth.python3.sitePackages}"
65 ++ lib.optionals (binPath != "") [
71 ++ (lib.lists.flatten (
73 # For every script in the `scripts` argument, add the necessary flags to the wrapper
78 # Here we rely on the existence of the `scriptName` passthru
79 # attribute of the script derivation from the `scripts`
80 "--script=${script}/share/mpv/scripts/${script.scriptName}"
82 # scripts can also set the `extraWrapperArgs` passthru
83 ++ (script.extraWrapperArgs or [ ])
87 ++ extraMakeWrapperArgs
89 umpvWrapperArgs = lib.strings.escapeShellArgs (
94 "${placeholder "out"}/bin/mpv"
96 ++ extraUmpvWrapperArgs
100 name = "mpv-with-scripts-${mpv.version}";
102 # TODO: don't link all mpv outputs and convert package to mpv-unwrapped?
105 nativeBuildInputs = [ makeWrapper ];
107 passthru.unwrapped = mpv;
109 passthru.tests.mpv-scripts-should-not-collide = buildEnv {
110 name = "mpv-scripts-env";
111 paths = lib.pipe mpvScripts [
112 # filters "override" "overrideDerivation" "recurseForDerivations"
113 (lib.filterAttrs (key: script: lib.isDerivation script))
114 # replaces unfree and meta.broken scripts with decent placeholders
115 (lib.mapAttrsToList (
117 if (builtins.tryEval script.outPath).success then
120 writeTextDir "share/mpv/scripts/${script.scriptName}" "placeholder of ${script.name}"
127 # wrapProgram can't operate on symlinks
129 makeWrapper "${mpv}/bin/mpv" "$out/bin/mpv" ${mostMakeWrapperArgs}
131 makeWrapper "${mpv}/bin/umpv" "$out/bin/umpv" ${umpvWrapperArgs}
133 + lib.optionalString stdenv.hostPlatform.isDarwin ''
134 # wrapProgram can't operate on symlinks
135 rm "$out/Applications/mpv.app/Contents/MacOS/mpv"
136 makeWrapper "${mpv}/Applications/mpv.app/Contents/MacOS/mpv" "$out/Applications/mpv.app/Contents/MacOS/mpv" ${mostMakeWrapperArgs}
150 lib.makeOverridable wrapper