1{
2 qtModule,
3 qtdeclarative,
4 qtwebchannel,
5 qtpositioning,
6 qtwebsockets,
7 buildPackages,
8 bison,
9 coreutils,
10 fetchpatch2,
11 flex,
12 git,
13 gperf,
14 ninja,
15 pkg-config,
16 python3,
17 which,
18 nodejs,
19 xorg,
20 libXcursor,
21 libXScrnSaver,
22 libXrandr,
23 libXtst,
24 libxshmfence,
25 libXi,
26 cups,
27 fontconfig,
28 freetype,
29 harfbuzz,
30 icu,
31 dbus,
32 libdrm,
33 zlib,
34 minizip,
35 libjpeg,
36 libpng,
37 libtiff,
38 libwebp,
39 libopus,
40 jsoncpp,
41 protobuf,
42 libvpx,
43 srtp,
44 snappy,
45 nss,
46 libevent,
47 openssl,
48 alsa-lib,
49 pulseaudio,
50 libcap,
51 pciutils,
52 systemd,
53 pipewire,
54 gn,
55 ffmpeg,
56 lib,
57 stdenv,
58 glib,
59 libxml2,
60 libxslt,
61 lcms2,
62 libkrb5,
63 libgbm,
64 enableProprietaryCodecs ? true,
65 # darwin
66 bootstrap_cmds,
67 cctools,
68 xcbuild,
69}:
70
71qtModule {
72 pname = "qtwebengine";
73 nativeBuildInputs = [
74 bison
75 coreutils
76 flex
77 git
78 gperf
79 ninja
80 pkg-config
81 (python3.withPackages (ps: with ps; [ html5lib ]))
82 which
83 gn
84 nodejs
85 ]
86 ++ lib.optionals stdenv.hostPlatform.isDarwin [
87 bootstrap_cmds
88 cctools
89 xcbuild
90 ];
91 doCheck = true;
92 outputs = [
93 "out"
94 "dev"
95 ];
96
97 dontUseGnConfigure = true;
98
99 # ninja builds some components with -Wno-format,
100 # which cannot be set at the same time as -Wformat-security
101 hardeningDisable = [ "format" ];
102
103 patches = [
104 # Don't assume /usr/share/X11, and also respect the XKB_CONFIG_ROOT
105 # environment variable, since NixOS relies on it working.
106 # See https://github.com/NixOS/nixpkgs/issues/226484 for more context.
107 ./xkb-includes.patch
108
109 ./link-pulseaudio.patch
110
111 # Override locales install path so they go to QtWebEngine's $out
112 ./locales-path.patch
113
114 # Reproducibility QTBUG-136068
115 ./gn-object-sorted.patch
116
117 # https://chromium-review.googlesource.com/c/chromium/src/+/6445471
118 (fetchpatch2 {
119 url = "https://github.com/chromium/chromium/commit/f8f21fb4aa01f75acbb12abf5ea8c263c6817141.patch?full_index=1";
120 stripLen = 1;
121 extraPrefix = "src/3rdparty/chromium/";
122 hash = "sha256-wcby9uD8xb4re9+s+rdl1hcpxDcHxuI68vUNAC7Baas=";
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}