diff options
Diffstat (limited to 'pkgs/applications/video/mpv')
-rw-r--r-- | pkgs/applications/video/mpv/default.nix | 48 | ||||
-rw-r--r-- | pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix | 33 | ||||
-rw-r--r-- | pkgs/applications/video/mpv/scripts/sponsorblock.nix | 51 | ||||
-rw-r--r-- | pkgs/applications/video/mpv/wrapper.nix | 89 |
4 files changed, 186 insertions, 35 deletions
diff --git a/pkgs/applications/video/mpv/default.nix b/pkgs/applications/video/mpv/default.nix index 50b67f45558..697a468f890 100644 --- a/pkgs/applications/video/mpv/default.nix +++ b/pkgs/applications/video/mpv/default.nix @@ -1,6 +1,6 @@ -{ 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 +, ffmpeg, freefont_ttf, freetype, libass, libpthreadstubs, mujs , nv-codec-headers, lua, libuchardet, libiconv ? null , CoreFoundation, Cocoa, CoreAudio, MediaPlayer @@ -39,7 +39,10 @@ , libpngSupport ? true, libpng ? null , pulseSupport ? config.pulseaudio or stdenv.isLinux, libpulseaudio ? null , rubberbandSupport ? stdenv.isLinux, rubberband ? null -, sambaSupport ? stdenv.isLinux, samba ? null +# NOTE: samba support should be removed on the next mpv release, see also: +# https://github.com/NixOS/nixpkgs/pull/89145#issuecomment-636424362 +# Please remove this line on the next mpv release. +, sambaSupport ? false, samba ? null , screenSaverSupport ? true, libXScrnSaver ? null , sdl2Support ? true, SDL2 ? null , sndioSupport ? true, sndio ? null @@ -50,7 +53,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 @@ -91,7 +93,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 @@ -112,6 +113,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"; @@ -135,12 +150,12 @@ 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; buildInputs = [ - ffmpeg_4 freetype libass libpthreadstubs + ffmpeg freetype libass libpthreadstubs luaEnv libuchardet mujs ] ++ optional alsaSupport alsaLib ++ optional archiveSupport libarchive @@ -164,7 +179,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 @@ -182,15 +196,6 @@ in stdenv.mkDerivation rec { python3 TOOLS/osxbundle.py -s build/mpv ''; - # Ensure youtube-dl is available in $PATH for mpv - wrapperFlags = - ''--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 { @@ -203,24 +208,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; { diff --git a/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix new file mode 100644 index 00000000000..d51434e241c --- /dev/null +++ b/pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix @@ -0,0 +1,33 @@ +{ stdenv +, fetchFromGitHub }: +stdenv.mkDerivation rec { + pname = "simple-mpv-ui"; + version = "1.0.0"; + + src = fetchFromGitHub { + owner = "open-dynaMIX"; + repo = "simple-mpv-webui"; + rev = "v${version}"; + sha256 = "1glrnnl1slcl0ri0zs4j64lc9aa52p9ffh6av0d81fk95nm98917"; + }; + + dontBuild = true; + installPhase = '' + mkdir -p $out/share/mpv/scripts + cp -r webui.lua webui-page $out/share/mpv/scripts/ + ''; + passthru.scriptName = "webui.lua"; + + meta = with stdenv.lib; { + description = "A web based user interface with controls for the mpv mediaplayer"; + homepage = "https://github.com/open-dynaMIX/simple-mpv-webui"; + maintainers = [ maintainers.cript0nauta ]; + longDescription = '' + You can access the webui when accessing http://127.0.0.1:8080 or + http://[::1]:8080 in your webbrowser. By default it listens on + 0.0.0.0:8080 and [::0]:8080 + ''; + license = licenses.mit; + }; +} + diff --git a/pkgs/applications/video/mpv/scripts/sponsorblock.nix b/pkgs/applications/video/mpv/scripts/sponsorblock.nix new file mode 100644 index 00000000000..8213e514d2b --- /dev/null +++ b/pkgs/applications/video/mpv/scripts/sponsorblock.nix @@ -0,0 +1,51 @@ +{ stdenv, fetchFromGitHub, fetchpatch, python3 }: + +# Usage: `pkgs.mpv.override { scripts = [ pkgs.mpvScripts.sponsorblock ]; }` +stdenv.mkDerivation { + pname = "mpv_sponsorblock"; + version = "unstable-2020-07-05"; + + src = fetchFromGitHub { + owner = "po5"; + repo = "mpv_sponsorblock"; + rev = "f71e49e0531350339134502e095721fdc66eac20"; + sha256 = "1fr4cagzs26ygxyk8dxqvjw4n85fzv6is6cb1jhr2qnsjg6pa0p8"; + }; + + dontBuild = true; + + patches = [ + # Use XDG_DATA_HOME and XDG_CACHE_HOME if defined for UID and DB + # Necessary to avoid sponsorblock to write in the nix store at runtime. + # https://github.com/po5/mpv_sponsorblock/pull/17 + (fetchpatch { + url = "https://github.com/po5/mpv_sponsorblock/pull/17/commits/e65b360a7d03a3430b4829e457a6670b2f617b09.patch"; + sha256 = "00wv0pvbz0dz2ibka66zhl2jk0pil4pyv6ipjfz37i81q6szyhs5"; + }) + (fetchpatch { + url = "https://github.com/po5/mpv_sponsorblock/pull/17/commits/3832304d959205e99120a14c0560ed3c37104b08.patch"; + sha256 = "149ffvn714n2m3mqs8mgrbs24bcr74kqfkx7wyql36ndhm88xd2z"; + }) + ]; + + postPatch = '' + substituteInPlace sponsorblock.lua \ + --replace "python3" "${python3}/bin/python3" \ + --replace 'mp.find_config_file("scripts")' "\"$out/share/mpv/scripts\"" + ''; + + installPhase = '' + mkdir -p $out/share/mpv/scripts + cp -r sponsorblock.lua sponsorblock_shared $out/share/mpv/scripts/ + ''; + + passthru.scriptName = "sponsorblock.lua"; + + meta = with stdenv.lib; { + description = "mpv script to skip sponsored segments of YouTube videos"; + homepage = "https://github.com/po5/mpv_sponsorblock"; + license = licenses.gpl3; + platforms = platforms.all; + maintainers = with maintainers; [ pacien ]; + }; +} diff --git a/pkgs/applications/video/mpv/wrapper.nix b/pkgs/applications/video/mpv/wrapper.nix index 53def80e7da..5b3ad7a9831 100644 --- a/pkgs/applications/video/mpv/wrapper.nix +++ b/pkgs/applications/video/mpv/wrapper.nix @@ -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 = lib.strings.escapeShellArgs ([ "--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 = lib.strings.escapeShellArgs ([ + "--argv0" "'$0'" + "--set" "MPV" "${placeholder "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 |