1{
2 lib,
3 clangStdenv,
4 buildPackages,
5 runCommand,
6 fetchurl,
7 perl,
8 python3,
9 ruby,
10 gi-docgen,
11 bison,
12 gperf,
13 cmake,
14 ninja,
15 pkg-config,
16 gettext,
17 gobject-introspection,
18 gnutls,
19 libgcrypt,
20 libgpg-error,
21 gtk3,
22 wayland,
23 wayland-protocols,
24 wayland-scanner,
25 libwebp,
26 enchant2,
27 xorg,
28 libxkbcommon,
29 libavif,
30 libepoxy,
31 libjxl,
32 at-spi2-core,
33 cairo,
34 libxml2,
35 libsoup,
36 libsecret,
37 libxslt,
38 harfbuzz,
39 hyphen,
40 icu,
41 libsysprof-capture,
42 libpthreadstubs,
43 nettle,
44 libtasn1,
45 p11-kit,
46 libidn,
47 libedit,
48 readline,
49 libGL,
50 libGLU,
51 libgbm,
52 libintl,
53 lcms2,
54 libmanette,
55 geoclue2,
56 flite,
57 fontconfig,
58 freetype,
59 openssl,
60 openxr-loader,
61 sqlite,
62 gst-plugins-base,
63 gst-plugins-bad,
64 woff2,
65 bubblewrap,
66 libseccomp,
67 libbacktrace,
68 systemd,
69 xdg-dbus-proxy,
70 replaceVars,
71 glib,
72 unifdef,
73 addDriverRunpath,
74 enableGeoLocation ? true,
75 enableExperimental ? false,
76 withLibsecret ? true,
77 systemdSupport ? lib.meta.availableOn clangStdenv.hostPlatform systemd,
78 testers,
79}:
80
81# https://webkitgtk.org/2024/10/04/webkitgtk-2.46.html recommends building with clang.
82clangStdenv.mkDerivation (finalAttrs: {
83 pname = "webkitgtk";
84 version = "2.50.0";
85 name = "${finalAttrs.pname}-${finalAttrs.version}+abi=${
86 if lib.versionAtLeast gtk3.version "4.0" then
87 "6.0"
88 else
89 "4.${if lib.versions.major libsoup.version == "2" then "0" else "1"}"
90 }";
91
92 outputs = [
93 "out"
94 "dev"
95 "devdoc"
96 ];
97
98 # https://github.com/NixOS/nixpkgs/issues/153528
99 # Can't be linked within a 4GB address space.
100 separateDebugInfo = clangStdenv.hostPlatform.isLinux && !clangStdenv.hostPlatform.is32bit;
101
102 src = fetchurl {
103 url = "https://webkitgtk.org/releases/webkitgtk-${finalAttrs.version}.tar.xz";
104 hash = "sha256-5WS4CZ+aOuMkCVObKQu9KtCE6ZttItSqxeUeRVTfi8I=";
105 };
106
107 patches = lib.optionals clangStdenv.hostPlatform.isLinux [
108 (replaceVars ./fix-bubblewrap-paths.patch {
109 inherit (builtins) storeDir;
110 inherit (addDriverRunpath) driverLink;
111 })
112 ];
113
114 nativeBuildInputs = [
115 bison
116 cmake
117 gettext
118 gobject-introspection
119 gperf
120 ninja
121 perl
122 perl.pkgs.FileCopyRecursive # used by copy-user-interface-resources.pl
123 pkg-config
124 python3
125 ruby
126 gi-docgen
127 glib # for gdbus-codegen
128 unifdef
129 ]
130 ++ lib.optionals clangStdenv.hostPlatform.isLinux [
131 wayland-scanner
132 ];
133
134 buildInputs = [
135 at-spi2-core
136 cairo # required even when using skia
137 enchant2
138 flite
139 libavif
140 libepoxy
141 libjxl
142 gnutls
143 gst-plugins-bad
144 gst-plugins-base
145 harfbuzz
146 hyphen
147 icu
148 libGL
149 libGLU
150 libgbm
151 libgcrypt
152 libgpg-error
153 libidn
154 libintl
155 lcms2
156 libpthreadstubs
157 libsysprof-capture
158 libtasn1
159 libwebp
160 libxkbcommon
161 libxml2
162 libxslt
163 libbacktrace
164 nettle
165 p11-kit
166 sqlite
167 woff2
168 ]
169 ++ lib.optionals clangStdenv.hostPlatform.isBigEndian [
170 # https://bugs.webkit.org/show_bug.cgi?id=274032
171 fontconfig
172 freetype
173 ]
174 ++ lib.optionals clangStdenv.hostPlatform.isDarwin [
175 libedit
176 readline
177 ]
178 ++ lib.optionals clangStdenv.hostPlatform.isLinux [
179 libseccomp
180 libmanette
181 wayland
182 xorg.libX11
183 ]
184 ++ lib.optionals systemdSupport [
185 systemd
186 ]
187 ++ lib.optionals enableGeoLocation [
188 geoclue2
189 ]
190 ++ lib.optionals enableExperimental [
191 # For ENABLE_WEB_RTC
192 openssl
193 # For ENABLE_WEBXR
194 openxr-loader
195 ]
196 ++ lib.optionals withLibsecret [
197 libsecret
198 ]
199 ++ lib.optionals (lib.versionAtLeast gtk3.version "4.0") [
200 wayland-protocols
201 ];
202
203 propagatedBuildInputs = [
204 gtk3
205 libsoup
206 ];
207
208 cmakeFlags =
209 let
210 cmakeBool = x: if x then "ON" else "OFF";
211 in
212 [
213 "-DENABLE_INTROSPECTION=ON"
214 "-DPORT=GTK"
215 "-DUSE_SOUP2=${cmakeBool (lib.versions.major libsoup.version == "2")}"
216 "-DUSE_LIBSECRET=${cmakeBool withLibsecret}"
217 "-DENABLE_EXPERIMENTAL_FEATURES=${cmakeBool enableExperimental}"
218 ]
219 ++ lib.optionals clangStdenv.hostPlatform.isLinux [
220 # Have to be explicitly specified when cross.
221 # https://github.com/WebKit/WebKit/commit/a84036c6d1d66d723f217a4c29eee76f2039a353
222 "-DBWRAP_EXECUTABLE=${lib.getExe bubblewrap}"
223 "-DDBUS_PROXY_EXECUTABLE=${lib.getExe xdg-dbus-proxy}"
224 ]
225 ++ lib.optionals clangStdenv.hostPlatform.isDarwin [
226 "-DENABLE_GAMEPAD=OFF"
227 "-DENABLE_GTKDOC=OFF"
228 "-DENABLE_MINIBROWSER=OFF"
229 "-DENABLE_QUARTZ_TARGET=ON"
230 "-DENABLE_X11_TARGET=OFF"
231 "-DUSE_APPLE_ICU=OFF"
232 "-DUSE_OPENGL_OR_ES=OFF"
233 ]
234 ++ lib.optionals (lib.versionOlder gtk3.version "4.0") [
235 "-DUSE_GTK4=OFF"
236 ]
237 ++ lib.optionals (!systemdSupport) [
238 "-DENABLE_JOURNALD_LOG=OFF"
239 ];
240
241 postPatch = ''
242 patchShebangs .
243 '';
244
245 postFixup = ''
246 # Cannot be in postInstall, otherwise _multioutDocs hook in preFixup will move right back.
247 moveToOutput "share/doc" "$devdoc"
248 '';
249
250 requiredSystemFeatures = [ "big-parallel" ];
251
252 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
253
254 meta = with lib; {
255 description = "Web content rendering engine, GTK port";
256 mainProgram = "WebKitWebDriver";
257 homepage = "https://webkitgtk.org/";
258 license = licenses.bsd2;
259 pkgConfigModules = [
260 "javascriptcoregtk-4.0"
261 "webkit2gtk-4.0"
262 "webkit2gtk-web-extension-4.0"
263 ];
264 platforms = platforms.linux ++ platforms.darwin;
265 teams = [ teams.gnome ];
266 broken = clangStdenv.hostPlatform.isDarwin;
267 };
268})