lol
1{ config
2, lib
3, stdenv
4, fetchFromGitHub
5, fetchpatch
6, addOpenGLRunpath
7, docutils
8, perl
9, pkg-config
10, python3
11, wafHook
12, which
13, ffmpeg
14, freefont_ttf
15, freetype
16, libass
17, libpthreadstubs
18, mujs
19, nv-codec-headers
20, lua
21, libuchardet
22, libiconv
23, CoreFoundation, Cocoa, CoreAudio, MediaPlayer
24
25, waylandSupport ? stdenv.isLinux
26 , wayland
27 , wayland-protocols
28 , libxkbcommon
29
30, x11Support ? stdenv.isLinux
31 , libGLU, libGL
32 , libX11
33 , libXext
34 , libXxf86vm
35 , libXrandr
36
37, cddaSupport ? false
38 , libcdio
39 , libcdio-paranoia
40
41, vulkanSupport ? stdenv.isLinux
42 , libplacebo
43 , shaderc
44 , vulkan-headers
45 , vulkan-loader
46
47, drmSupport ? stdenv.isLinux
48 , libdrm
49 , mesa
50
51, alsaSupport ? stdenv.isLinux, alsa-lib
52, archiveSupport ? true, libarchive
53, bluraySupport ? true, libbluray
54, bs2bSupport ? true, libbs2b
55, cacaSupport ? true, libcaca
56, cmsSupport ? true, lcms2
57, dvdnavSupport ? stdenv.isLinux, libdvdnav
58, jackaudioSupport ? false, libjack2
59, libpngSupport ? true, libpng
60, openalSupport ? true, openalSoft
61, pulseSupport ? config.pulseaudio or stdenv.isLinux, libpulseaudio
62, rubberbandSupport ? stdenv.isLinux, rubberband
63, screenSaverSupport ? true, libXScrnSaver
64, sdl2Support ? true, SDL2
65, sixelSupport ? false, libsixel
66, speexSupport ? true, speex
67, swiftSupport ? false, swift
68, theoraSupport ? true, libtheora
69, vaapiSupport ? stdenv.isLinux, libva
70, vapoursynthSupport ? false, vapoursynth
71, vdpauSupport ? true, libvdpau
72, xineramaSupport ? stdenv.isLinux, libXinerama
73, xvSupport ? stdenv.isLinux, libXv
74, zimgSupport ? true, zimg
75}:
76
77with lib;
78
79let
80 luaEnv = lua.withPackages (ps: with ps; [ luasocket ]);
81
82in stdenv.mkDerivation rec {
83 pname = "mpv";
84 version = "0.34.0";
85
86 outputs = [ "out" "dev" "man" ];
87
88 src = fetchFromGitHub {
89 owner = "mpv-player";
90 repo = "mpv";
91 rev = "v${version}";
92 sha256 = "sha256-qa6xZV4aLcHBMa2bIqoKjte4+KWEGGZre4L0u1+eDE8=";
93 };
94
95 postPatch = ''
96 patchShebangs ./TOOLS/
97 '';
98
99 NIX_LDFLAGS = lib.optionalString x11Support "-lX11 -lXext "
100 + lib.optionalString stdenv.isDarwin "-framework CoreFoundation";
101
102 wafConfigureFlags = [
103 "--enable-libmpv-shared"
104 "--enable-manpage-build"
105 "--disable-libmpv-static"
106 "--disable-static-build"
107 "--disable-build-date" # Purity
108 (lib.enableFeature archiveSupport "libarchive")
109 (lib.enableFeature cddaSupport "cdda")
110 (lib.enableFeature dvdnavSupport "dvdnav")
111 (lib.enableFeature openalSupport "openal")
112 (lib.enableFeature sdl2Support "sdl2")
113 (lib.enableFeature sixelSupport "sixel")
114 (lib.enableFeature vaapiSupport "vaapi")
115 (lib.enableFeature waylandSupport "wayland")
116 (lib.enableFeature stdenv.isLinux "dvbin")
117 ] # Disable whilst Swift isn't supported
118 ++ lib.optional (!swiftSupport) "--disable-macos-cocoa-cb";
119
120 nativeBuildInputs = [
121 addOpenGLRunpath
122 docutils
123 perl
124 pkg-config
125 python3
126 wafHook
127 which
128 ] ++ lib.optionals swiftSupport [ swift ];
129
130 buildInputs = [
131 ffmpeg
132 freetype
133 libass
134 libpthreadstubs
135 libuchardet
136 luaEnv
137 mujs
138 ] ++ lib.optionals alsaSupport [ alsa-lib ]
139 ++ lib.optionals archiveSupport [ libarchive ]
140 ++ lib.optionals bluraySupport [ libbluray ]
141 ++ lib.optionals bs2bSupport [ libbs2b ]
142 ++ lib.optionals cacaSupport [ libcaca ]
143 ++ lib.optionals cddaSupport [ libcdio libcdio-paranoia ]
144 ++ lib.optionals cmsSupport [ lcms2 ]
145 ++ lib.optionals drmSupport [ libdrm mesa ]
146 ++ lib.optionals dvdnavSupport [ libdvdnav libdvdnav.libdvdread ]
147 ++ lib.optionals jackaudioSupport [ libjack2 ]
148 ++ lib.optionals libpngSupport [ libpng ]
149 ++ lib.optionals openalSupport [ openalSoft ]
150 ++ lib.optionals pulseSupport [ libpulseaudio ]
151 ++ lib.optionals rubberbandSupport [ rubberband ]
152 ++ lib.optionals screenSaverSupport [ libXScrnSaver ]
153 ++ lib.optionals sdl2Support [ SDL2 ]
154 ++ lib.optionals sixelSupport [ libsixel ]
155 ++ lib.optionals speexSupport [ speex ]
156 ++ lib.optionals theoraSupport [ libtheora ]
157 ++ lib.optionals vaapiSupport [ libva ]
158 ++ lib.optionals vapoursynthSupport [ vapoursynth ]
159 ++ lib.optionals vdpauSupport [ libvdpau ]
160 ++ lib.optionals vulkanSupport [ libplacebo shaderc vulkan-headers vulkan-loader ]
161 ++ lib.optionals waylandSupport [ wayland wayland-protocols libxkbcommon ]
162 ++ lib.optionals x11Support [ libX11 libXext libGLU libGL libXxf86vm libXrandr ]
163 ++ lib.optionals xineramaSupport [ libXinerama ]
164 ++ lib.optionals xvSupport [ libXv ]
165 ++ lib.optionals zimgSupport [ zimg ]
166 ++ lib.optionals stdenv.isLinux [ nv-codec-headers ]
167 ++ lib.optionals stdenv.isDarwin [ libiconv ]
168 ++ lib.optionals stdenv.isDarwin [ CoreFoundation Cocoa CoreAudio MediaPlayer ];
169
170 enableParallelBuilding = true;
171
172 postBuild = lib.optionalString stdenv.isDarwin ''
173 python3 TOOLS/osxbundle.py -s build/mpv
174 '';
175
176 postInstall = ''
177 # Use a standard font
178 mkdir -p $out/share/mpv
179 ln -s ${freefont_ttf}/share/fonts/truetype/FreeSans.ttf $out/share/mpv/subfont.ttf
180
181 cp TOOLS/mpv_identify.sh $out/bin
182 cp TOOLS/umpv $out/bin
183 cp $out/share/applications/mpv.desktop $out/share/applications/umpv.desktop
184 sed -i '/Icon=/ ! s/mpv/umpv/g' $out/share/applications/umpv.desktop
185
186 substituteInPlace $out/lib/pkgconfig/mpv.pc \
187 --replace "$out/include" "$dev/include"
188 '' + lib.optionalString stdenv.isDarwin ''
189 mkdir -p $out/Applications
190 cp -r build/mpv.app $out/Applications
191 '';
192
193 # Set RUNPATH so that libcuda in /run/opengl-driver(-32)/lib can be found.
194 # See the explanation in addOpenGLRunpath.
195 postFixup = lib.optionalString stdenv.isLinux ''
196 addOpenGLRunpath $out/bin/mpv
197 '';
198
199 passthru = {
200 inherit
201 # The wrapper consults luaEnv and lua.version
202 luaEnv
203 lua
204 # In the wrapper, we want to reference vapoursynth which has the `python3`
205 # passthru attribute (which has the `sitePrefix` attribute). This way we'll
206 # be sure that in the wrapper we'll use the same python3.sitePrefix used to
207 # build vapoursynth.
208 vapoursynthSupport
209 vapoursynth
210 ;
211 };
212
213 meta = with lib; {
214 homepage = "https://mpv.io";
215 description = "General-purpose media player, fork of MPlayer and mplayer2";
216 longDescription = ''
217 mpv is a free and open-source general-purpose video player, based on the
218 MPlayer and mplayer2 projects, with great improvements above both.
219 '';
220 license = licenses.gpl2Plus;
221 maintainers = with maintainers; [ AndersonTorres fpletz globin ma27 tadeokondrak ];
222 platforms = platforms.darwin ++ platforms.linux;
223 };
224}