summaryrefslogtreecommitdiff
path: root/pkgs/by-name/vl/vlc/package.nix
blob: 6bfb919b930760f35eefeaff03f1faef3da6e33f (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
{
  lib,
  a52dec,
  alsa-lib,
  autoreconfHook,
  avahi,
  curl,
  dbus,
  faad2,
  fetchpatch,
  fetchurl,
  # Please unpin FFmpeg on the next upstream release.
  ffmpeg_6,
  flac,
  fluidsynth,
  freefont_ttf,
  freetype,
  fribidi,
  genericUpdater,
  gnutls,
  libSM,
  libXext,
  libXinerama,
  libXpm,
  libXv,
  libXvMC,
  libarchive,
  libass,
  libbluray,
  libcaca,
  libcddb,
  libdc1394,
  libdvbpsi,
  libdvdnav,
  libebml,
  libgcrypt,
  libgpg-error,
  libjack2,
  libkate,
  libmad,
  libmatroska,
  libmicrodns,
  libmodplug,
  libmtp,
  liboggz,
  libopus,
  libplacebo_5,
  libpulseaudio,
  libraw1394,
  librsvg,
  libsForQt5,
  libsamplerate,
  libspatialaudio,
  libssh2,
  libtheora,
  libtiger,
  libupnp,
  libv4l,
  libva,
  libvdpau,
  libvorbis,
  libxml2,
  live555,
  lua5,
  mpeg2dec,
  ncurses,
  perl,
  pkg-config,
  pkgsBuildBuild,
  protobuf,
  removeReferencesTo,
  samba,
  schroedinger,
  speex,
  srt,
  stdenv,
  systemd,
  taglib_1,
  unzip,
  wayland,
  wayland-protocols,
  wayland-scanner,
  wrapGAppsHook3,
  writeShellScript,
  xcbutilkeysyms,
  zlib,

  chromecastSupport ? true,
  jackSupport ? false,
  onlyLibVLC ? false,
  skins2Support ? !onlyLibVLC,
  waylandSupport ? true,
  withQt5 ? true,
}:

# chromecastSupport requires TCP port 8010 to be open for it to work.
# If your firewall is enabled, make sure to have something like:
#   networking.firewall.allowedTCPPorts = [ 8010 ];

let
  inherit (lib) optionalString optionals;
in
stdenv.mkDerivation (finalAttrs: {
  pname = "${optionalString onlyLibVLC "lib"}vlc";
  version = "3.0.21";

  src = fetchurl {
    url = "https://get.videolan.org/vlc/${finalAttrs.version}/vlc-${finalAttrs.version}.tar.xz";
    hash = "sha256-JNu+HX367qCZTV3vC73iABdzRxNtv+Vz9bakzuJa+7A=";
  };

  nativeBuildInputs =
    [
      autoreconfHook
      lua5
      perl
      pkg-config
      removeReferencesTo
      unzip
      wrapGAppsHook3
    ]
    ++ optionals chromecastSupport [ protobuf ]
    ++ optionals withQt5 [ libsForQt5.wrapQtAppsHook ]
    ++ optionals waylandSupport [
      wayland-scanner
    ];

  # VLC uses a *ton* of libraries for various pieces of functionality, many of
  # which are not included here for no other reason that nobody has mentioned
  # needing them
  buildInputs =
    [
      a52dec
      alsa-lib
      avahi
      dbus
      faad2
      ffmpeg_6
      flac
      fluidsynth
      fribidi
      gnutls
      libSM
      libXpm
      libXv
      libXvMC
      libarchive
      libass
      libbluray
      libcaca
      libcddb
      libdc1394
      libdvbpsi
      libdvdnav
      libdvdnav.libdvdread
      libebml
      libgcrypt
      libgpg-error
      libkate
      libmad
      libmatroska
      libmodplug
      libmtp
      liboggz
      libopus
      libplacebo_5
      libpulseaudio
      libraw1394
      librsvg
      libsamplerate
      libspatialaudio
      libssh2
      libtheora
      libtiger
      libupnp
      libv4l
      libva
      libvdpau
      libvorbis
      libxml2
      lua5
      mpeg2dec
      ncurses
      samba
      schroedinger
      speex
      srt
      systemd
      taglib_1
      xcbutilkeysyms
      wayland-scanner # only required for configure script
      zlib
    ]
    ++ optionals (!stdenv.hostPlatform.isAarch && !onlyLibVLC) [ live555 ]
    ++ optionals jackSupport [ libjack2 ]
    ++ optionals chromecastSupport [
      libmicrodns
      protobuf
    ]
    ++ optionals skins2Support [
      freetype
      libXext
      libXinerama
      libXpm
    ]
    ++ optionals waylandSupport [
      wayland
      wayland-protocols
    ]
    ++ optionals withQt5 (
      with libsForQt5;
      [
        qtbase
        qtsvg
        qtx11extras
      ]
    )
    ++ optionals (waylandSupport && withQt5) [ libsForQt5.qtwayland ];
  strictDeps = true;

  env =
    {
      # vlc depends on a c11-gcc wrapper script which we don't have so we need to
      # set the path to the compiler
      BUILDCC = "${pkgsBuildBuild.stdenv.cc}/bin/gcc";
      PKG_CONFIG_WAYLAND_SCANNER_WAYLAND_SCANNER = "wayland-scanner";
    }
    // lib.optionalAttrs stdenv.cc.isGNU {
      NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types";
    }
    // lib.optionalAttrs (!stdenv.hostPlatform.isAarch) {
      LIVE555_PREFIX = live555;
    };

  patches = [
    # patch to build with recent live555
    # upstream issue: https://code.videolan.org/videolan/vlc/-/issues/25473
    (fetchpatch {
      url = "https://code.videolan.org/videolan/vlc/uploads/eb1c313d2d499b8a777314f789794f9d/0001-Add-lssl-and-lcrypto-to-liblive555_plugin_la_LIBADD.patch";
      hash = "sha256-qs3gY1ksCZlf931TSZyMuT2JD0sqrmcRCZwL+wVG0U8=";
    })
    # support VAAPI hardware video decoding with newer ffmpeg
    # upstream merge request: https://code.videolan.org/videolan/vlc/-/merge_requests/6606 (will be included in the next release)
    (fetchpatch {
      url = "https://code.videolan.org/videolan/vlc/-/commit/ba5dc03aecc1d96f81b76838f845ebde7348cf62.diff";
      hash = "sha256-s6AI9O0V3AKOyw9LbQ9CgjaCi5m5+nLacKNLl5ZLC6Q=";
    })
    # make the plugins.dat file generation reproducible
    # upstream merge request: https://code.videolan.org/videolan/vlc/-/merge_requests/7149
    ./deterministic-plugin-cache.diff
  ];

  postPatch =
    ''
      substituteInPlace modules/text_renderer/freetype/platform_fonts.h \
        --replace \
          /usr/share/fonts/truetype/freefont \
          ${freefont_ttf}/share/fonts/truetype
    ''
    # Upstream luac can't cross compile, so we have to install the lua sources
    # instead of bytecode, which was built for buildPlatform:
    # https://www.lua.org/wshop13/Jericke.pdf#page=39
    + lib.optionalString (!stdenv.hostPlatform.canExecute stdenv.buildPlatform) ''
      substituteInPlace share/Makefile.am \
        --replace $'.luac \\\n' $'.lua \\\n'
    '';

  enableParallelBuilding = true;

  dontWrapGApps = true; # to prevent double wrapping of Qtwrap and Gwrap

  # Most of the libraries are auto-detected so we don't need to set a bunch of
  # "--enable-foo" flags here
  configureFlags =
    [
      "--enable-srt" # Explicit enable srt to ensure the patch is applied.
      "--with-kde-solid=$out/share/apps/solid/actions"
    ]
    ++ optionals onlyLibVLC [ "--disable-vlc" ]
    ++ optionals skins2Support [ "--enable-skins2" ]
    ++ optionals waylandSupport [ "--enable-wayland" ]
    ++ optionals chromecastSupport [
      "--enable-sout"
      "--enable-chromecast"
      "--enable-microdns"
    ];

  # Remove runtime dependencies on libraries
  postConfigure = ''
    sed -i 's|^#define CONFIGURE_LINE.*$|#define CONFIGURE_LINE "<removed>"|g' config.h
  '';

  # fails on high core machines
  # ld: cannot find -lvlc_vdpau: No such file or directory
  # https://code.videolan.org/videolan/vlc/-/issues/27338
  enableParallelInstalling = false;

  # Add missing SOFA files
  # Given in EXTRA_DIST, but not in install-data target
  postInstall = ''
    cp -R share/hrtfs $out/share/vlc
  '';

  preFixup = ''
    qtWrapperArgs+=("''${gappsWrapperArgs[@]}")
  '';

  # - Touch plugins (plugins cache keyed off mtime and file size:
  #     https://github.com/NixOS/nixpkgs/pull/35124#issuecomment-370552830
  # - Remove references to the Qt development headers (used in error messages)
  #
  # pkgsBuildBuild is used here because buildPackages.libvlc somehow
  # depends on a qt5.qttranslations that doesn't build, even though it
  # should be the same as pkgsBuildBuild.qt5.qttranslations.
  postFixup =
    ''
      find $out/lib/vlc/plugins -exec touch -d @1 '{}' ';'
      ${
        if stdenv.buildPlatform.canExecute stdenv.hostPlatform then "$out" else pkgsBuildBuild.libvlc
      }/lib/vlc/vlc-cache-gen $out/vlc/plugins
    ''
    + optionalString withQt5 ''
      remove-references-to -t "${libsForQt5.qtbase.dev}" $out/lib/vlc/plugins/gui/libqt_plugin.so
    '';

  passthru.updateScript = genericUpdater {
    versionLister = writeShellScript "vlc-versionLister" ''
      ${curl}/bin/curl -s https://get.videolan.org/vlc/ | sed -En 's/^.*href="([0-9]+(\.[0-9]+)+)\/".*$/\1/p'
    '';
  };

  meta = {
    description = "Cross-platform media player and streaming server";
    homepage = "https://www.videolan.org/vlc/";
    license = lib.licenses.lgpl21Plus;
    maintainers = with lib.maintainers; [ alois31 ];
    platforms = lib.platforms.linux;
    mainProgram = "vlc";
  };
})