1{
2 qtModule,
3 qtdeclarative,
4 qtwebchannel,
5 qtpositioning,
6 qtwebsockets,
7 buildPackages,
8 bison,
9 coreutils,
10 flex,
11 gperf,
12 ninja,
13 pkg-config,
14 python3,
15 which,
16 nodejs,
17 xorg,
18 libXcursor,
19 libXScrnSaver,
20 libXrandr,
21 libXtst,
22 libxshmfence,
23 libXi,
24 cups,
25 fontconfig,
26 freetype,
27 harfbuzz,
28 icu,
29 dbus,
30 libdrm,
31 zlib,
32 minizip,
33 libjpeg,
34 libpng,
35 libtiff,
36 libwebp,
37 libopus,
38 jsoncpp,
39 protobuf,
40 libvpx,
41 srtp,
42 snappy,
43 nss,
44 libevent,
45 openssl,
46 alsa-lib,
47 pulseaudio,
48 libcap,
49 pciutils,
50 systemd,
51 pipewire,
52 gn,
53 ffmpeg,
54 lib,
55 stdenv,
56 glib,
57 libxml2,
58 libxslt,
59 lcms2,
60 libkrb5,
61 libgbm,
62 enableProprietaryCodecs ? true,
63 # darwin
64 bootstrap_cmds,
65 cctools,
66 xcbuild,
67
68 fetchpatch,
69}:
70
71qtModule {
72 pname = "qtwebengine";
73 nativeBuildInputs = [
74 bison
75 coreutils
76 flex
77 gperf
78 ninja
79 pkg-config
80 (python3.withPackages (ps: with ps; [ html5lib ]))
81 which
82 gn
83 nodejs
84 ]
85 ++ lib.optionals stdenv.hostPlatform.isDarwin [
86 bootstrap_cmds
87 cctools
88 xcbuild
89 ];
90 doCheck = true;
91 outputs = [
92 "out"
93 "dev"
94 ];
95
96 dontUseGnConfigure = true;
97
98 # ninja builds some components with -Wno-format,
99 # which cannot be set at the same time as -Wformat-security
100 hardeningDisable = [ "format" ];
101
102 patches = [
103 # Don't assume /usr/share/X11, and also respect the XKB_CONFIG_ROOT
104 # environment variable, since NixOS relies on it working.
105 # See https://github.com/NixOS/nixpkgs/issues/226484 for more context.
106 ./xkb-includes.patch
107
108 ./link-pulseaudio.patch
109
110 # Override locales install path so they go to QtWebEngine's $out
111 ./locales-path.patch
112
113 # Reproducibility QTBUG-136068
114 ./gn-object-sorted.patch
115
116 # Revert "Create EGLImage with eglCreateDRMImageMESA() for exporting dma_buf"
117 # Mesa 25.2 dropped eglCreateDRMImageMESA, so this no longer works.
118 # There are better ways to do this, but this is the easy fix for now.
119 (fetchpatch {
120 url = "https://invent.kde.org/qt/qt/qtwebengine/-/commit/ddcd30454aa6338d898c9d20c8feb48f36632e16.diff";
121 revert = true;
122 hash = "sha256-ht7C3GIEaPtmMGLzQKOtMqE9sLKdqqYCgi/W6b430YU=";
123 })
124 ];
125
126 postPatch = ''
127 # Patch Chromium build tools
128 (
129 cd src/3rdparty/chromium;
130
131 # Manually fix unsupported shebangs
132 substituteInPlace third_party/harfbuzz-ng/src/src/update-unicode-tables.make \
133 --replace "/usr/bin/env -S make -f" "/usr/bin/make -f" || true
134 substituteInPlace third_party/webgpu-cts/src/tools/run_deno \
135 --replace "/usr/bin/env -S deno" "/usr/bin/deno" || true
136 patchShebangs .
137 )
138
139 substituteInPlace cmake/Functions.cmake \
140 --replace "/bin/bash" "${buildPackages.bash}/bin/bash"
141
142 # Patch library paths in sources
143 substituteInPlace src/core/web_engine_library_info.cpp \
144 --replace "QLibraryInfo::path(QLibraryInfo::DataPath)" "\"$out\"" \
145 --replace "QLibraryInfo::path(QLibraryInfo::TranslationsPath)" "\"$out/translations\"" \
146 --replace "QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath)" "\"$out/libexec\""
147
148 substituteInPlace configure.cmake src/gn/CMakeLists.txt \
149 --replace "AppleClang" "Clang"
150
151 # Disable metal shader compilation, Xcode only
152 substituteInPlace src/3rdparty/chromium/third_party/angle/src/libANGLE/renderer/metal/metal_backend.gni \
153 --replace-fail 'angle_has_build && !is_ios && target_os == host_os' "false"
154 ''
155 + lib.optionalString stdenv.hostPlatform.isLinux ''
156 sed -i -e '/lib_loader.*Load/s!"\(libudev\.so\)!"${lib.getLib systemd}/lib/\1!' \
157 src/3rdparty/chromium/device/udev_linux/udev?_loader.cc
158
159 sed -i -e '/libpci_loader.*Load/s!"\(libpci\.so\)!"${pciutils}/lib/\1!' \
160 src/3rdparty/chromium/gpu/config/gpu_info_collector_linux.cc
161 ''
162 + lib.optionalString stdenv.hostPlatform.isDarwin ''
163 substituteInPlace cmake/QtToolchainHelpers.cmake \
164 --replace-fail "/usr/bin/xcrun" "${xcbuild}/bin/xcrun"
165 '';
166
167 cmakeFlags = [
168 "-DQT_FEATURE_qtpdf_build=ON"
169 "-DQT_FEATURE_qtpdf_widgets_build=ON"
170 "-DQT_FEATURE_qtpdf_quick_build=ON"
171 "-DQT_FEATURE_pdf_v8=ON"
172 "-DQT_FEATURE_pdf_xfa=ON"
173 "-DQT_FEATURE_pdf_xfa_bmp=ON"
174 "-DQT_FEATURE_pdf_xfa_gif=ON"
175 "-DQT_FEATURE_pdf_xfa_png=ON"
176 "-DQT_FEATURE_pdf_xfa_tiff=ON"
177 "-DQT_FEATURE_webengine_system_libevent=ON"
178 "-DQT_FEATURE_webengine_system_ffmpeg=ON"
179 # android only. https://bugreports.qt.io/browse/QTBUG-100293
180 # "-DQT_FEATURE_webengine_native_spellchecker=ON"
181 "-DQT_FEATURE_webengine_sanitizer=ON"
182 "-DQT_FEATURE_webengine_kerberos=ON"
183 ]
184 ++ lib.optionals stdenv.hostPlatform.isLinux [
185 "-DQT_FEATURE_webengine_system_libxml=ON"
186 "-DQT_FEATURE_webengine_webrtc_pipewire=ON"
187
188 # Appears not to work on some platforms
189 # https://github.com/Homebrew/homebrew-core/issues/104008
190 "-DQT_FEATURE_webengine_system_icu=ON"
191 ]
192 ++ lib.optionals enableProprietaryCodecs [
193 "-DQT_FEATURE_webengine_proprietary_codecs=ON"
194 ]
195 ++ lib.optionals stdenv.hostPlatform.isDarwin [
196 "-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0" # Per Qt 6’s deployment target (why doesn’t the hook work?)
197 ];
198
199 propagatedBuildInputs = [
200 qtdeclarative
201 qtwebchannel
202 qtwebsockets
203 qtpositioning
204
205 # Image formats
206 libjpeg
207 libpng
208 libtiff
209 libwebp
210
211 # Video formats
212 srtp
213 libvpx
214
215 # Audio formats
216 libopus
217
218 # Text rendering
219 harfbuzz
220
221 openssl
222 glib
223 libxslt
224 lcms2
225
226 libevent
227 ffmpeg
228 ]
229 ++ lib.optionals stdenv.hostPlatform.isLinux [
230 dbus
231 zlib
232 minizip
233 snappy
234 nss
235 protobuf
236 jsoncpp
237
238 icu
239 libxml2
240
241 # Audio formats
242 alsa-lib
243 pulseaudio
244
245 # Text rendering
246 fontconfig
247 freetype
248
249 libcap
250 pciutils
251
252 # X11 libs
253 xorg.xrandr
254 libXScrnSaver
255 libXcursor
256 libXrandr
257 xorg.libpciaccess
258 libXtst
259 xorg.libXcomposite
260 xorg.libXdamage
261 libdrm
262 xorg.libxkbfile
263 libxshmfence
264 libXi
265 xorg.libXext
266
267 # Pipewire
268 pipewire
269
270 libkrb5
271 libgbm
272 ];
273
274 buildInputs = [
275 cups
276 ];
277
278 requiredSystemFeatures = [ "big-parallel" ];
279
280 preConfigure = ''
281 export NINJAFLAGS="-j$NIX_BUILD_CORES"
282 '';
283
284 # Debug info is too big to link with LTO.
285 separateDebugInfo = false;
286
287 meta = with lib; {
288 description = "Web engine based on the Chromium web browser";
289 platforms = [
290 "x86_64-darwin"
291 "aarch64-darwin"
292 "aarch64-linux"
293 "armv7a-linux"
294 "armv7l-linux"
295 "x86_64-linux"
296 ];
297 # This build takes a long time; particularly on slow architectures
298 # 1 hour on 32x3.6GHz -> maybe 12 hours on 4x2.4GHz
299 timeout = 24 * 3600;
300 };
301}