Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpv: Move all wrappings to a single wrapper Nix function #88620

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions pkgs/applications/video/mpv/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, stdenv, fetchurl, fetchFromGitHub, makeWrapper, fetchpatch
{ config, stdenv, fetchurl, fetchFromGitHub, fetchpatch
, addOpenGLRunpath, docutils, perl, pkgconfig, python3, wafHook, which
, ffmpeg_4, freefont_ttf, freetype, libass, libpthreadstubs, mujs
, nv-codec-headers, lua, libuchardet, libiconv ? null
Expand Down Expand Up @@ -50,7 +50,6 @@
, vdpauSupport ? true, libvdpau ? null
, xineramaSupport ? stdenv.isLinux, libXinerama ? null
, xvSupport ? stdenv.isLinux, libXv ? null
, youtubeSupport ? true, youtube-dl ? null
, zimgSupport ? true, zimg ? null
, archiveSupport ? true, libarchive ? null
, jackaudioSupport ? false, libjack2 ? null
Expand Down Expand Up @@ -91,7 +90,6 @@ assert waylandSupport -> all available [ wayland wayland-protocols libxkbcom
assert x11Support -> all available [ libGLU libGL libX11 libXext libXxf86vm libXrandr ];
assert xineramaSupport -> x11Support && available libXinerama;
assert xvSupport -> x11Support && available libXv;
assert youtubeSupport -> available youtube-dl;
assert zimgSupport -> available zimg;

let
Expand All @@ -112,6 +110,20 @@ in stdenv.mkDerivation rec {
patchShebangs ./TOOLS/
'';

passthru = {
inherit
# The wrapper consults luaEnv and lua.version
luaEnv
lua
# In the wrapper, we want to reference vapoursynth which has the
# `python3` passthru attribute (which has the `sitePrefix`
# attribute). This way we'll be sure that in the wrapper we'll
# use the same python3.sitePrefix used to build vapoursynth.
vapoursynthSupport
vapoursynth
;
};

NIX_LDFLAGS = optionalString x11Support "-lX11 -lXext "
+ optionalString stdenv.isDarwin "-framework CoreFoundation";

Expand All @@ -135,7 +147,7 @@ in stdenv.mkDerivation rec {
++ stdenv.lib.optional (!swiftSupport) "--disable-macos-cocoa-cb";

nativeBuildInputs = [
addOpenGLRunpath docutils makeWrapper perl pkgconfig python3 wafHook which
addOpenGLRunpath docutils perl pkgconfig python3 wafHook which
]
++ optional swiftSupport swift;

Expand Down Expand Up @@ -164,7 +176,6 @@ in stdenv.mkDerivation rec {
++ optional vdpauSupport libvdpau
++ optional xineramaSupport libXinerama
++ optional xvSupport libXv
++ optional youtubeSupport youtube-dl
++ optional zimgSupport zimg
++ optional stdenv.isDarwin libiconv
++ optional stdenv.isLinux nv-codec-headers
Expand All @@ -182,17 +193,6 @@ in stdenv.mkDerivation rec {
python3 TOOLS/osxbundle.py -s build/mpv
'';

# Ensure youtube-dl is available in $PATH for mpv
wrapperFlags =
''--prefix LUA_CPATH ';' "${luaEnv}/lib/lua/${lua.luaversion}/?.so" \'' +
''--prefix LUA_PATH ';' "${luaEnv}/share/lua/${lua.luaversion}/?.lua" \'' +
''--prefix PATH : "${luaEnv}/bin" \''
+ optionalString youtubeSupport ''
--prefix PATH : "${youtube-dl}/bin" \
'' + optionalString vapoursynthSupport ''
--prefix PYTHONPATH : "${vapoursynth}/lib/${python3.libPrefix}/site-packages:$PYTHONPATH"
'';

patches = stdenv.lib.optionals stdenv.isDarwin [
# Fix cocoa backend. Remove with the next release
(fetchpatch {
Expand All @@ -205,24 +205,17 @@ in stdenv.mkDerivation rec {
# Use a standard font
mkdir -p $out/share/mpv
ln -s ${freefont_ttf}/share/fonts/truetype/FreeSans.ttf $out/share/mpv/subfont.ttf
wrapProgram "$out/bin/mpv" \
${wrapperFlags}

cp TOOLS/umpv $out/bin
wrapProgram $out/bin/umpv \
--set MPV "$out/bin/mpv"

'' + optionalString stdenv.isDarwin ''
mkdir -p $out/Applications
cp -r build/mpv.app $out/Applications
wrapProgram "$out/Applications/mpv.app/Contents/MacOS/mpv" \
${wrapperFlags}
'';

# Set RUNPATH so that libcuda in /run/opengl-driver(-32)/lib can be found.
# See the explanation in addOpenGLRunpath.
postFixup = optionalString stdenv.isLinux ''
addOpenGLRunpath $out/bin/.mpv-wrapped
addOpenGLRunpath $out/bin/mpv
'';

meta = with stdenv.lib; {
Expand Down
89 changes: 79 additions & 10 deletions pkgs/applications/video/mpv/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,83 @@
{ stdenv, symlinkJoin, makeWrapper, mpv, scripts ? [] }:
# Arguments that this derivation gets when it is created with `callPackage`
{ stdenv
, lib
, symlinkJoin
, makeWrapper
, youtube-dl
}:

symlinkJoin {
name = "mpv-with-scripts-${mpv.version}";
# the unwrapped mpv derivation - 1st argument to `wrapMpv`
mpv:

paths = [ mpv ];
let
# arguments to the function (called `wrapMpv` in all-packages.nix)
wrapper = {
extraMakeWrapperArgs ? [],
youtubeSupport ? true,
# a set of derivations (probably from `mpvScripts`) where each is
# expected to have a `scriptName` passthru attribute that points to the
# name of the script that would reside in the script's derivation's
# `$out/share/mpv/scripts/`.
scripts ? [],
extraUmpvWrapperArgs ? []
}:
let
binPath = lib.makeBinPath ([
mpv.luaEnv
] ++ lib.optionals youtubeSupport [
youtube-dl
] ++ lib.optionals mpv.vapoursynthSupport [
mpv.vapoursynth.python3
]);
# All arguments besides the input and output binaries (${mpv}/bin/mpv and
# $out/bin/mpv). These are used by the darwin specific makeWrapper call
# used to wrap $out/Applications/mpv.app/Contents/MacOS/mpv as well.
mostMakeWrapperArgs = builtins.concatStringsSep " " ([ "--argv0" "'$0'"
# These are always needed (TODO: Explain why)
"--prefix" "LUA_CPATH" "\\;" "${mpv.luaEnv}/lib/lua/${mpv.lua.luaversion}/\\?.so"
"--prefix" "LUA_PATH" "\\;" "${mpv.luaEnv}/share/lua/${mpv.lua.luaversion}/\\?.lua"
] ++ lib.optionals mpv.vapoursynthSupport [
"--prefix" "PYTHONPATH" ":" "${mpv.vapoursynth}/lib/${mpv.vapoursynth.python3.sitePackages}"
] ++ lib.optionals (binPath != "") [
"--prefix" "PATH" ":" binPath
] ++ (lib.lists.flatten (map
# For every script in the `scripts` argument, add the necessary flags to the wrapper
(script:
[
"--add-flags"
# Here we rely on the existence of the `scriptName` passthru
# attribute of the script derivation from the `scripts`
"--script=${script}/share/mpv/scripts/${script.scriptName}"
]
) scripts
)) ++ extraMakeWrapperArgs)
;
umpvWrapperArgs = builtins.concatStringsSep " " ([
"--argv0" "'$0'"
"--set" "MPV" "$out/bin/mpv"
] ++ extraUmpvWrapperArgs)
;
in
symlinkJoin {
name = "mpv-with-scripts-${mpv.version}";

buildInputs = [ makeWrapper ];
paths = [ mpv ];

postBuild = ''
wrapProgram $out/bin/mpv \
--add-flags "${stdenv.lib.concatMapStringsSep " " (x: "--script=${x}/share/mpv/scripts/${x.scriptName}") scripts}"
'';
}
buildInputs = [ makeWrapper ];

passthru.unwrapped = mpv;

postBuild = ''
# wrapProgram can't operate on symlinks
rm "$out/bin/mpv"
makeWrapper "${mpv}/bin/mpv" "$out/bin/mpv" ${mostMakeWrapperArgs}
rm "$out/bin/umpv"
makeWrapper "${mpv}/bin/umpv" "$out/bin/umpv" ${umpvWrapperArgs}
'' + lib.optionalString stdenv.isDarwin ''
# wrapProgram can't operate on symlinks
rm "$out/Applications/mpv.app/Contents/MacOS/mpv"
makeWrapper "${mpv}/Applications/mpv.app/Contents/MacOS/mpv" "$out/Applications/mpv.app/Contents/MacOS/mpv" ${mostMakeWrapperArgs}
'';
};
in
lib.makeOverridable wrapper
8 changes: 8 additions & 0 deletions pkgs/development/libraries/vapoursynth/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ stdenv.mkDerivation rec {

enableParallelBuilding = true;

passthru = {
# If vapoursynth is added to the build inputs of mpv and then
# used in the wrapping of it, we want to know once inside the
# wrapper, what python3 version was used to build vapoursynth so
# the right python3.sitePackages will be used there.
inherit python3;
};

postInstall = ''
wrapProgram $out/bin/vspipe \
--prefix PYTHONPATH : $out/${python3.sitePackages}
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/aliases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ mapAliases ({
msf = metasploit; # added 2018-04-25
libmsgpack = msgpack; # added 2018-08-17
mssys = ms-sys; # added 2015-12-13
mpv-with-scripts = throw "Use wrapMpv for editing the environment of mpv"; # added 2012-05-22
multipath_tools = multipath-tools; # added 2016-01-21
mupen64plus1_5 = mupen64plus; # added 2016-02-12
mysqlWorkbench = mysql-workbench; # added 2017-01-19
Expand Down
6 changes: 4 additions & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20862,12 +20862,14 @@ in
libdvdnav = libdvdnav_4_2_1;
} // (config.mplayer or {}));

mpv = callPackage ../applications/video/mpv {
mpv-unwrapped = callPackage ../applications/video/mpv {
inherit lua;
inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa CoreAudio MediaPlayer;
};

mpv-with-scripts = callPackage ../applications/video/mpv/wrapper.nix { };
# Wraps without trigerring a rebuild
wrapMpv = callPackage ../applications/video/mpv/wrapper.nix { };
mpv = wrapMpv mpv-unwrapped {};

mpvScripts = recurseIntoAttrs {
convert = callPackage ../applications/video/mpv/scripts/convert.nix {};
Expand Down