1{
2 qtModule,
3 qtdeclarative,
4 qtquickcontrols,
5 qtlocation,
6 qtwebchannel,
7 fetchpatch,
8 fetchpatch2,
9
10 bison,
11 flex,
12 git,
13 gperf,
14 ninja,
15 pkg-config,
16 python,
17 which,
18 nodejs,
19 perl,
20 buildPackages,
21 pkgsBuildTarget,
22 pkgsBuildBuild,
23
24 xorg,
25 libXcursor,
26 libXScrnSaver,
27 libXrandr,
28 libXtst,
29 fontconfig,
30 freetype,
31 harfbuzz,
32 icu,
33 dbus,
34 libdrm,
35 zlib,
36 minizip,
37 libjpeg,
38 libpng,
39 libtiff,
40 libwebp,
41 libopus,
42 jsoncpp,
43 protobuf,
44 libvpx,
45 srtp,
46 snappy,
47 nss,
48 libevent,
49 alsa-lib,
50 pulseaudio,
51 libcap,
52 pciutils,
53 systemd,
54 enableProprietaryCodecs ? true,
55 gn,
56 cctools,
57 cups,
58 bootstrap_cmds,
59 xcbuild,
60 writeScriptBin,
61 ffmpeg ? null,
62 lib,
63 stdenv,
64 version ? null,
65 qtCompatVersion,
66 pipewireSupport ? stdenv.hostPlatform.isLinux,
67 pipewire,
68 postPatch ? "",
69 nspr,
70 lndir,
71}:
72
73let
74 # qtwebengine expects to find an executable in $PATH which runs on
75 # the build platform yet knows about the host `.pc` files. Most
76 # configury allows setting $PKG_CONFIG to point to an
77 # arbitrarily-named script which serves this purpose; however QT
78 # insists that it is named `pkg-config` with no target prefix. So
79 # we re-wrap the host platform's pkg-config.
80 pkg-config-wrapped-without-prefix = stdenv.mkDerivation {
81 name = "pkg-config-wrapper-without-target-prefix";
82 dontUnpack = true;
83 dontBuild = true;
84 installPhase = ''
85 mkdir -p $out/bin
86 ln -s '${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config' $out/bin/pkg-config
87 '';
88 };
89
90in
91
92qtModule (
93 {
94 pname = "qtwebengine";
95 nativeBuildInputs = [
96 bison
97 flex
98 git
99 gperf
100 ninja
101 pkg-config
102 (python.withPackages (ps: [ ps.html5lib ]))
103 which
104 gn
105 nodejs
106 ]
107 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
108 perl
109 lndir
110 (lib.getDev pkgsBuildTarget.targetPackages.qt5.qtbase)
111 pkgsBuildBuild.pkg-config
112 (lib.getDev pkgsBuildTarget.targetPackages.qt5.qtquickcontrols)
113 pkg-config-wrapped-without-prefix
114 ]
115 ++ lib.optional stdenv.hostPlatform.isDarwin [
116 bootstrap_cmds
117 xcbuild
118 ];
119 doCheck = true;
120 outputs = [
121 "bin"
122 "dev"
123 "out"
124 ];
125
126 enableParallelBuilding = true;
127
128 # Don’t use the gn setup hook
129 dontUseGnConfigure = true;
130
131 # ninja builds some components with -Wno-format,
132 # which cannot be set at the same time as -Wformat-security
133 hardeningDisable = [ "format" ];
134
135 patches = [
136 # Support FFmpeg 5
137 (fetchpatch2 {
138 url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/14074e4d789167bd776939037fe6df8d4d7dc0b3/qt5-webengine-ffmpeg5.patch";
139 hash = "sha256-jTbJFXBPwRMzr8IeTxrv9dtS+/xDS/zR4dysV/bRg3I=";
140 stripLen = 1;
141 extraPrefix = "src/3rdparty/";
142 })
143
144 # Support FFmpeg 7
145 (fetchpatch2 {
146 url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/e8fb4f86104243b90966b69cdfaa967273d834b6/qt5-webengine-ffmpeg7.patch";
147 hash = "sha256-YNeHmOVp0M5HB+b91AOxxJxl+ktBtLYVdHlq13F7xtY=";
148 stripLen = 1;
149 extraPrefix = "src/3rdparty/chromium/";
150 })
151
152 # Support PipeWire ≥ 0.3
153 (fetchpatch2 {
154 url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/c9db2cd9e144bd7a5e9246f5f7a01fe52fd089ba/qt5-webengine-pipewire-0.3.patch";
155 hash = "sha256-mGexRfVDF3yjNzSi9BjavhzPtsXI0BooSr/rZ1z/BDo=";
156 stripLen = 1;
157 extraPrefix = "src/3rdparty/";
158 })
159
160 # Fix race condition exposed by missing dependency
161 # https://bugs.gentoo.org/933368
162 ./qtwebengine-fix_build_pdf_extension_util.patch
163
164 # The latest version of Clang changed what macros it predefines on Apple
165 # targets, causing errors about predefined macros in zlib.
166 (fetchpatch2 {
167 url = "https://github.com/chromium/chromium/commit/2f39ac8d0a414dd65c0e1d5aae38c8f97aa06ae9.patch";
168 hash = "sha256-3kA2os0IntxIiJwzS5nPd7QWYlOWOpoLKYsOQFYv0Sk=";
169 stripLen = 1;
170 extraPrefix = "src/3rdparty/chromium/";
171 })
172
173 # The latest version of Clang changed what macros it predefines on Apple
174 # targets, causing errors about predefined macros in libpng.
175 (fetchpatch2 {
176 url = "https://github.com/chromium/chromium/commit/66defc14abe47c0494da9faebebfa0a5b6efcf38.patch";
177 hash = "sha256-ErS5Eycls5+xQLGYKz1r/tQC6IcRJWb/WoGsUyzO9WY=";
178 stripLen = 1;
179 extraPrefix = "src/3rdparty/chromium/";
180 })
181
182 # https://trac.macports.org/ticket/71563
183 # src/3rdparty/chromium/third_party/freetype/src/src/gzip/ftzconf.h:228:12: error: unknown type name 'Byte'
184 (fetchpatch2 {
185 url = "https://github.com/macports/macports-ports/raw/f9a4136c48020b01ecc6dffa99b88333c360f056/aqua/qt5/files/patch-qtwebengine-chromium-freetype-gzip.diff";
186 hash = "sha256-NeLmMfYMo80u3h+5GTenMANWfWLPeS35cKg+h3vzW4g=";
187 extraPrefix = "";
188 })
189
190 # src/3rdparty/chromium/base/process/process_metrics_mac.cc:303:17: error: static assertion expression is not an integral constant expression
191 (fetchpatch2 {
192 url = "https://github.com/macports/macports-ports/raw/f9a4136c48020b01ecc6dffa99b88333c360f056/aqua/qt5/files/patch-qtwebengine_chromium_static_page_size.diff";
193 hash = "sha256-8TFN5XU0SUvPJCFU6wvcKP5a8HCd0ygUnLT8BF4MZ/E=";
194 extraPrefix = "";
195 })
196
197 # Add "-target-feature +aes" to the arm crc32c build flags
198 (fetchpatch2 {
199 url = "https://github.com/chromium/chromium/commit/9f43d823b6b4cdea62f0cc7563ff01f9239b8970.patch";
200 hash = "sha256-2WCx+ZOWA8ZyV2yiSQLx9uFZOoeWQHxLqwLEZsV41QU=";
201 stripLen = 1;
202 extraPrefix = "src/3rdparty/chromium/";
203 })
204
205 # Fix build with clang and libc++ 19
206 # https://github.com/freebsd/freebsd-ports/commit/0ddd6468fb3cb9ba390973520517cb1ca2cd690d
207 (fetchpatch2 {
208 url = "https://github.com/freebsd/freebsd-ports/raw/0ddd6468fb3cb9ba390973520517cb1ca2cd690d/www/qt5-webengine/files/patch-libc++19";
209 hash = "sha256-pSVPnuEpjFHW60dbId5sZ3zHP709EWG4LSWoS+TkgcQ=";
210 extraPrefix = "";
211 })
212 (fetchpatch2 {
213 url = "https://github.com/freebsd/freebsd-ports/raw/0ddd6468fb3cb9ba390973520517cb1ca2cd690d/www/qt5-webengine/files/patch-src_3rdparty_chromium_third__party_blink_renderer_platform_wtf_hash__table.h";
214 hash = "sha256-+vyWC7Indd1oBhvL5fMTlIH4mM4INgISZFAbHsq32Lg=";
215 extraPrefix = "";
216 })
217 (fetchpatch2 {
218 url = "https://github.com/freebsd/freebsd-ports/raw/0ddd6468fb3cb9ba390973520517cb1ca2cd690d/www/qt5-webengine/files/patch-src_3rdparty_chromium_third__party_perfetto_include_perfetto_tracing_internal_track__event__data__source.h";
219 hash = "sha256-DcAYOV9b30ogPCiedvQimEmiZpUJquk5j6WLjJxR54U=";
220 extraPrefix = "";
221 })
222 ];
223
224 postPatch = ''
225 # Patch Chromium build tools
226 (
227 cd src/3rdparty/chromium;
228
229 patch -p1 < ${
230 (fetchpatch {
231 # support for building with python 3.12
232 name = "python312-six.patch";
233 url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/6b0c0e76e0934db2f84be40cb5978cee47266e78/python3.12-six.patch";
234 hash = "sha256-YgP9Sq5+zTC+U7+0hQjZokwb+fytk0UEIJztUXFhTkI=";
235 })
236 }
237
238 # Manually fix unsupported shebangs
239 substituteInPlace third_party/harfbuzz-ng/src/src/update-unicode-tables.make \
240 --replace "/usr/bin/env -S make -f" "/usr/bin/make -f" || true
241
242 # TODO: be more precise
243 patchShebangs .
244 )
245 ''
246 # Prevent Chromium build script from making the path to `clang` relative to
247 # the build directory. `clang_base_path` is the value of `QMAKE_CLANG_DIR`
248 # from `src/core/config/mac_osx.pri`.
249 + lib.optionalString stdenv.hostPlatform.isDarwin ''
250 substituteInPlace ./src/3rdparty/chromium/build/toolchain/mac/BUILD.gn \
251 --replace 'prefix = rebase_path("$clang_base_path/bin/", root_build_dir)' 'prefix = "$clang_base_path/bin/"'
252 ''
253 # Patch library paths in Qt sources
254 + ''
255 sed -i \
256 -e "s,QLibraryInfo::location(QLibraryInfo::DataPath),QLatin1String(\"$out\"),g" \
257 -e "s,QLibraryInfo::location(QLibraryInfo::TranslationsPath),QLatin1String(\"$out/translations\"),g" \
258 -e "s,QLibraryInfo::location(QLibraryInfo::LibraryExecutablesPath),QLatin1String(\"$out/libexec\"),g" \
259 src/core/web_engine_library_info.cpp
260 ''
261 # Patch library paths in Chromium sources
262 + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
263 sed -i -e '/lib_loader.*Load/s!"\(libudev\.so\)!"${lib.getLib systemd}/lib/\1!' \
264 src/3rdparty/chromium/device/udev_linux/udev?_loader.cc
265
266 sed -i -e '/libpci_loader.*Load/s!"\(libpci\.so\)!"${pciutils}/lib/\1!' \
267 src/3rdparty/chromium/gpu/config/gpu_info_collector_linux.cc
268 ''
269 + lib.optionalString stdenv.hostPlatform.isDarwin (''
270 substituteInPlace src/buildtools/config/mac_osx.pri \
271 --replace 'QMAKE_CLANG_DIR = "/usr"' 'QMAKE_CLANG_DIR = "${stdenv.cc}"'
272
273 # Use system ffmpeg
274 echo "gn_args += use_system_ffmpeg=true" >> src/core/config/mac_osx.pri
275 echo "LIBS += -lavformat -lavcodec -lavutil" >> src/core/core_common.pri
276 '')
277 + postPatch;
278
279 env = {
280 NIX_CFLAGS_COMPILE = toString (
281 lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
282 "-w "
283 ]
284 ++ lib.optionals stdenv.cc.isGNU [
285 # with gcc8, -Wclass-memaccess became part of -Wall and this exceeds the logging limit
286 "-Wno-class-memaccess"
287 ]
288 ++ lib.optionals (stdenv.hostPlatform.gcc.arch or "" == "sandybridge") [
289 # it fails when compiled with -march=sandybridge https://github.com/NixOS/nixpkgs/pull/59148#discussion_r276696940
290 # TODO: investigate and fix properly
291 "-march=westmere"
292 ]
293 ++ lib.optionals stdenv.cc.isClang [
294 "-Wno-elaborated-enum-base"
295 # 5.15.17: need to silence these two warnings
296 # https://trac.macports.org/ticket/70850
297 "-Wno-enum-constexpr-conversion"
298 "-Wno-unused-but-set-variable"
299 # Clang 19
300 "-Wno-error=missing-template-arg-list-after-template-kw"
301 ]
302 );
303 }
304 // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
305 NIX_CFLAGS_LINK = "-Wl,--no-warn-search-mismatch";
306 "NIX_CFLAGS_LINK_${buildPackages.stdenv.cc.suffixSalt}" = "-Wl,--no-warn-search-mismatch";
307 };
308
309 preConfigure = ''
310 export NINJAFLAGS=-j$NIX_BUILD_CORES
311
312 if [ -d "$PWD/tools/qmake" ]; then
313 QMAKEPATH="$PWD/tools/qmake''${QMAKEPATH:+:}$QMAKEPATH"
314 fi
315 ''
316 + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
317 export QMAKE_CC=$CC
318 export QMAKE_CXX=$CXX
319 export QMAKE_LINK=$CXX
320 export QMAKE_AR=$AR
321 '';
322
323 qmakeFlags = [
324 "--"
325 "-system-ffmpeg"
326 ]
327 ++ lib.optional (
328 pipewireSupport && stdenv.buildPlatform == stdenv.hostPlatform
329 ) "-webengine-webrtc-pipewire"
330 ++ lib.optional enableProprietaryCodecs "-proprietary-codecs";
331
332 propagatedBuildInputs = [
333 qtdeclarative
334 qtquickcontrols
335 qtlocation
336 qtwebchannel
337
338 # Image formats
339 libjpeg
340 libpng
341 libtiff
342 libwebp
343
344 # Video formats
345 srtp
346 libvpx
347
348 # Audio formats
349 libopus
350
351 # Text rendering
352 harfbuzz
353 icu
354
355 libevent
356 ffmpeg
357 ]
358 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
359 dbus
360 zlib
361 minizip
362 snappy
363 nss
364 protobuf
365 jsoncpp
366
367 # Audio formats
368 alsa-lib
369 pulseaudio
370
371 # Text rendering
372 fontconfig
373 freetype
374
375 libcap
376 pciutils
377
378 # X11 libs
379 xorg.xrandr
380 libXScrnSaver
381 libXcursor
382 libXrandr
383 xorg.libpciaccess
384 libXtst
385 xorg.libXcomposite
386 xorg.libXdamage
387 libdrm
388 xorg.libxkbfile
389
390 ]
391 ++ lib.optionals pipewireSupport [
392 # Pipewire
393 pipewire
394 ]
395
396 # FIXME These dependencies shouldn't be needed but can't find a way
397 # around it. Chromium pulls this in while bootstrapping GN.
398 ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools.libtool ];
399
400 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
401 cups
402
403 # `sw_vers` is used by `src/3rdparty/chromium/build/config/mac/sdk_info.py`
404 # to get some information about the host platform.
405 (writeScriptBin "sw_vers" ''
406 #!${stdenv.shell}
407
408 while [ $# -gt 0 ]; do
409 case "$1" in
410 -buildVersion) echo "17E199";;
411 *) break ;;
412
413 esac
414 shift
415 done
416 '')
417 ];
418
419 dontUseNinjaBuild = true;
420 dontUseNinjaInstall = true;
421
422 postInstall =
423 lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
424 mkdir -p $out/libexec
425 ''
426 + lib.optionalString stdenv.hostPlatform.isLinux ''
427 cat > $out/libexec/qt.conf <<EOF
428 [Paths]
429 Prefix = ..
430 EOF
431
432 ''
433 + ''
434 # Fix for out-of-sync QtWebEngine and Qt releases (since 5.15.3)
435 sed 's/${lib.head (lib.splitString "-" version)} /${qtCompatVersion} /' -i "$out"/lib/cmake/*/*Config.cmake
436 '';
437
438 requiredSystemFeatures = [ "big-parallel" ];
439
440 meta = with lib; {
441 description = "Web engine based on the Chromium web browser";
442 mainProgram = "qwebengine_convert_dict";
443 maintainers = with maintainers; [ matthewbauer ];
444
445 # qtwebengine-5.15.8: "QtWebEngine can only be built for x86,
446 # x86-64, ARM, Aarch64, and MIPSel architectures."
447 platforms =
448 with lib.systems.inspect.patterns;
449 let
450 inherit (lib.systems.inspect) patternLogicalAnd;
451 in
452 concatMap (patternLogicalAnd isUnix) (
453 lib.concatMap lib.toList [
454 isx86_32
455 isx86_64
456 isAarch32
457 isAarch64
458 (patternLogicalAnd isMips isLittleEndian)
459 ]
460 );
461
462 # This build takes a long time; particularly on slow architectures
463 timeout = 24 * 3600;
464 };
465
466 }
467 // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
468 configurePlatforms = [ ];
469 # to get progress output in `nix-build` and `nix build -L`
470 preBuild = ''
471 export TERM=dumb
472 '';
473 depsBuildBuild = [
474 pkgsBuildBuild.stdenv
475 zlib
476 nss
477 nspr
478 ];
479
480 }
481)