biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / applications / video / mpv / default.nix
blob163729d879b9ab4eab1307753f4406db1c23dd47
1 { lib
2 , config
3 , stdenv
4 , fetchFromGitHub
5 , fetchpatch
6 , addOpenGLRunpath
7 , bash
8 , docutils
9 , meson
10 , ninja
11 , pkg-config
12 , python3
13 , ffmpeg
14 , freefont_ttf
15 , freetype
16 , libass
17 , libpthreadstubs
18 , nv-codec-headers-11
19 , lua
20 , libuchardet
21 , libiconv
22 , xcbuild
23 , rcodesign
25 , waylandSupport ? stdenv.isLinux
26   , wayland
27   , wayland-protocols
28   , wayland-scanner
29   , libxkbcommon
31 , x11Support ? stdenv.isLinux
32   , libGLU, libGL
33   , libX11
34   , libXext
35   , libXxf86vm
36   , libXrandr
37   , libXpresent
39 , cddaSupport ? false
40   , libcdio
41   , libcdio-paranoia
43 , vulkanSupport ? stdenv.isLinux
44   , libplacebo
45   , shaderc # instead of spirv-cross
46   , vulkan-headers
47   , vulkan-loader
49 , drmSupport ? stdenv.isLinux
50   , libdrm
51   , mesa
53 , alsaSupport        ? stdenv.isLinux, alsa-lib
54 , archiveSupport     ? true,           libarchive
55 , bluraySupport      ? true,           libbluray
56 , bs2bSupport        ? true,           libbs2b
57 , cacaSupport        ? true,           libcaca
58 , cmsSupport         ? true,           lcms2
59 , dvdnavSupport      ? stdenv.isLinux, libdvdnav
60 , dvbinSupport       ? stdenv.isLinux
61 , jackaudioSupport   ? false,          libjack2
62 , javascriptSupport  ? true,           mujs
63 , libpngSupport      ? true,           libpng
64 , openalSupport      ? true,           openalSoft
65 , pulseSupport       ? config.pulseaudio or stdenv.isLinux, libpulseaudio
66 , pipewireSupport    ? stdenv.isLinux, pipewire
67 , rubberbandSupport  ? true,           rubberband
68 , screenSaverSupport ? true,           libXScrnSaver
69 , sdl2Support        ? true,           SDL2
70 , sixelSupport       ? false,          libsixel
71 , speexSupport       ? true,           speex
72 , swiftSupport       ? stdenv.isDarwin, swift
73 , theoraSupport      ? true,           libtheora
74 , vaapiSupport       ? x11Support || waylandSupport, libva
75 , vapoursynthSupport ? false,          vapoursynth
76 , vdpauSupport       ? true,           libvdpau
77 , xineramaSupport    ? stdenv.isLinux, libXinerama
78 , xvSupport          ? stdenv.isLinux, libXv
79 , zimgSupport        ? true,           zimg
80 , darwin
83 let
84   inherit (darwin.apple_sdk_11_0.frameworks)
85     AVFoundation Accelerate Cocoa CoreAudio CoreFoundation CoreMedia
86     MediaPlayer VideoToolbox;
87   luaEnv = lua.withPackages (ps: with ps; [ luasocket ]);
89   overrideSDK = platform: version:
90     platform // lib.optionalAttrs (platform ? darwinMinVersion) {
91       darwinMinVersion = version;
92     };
94   stdenv' = if swiftSupport && stdenv.isDarwin && stdenv.isx86_64
95     then stdenv.override (old: {
96       buildPlatform = overrideSDK old.buildPlatform "10.15";
97       hostPlatform = overrideSDK old.hostPlatform "10.15";
98       targetPlatform = overrideSDK old.targetPlatform "10.15";
99     })
100     else stdenv;
101 in stdenv'.mkDerivation (finalAttrs: {
102   pname = "mpv";
103   version = "0.37.0";
105   outputs = [ "out" "dev" "doc" "man" ];
107   src = fetchFromGitHub {
108     owner = "mpv-player";
109     repo = "mpv";
110     rev = "v${finalAttrs.version}";
111     hash = "sha256-izAz9Iiam7tJAWIQkmn2cKOfoaog8oPKq4sOUtp1nvU=";
112   };
114   patches = [ ./darwin-sigtool-no-deep.patch ];
116   postPatch = lib.concatStringsSep "\n" [
117     # Don't reference compile time dependencies or create a build outputs cycle
118     # between out and dev
119     ''
120     substituteInPlace meson.build \
121       --replace-fail "conf_data.set_quoted('CONFIGURATION', configuration)" \
122                      "conf_data.set_quoted('CONFIGURATION', '<ommited>')"
123     ''
124     # A trick to patchShebang everything except mpv_identify.sh
125     ''
126     pushd TOOLS
127     mv mpv_identify.sh mpv_identify
128     patchShebangs *.py *.sh
129     mv mpv_identify mpv_identify.sh
130     popd
131     ''
132   ];
134   # Ensure we reference 'lib' (not 'out') of Swift.
135   preConfigure = lib.optionalString swiftSupport ''
136     export SWIFT_LIB_DYNAMIC="${lib.getLib swift.swift}/lib/swift/macosx"
137   '';
139   mesonFlags = [
140     (lib.mesonOption "default_library" "shared")
141     (lib.mesonBool "libmpv" true)
142     (lib.mesonEnable "libarchive" archiveSupport)
143     (lib.mesonEnable "manpage-build" true)
144     (lib.mesonEnable "cdda" cddaSupport)
145     (lib.mesonEnable "dvbin" dvbinSupport)
146     (lib.mesonEnable "dvdnav" dvdnavSupport)
147     (lib.mesonEnable "openal" openalSupport)
148     (lib.mesonEnable "sdl2" sdl2Support)
149     # Disable whilst Swift isn't supported
150     (lib.mesonEnable "swift-build" swiftSupport)
151     (lib.mesonEnable "macos-cocoa-cb" swiftSupport)
152   ] ++ lib.optionals stdenv.isDarwin [
153     # Toggle explicitly because it fails on darwin
154     (lib.mesonEnable "videotoolbox-pl" vulkanSupport)
155   ];
157   mesonAutoFeatures = "auto";
159   nativeBuildInputs = [
160     addOpenGLRunpath
161     docutils # for rst2man
162     meson
163     ninja
164     pkg-config
165   ]
166   ++ lib.optionals stdenv.isDarwin [ xcbuild.xcrun rcodesign ]
167   ++ lib.optionals swiftSupport [ swift ]
168   ++ lib.optionals waylandSupport [ wayland-scanner ];
170   buildInputs = [
171     bash
172     ffmpeg
173     freetype
174     libass
175     libplacebo
176     libpthreadstubs
177     libuchardet
178     luaEnv
179     python3
180   ] ++ lib.optionals alsaSupport        [ alsa-lib ]
181     ++ lib.optionals archiveSupport     [ libarchive ]
182     ++ lib.optionals bluraySupport      [ libbluray ]
183     ++ lib.optionals bs2bSupport        [ libbs2b ]
184     ++ lib.optionals cacaSupport        [ libcaca ]
185     ++ lib.optionals cddaSupport        [ libcdio libcdio-paranoia ]
186     ++ lib.optionals cmsSupport         [ lcms2 ]
187     ++ lib.optionals drmSupport         [ libdrm mesa ]
188     ++ lib.optionals dvdnavSupport      [ libdvdnav libdvdnav.libdvdread ]
189     ++ lib.optionals jackaudioSupport   [ libjack2 ]
190     ++ lib.optionals javascriptSupport  [ mujs ]
191     ++ lib.optionals libpngSupport      [ libpng ]
192     ++ lib.optionals openalSupport      [ openalSoft ]
193     ++ lib.optionals pipewireSupport    [ pipewire ]
194     ++ lib.optionals pulseSupport       [ libpulseaudio ]
195     ++ lib.optionals rubberbandSupport  [ rubberband ]
196     ++ lib.optionals screenSaverSupport [ libXScrnSaver ]
197     ++ lib.optionals sdl2Support        [ SDL2 ]
198     ++ lib.optionals sixelSupport       [ libsixel ]
199     ++ lib.optionals speexSupport       [ speex ]
200     ++ lib.optionals theoraSupport      [ libtheora ]
201     ++ lib.optionals vaapiSupport       [ libva ]
202     ++ lib.optionals vapoursynthSupport [ vapoursynth ]
203     ++ lib.optionals vdpauSupport       [ libvdpau ]
204     ++ lib.optionals vulkanSupport      [ shaderc vulkan-headers vulkan-loader ]
205     ++ lib.optionals waylandSupport     [ wayland wayland-protocols libxkbcommon ]
206     ++ lib.optionals x11Support         [ libX11 libXext libGLU libGL libXxf86vm libXrandr libXpresent ]
207     ++ lib.optionals xineramaSupport    [ libXinerama ]
208     ++ lib.optionals xvSupport          [ libXv ]
209     ++ lib.optionals zimgSupport        [ zimg ]
210     ++ lib.optionals stdenv.isLinux     [ nv-codec-headers-11 ]
211     ++ lib.optionals stdenv.isDarwin    [ libiconv ]
212     ++ lib.optionals stdenv.isDarwin    [ Accelerate CoreFoundation Cocoa CoreAudio MediaPlayer VideoToolbox ]
213     ++ lib.optionals (stdenv.isDarwin && swiftSupport) [ AVFoundation CoreMedia ];
215   postBuild = lib.optionalString stdenv.isDarwin ''
216     pushd .. # Must be run from the source dir because it uses relative paths
217     python3 TOOLS/osxbundle.py -s build/mpv
218     popd
219   '';
221   postInstall = ''
222     # Use a standard font
223     mkdir -p $out/share/mpv
224     ln -s ${freefont_ttf}/share/fonts/truetype/FreeSans.ttf $out/share/mpv/subfont.ttf
226     pushd ../TOOLS
227     cp mpv_identify.sh umpv $out/bin/
228     popd
229     pushd $out/share/applications
231     # patch out smb protocol reference, since our ffmpeg can't handle it
232     substituteInPlace mpv.desktop --replace-fail "smb," ""
234     sed -e '/Icon=/ ! s|mpv|umpv|g; s|^Exec=.*|Exec=umpv %U|' \
235       mpv.desktop > umpv.desktop
236     printf "NoDisplay=true\n" >> umpv.desktop
237     popd
238   '' + lib.optionalString stdenv.isDarwin ''
239     mkdir -p $out/Applications
240     cp -r mpv.app $out/Applications
241   '';
243   # Set RUNPATH so that libcuda in /run/opengl-driver(-32)/lib can be found.
244   # See the explanation in addOpenGLRunpath.
245   postFixup = lib.optionalString stdenv.isLinux ''
246     addOpenGLRunpath $out/bin/mpv
247     patchShebangs --update --host $out/bin/umpv $out/bin/mpv_identify.sh
248   '';
250   passthru = {
251     inherit
252     # The wrapper consults luaEnv and lua.version
253     luaEnv
254     lua
255     # In the wrapper, we want to reference vapoursynth which has the `python3`
256     # passthru attribute (which has the `sitePrefix` attribute). This way we'll
257     # be sure that in the wrapper we'll use the same python3.sitePrefix used to
258     # build vapoursynth.
259     vapoursynthSupport
260     vapoursynth
261     ;
262   };
264   meta = {
265     homepage = "https://mpv.io";
266     description = "General-purpose media player, fork of MPlayer and mplayer2";
267     longDescription = ''
268       mpv is a free and open-source general-purpose video player, based on the
269       MPlayer and mplayer2 projects, with great improvements above both.
270     '';
271     changelog = "https://github.com/mpv-player/mpv/releases/tag/v${finalAttrs.version}";
272     license = lib.licenses.gpl2Plus;
273     mainProgram = "mpv";
274     maintainers = with lib.maintainers; [
275       AndersonTorres fpletz globin ma27 tadeokondrak
276     ];
277     platforms = lib.platforms.unix;
278   };