1{
2 lib,
3 stdenv,
4 buildPackages,
5 replaceVars,
6 fetchurl,
7 pkg-config,
8 docutils,
9 gettext,
10 graphene,
11 gi-docgen,
12 meson,
13 mesonEmulatorHook,
14 ninja,
15 python3,
16 makeWrapper,
17 shared-mime-info,
18 isocodes,
19 glib,
20 cairo,
21 pango,
22 gdk-pixbuf,
23 gobject-introspection,
24 fribidi,
25 harfbuzz,
26 xorg,
27 libepoxy,
28 libxkbcommon,
29 libpng,
30 libtiff,
31 libjpeg,
32 libxml2,
33 gnome,
34 gsettings-desktop-schemas,
35 gst_all_1,
36 sassc,
37 trackerSupport ? stdenv.hostPlatform.isLinux,
38 tinysparql,
39 x11Support ? stdenv.hostPlatform.isLinux,
40 waylandSupport ? stdenv.hostPlatform.isLinux,
41 libGL,
42 vulkanSupport ? stdenv.hostPlatform.isLinux,
43 shaderc,
44 vulkan-loader,
45 vulkan-headers,
46 libdrm,
47 wayland,
48 wayland-protocols,
49 wayland-scanner,
50 xineramaSupport ? stdenv.hostPlatform.isLinux,
51 cupsSupport ? stdenv.hostPlatform.isLinux,
52 compileSchemas ? stdenv.hostPlatform.emulatorAvailable buildPackages,
53 cups,
54 libexecinfo,
55 broadwaySupport ? true,
56 testers,
57 darwinMinVersionHook,
58}:
59
60let
61
62 gtkCleanImmodulesCache = replaceVars ./hooks/clean-immodules-cache.sh {
63 gtk_module_path = "gtk-4.0";
64 gtk_binary_version = "4.0.0";
65 };
66
67in
68
69stdenv.mkDerivation (finalAttrs: {
70 pname = "gtk4";
71 version = "4.18.6";
72
73 outputs = [
74 "out"
75 "dev"
76 ]
77 ++ lib.optionals x11Support [ "devdoc" ];
78 outputBin = "dev";
79
80 setupHooks = [
81 ./hooks/drop-icon-theme-cache.sh
82 gtkCleanImmodulesCache
83 ];
84
85 src = fetchurl {
86 url = "mirror://gnome/sources/gtk/${lib.versions.majorMinor finalAttrs.version}/gtk-${finalAttrs.version}.tar.xz";
87 hash = "sha256-4YF8ZQ3cMmH5qDRbOyKial2ArxVGMN7cA8x77O//0Po=";
88 };
89
90 depsBuildBuild = [
91 pkg-config
92 ];
93
94 nativeBuildInputs = [
95 docutils # for rst2man, rst2html5
96 gettext
97 gobject-introspection
98 makeWrapper
99 meson
100 ninja
101 pkg-config
102 python3
103 sassc
104 gi-docgen
105 libxml2 # for xmllint
106 ]
107 ++ lib.optionals (compileSchemas && !stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
108 mesonEmulatorHook
109 ]
110 ++ lib.optionals waylandSupport [
111 wayland-scanner
112 ]
113 ++ lib.optionals vulkanSupport [
114 shaderc # for glslc
115 ]
116 ++ finalAttrs.setupHooks;
117
118 buildInputs = [
119 libxkbcommon
120 libpng
121 libtiff
122 libjpeg
123 (libepoxy.override { inherit x11Support; })
124 isocodes
125 ]
126 ++ lib.optionals vulkanSupport [
127 vulkan-headers
128 libdrm
129 ]
130 ++ [
131 gst_all_1.gst-plugins-base
132 gst_all_1.gst-plugins-bad
133 fribidi
134 harfbuzz
135 ]
136 ++ (with xorg; [
137 libICE
138 libSM
139 libXcursor
140 libXdamage
141 libXi
142 libXrandr
143 libXrender
144 ])
145 ++ lib.optionals trackerSupport [
146 tinysparql
147 ]
148 ++ lib.optionals waylandSupport [
149 libGL
150 wayland
151 wayland-protocols
152 ]
153 ++ lib.optionals xineramaSupport [
154 xorg.libXinerama
155 ]
156 ++ lib.optionals cupsSupport [
157 cups
158 ]
159 ++ lib.optionals stdenv.hostPlatform.isMusl [
160 libexecinfo
161 ];
162 #TODO: colord?
163
164 propagatedBuildInputs = [
165 # Required by pkg-config files.
166 cairo
167 gdk-pixbuf
168 glib
169 graphene
170 pango
171 ]
172 ++ lib.optionals waylandSupport [
173 wayland
174 ]
175 ++ lib.optionals vulkanSupport [
176 vulkan-loader
177 ]
178 ++ [
179 # Required for GSettings schemas at runtime.
180 # Will be picked up by wrapGAppsHook4.
181 gsettings-desktop-schemas
182 ];
183
184 mesonFlags = [
185 # ../docs/tools/shooter.c:4:10: fatal error: 'cairo-xlib.h' file not found
186 (lib.mesonBool "documentation" x11Support)
187 "-Dbuild-tests=false"
188 (lib.mesonEnable "tracker" trackerSupport)
189 (lib.mesonBool "broadway-backend" broadwaySupport)
190 (lib.mesonEnable "vulkan" vulkanSupport)
191 (lib.mesonEnable "print-cups" cupsSupport)
192 (lib.mesonBool "x11-backend" x11Support)
193 ]
194 ++ lib.optionals (stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isAarch64) [
195 "-Dmedia-gstreamer=disabled" # requires gstreamer-gl
196 ];
197
198 doCheck = false; # needs X11
199
200 separateDebugInfo = stdenv.hostPlatform.isLinux;
201
202 # These are the defines that'd you'd get with --enable-debug=minimum (default).
203 # See: https://developer.gnome.org/gtk3/stable/gtk-building.html#extra-configuration-options
204 env = {
205 NIX_CFLAGS_COMPILE = "-DG_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS";
206 }
207 // lib.optionalAttrs stdenv.hostPlatform.isMusl {
208 NIX_LDFLAGS = "-lexecinfo";
209 };
210
211 postPatch = ''
212 # this conditional gates the installation of share/gsettings-schemas/.../glib-2.0/schemas/gschemas.compiled.
213 substituteInPlace meson.build \
214 --replace 'if not meson.is_cross_build()' 'if ${lib.boolToString compileSchemas}'
215
216 files=(
217 build-aux/meson/gen-profile-conf.py
218 build-aux/meson/gen-visibility-macros.py
219 demos/gtk-demo/geninclude.py
220 gdk/broadway/gen-c-array.py
221 gdk/gen-gdk-gresources-xml.py
222 gtk/gen-gtk-gresources-xml.py
223 gtk/gentypefuncs.py
224 )
225
226 chmod +x ''${files[@]}
227 patchShebangs ''${files[@]}
228
229 '';
230
231 preInstall = ''
232 OLD_PATH="$PATH"
233 PATH="$PATH:$dev/bin" # so the install script finds gtk4-update-icon-cache
234 '';
235
236 postInstall = ''
237 PATH="$OLD_PATH"
238 ''
239 + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
240 # The updater is needed for nixos env and it's tiny.
241 moveToOutput bin/gtk4-update-icon-cache "$out"
242 # Launcher
243 moveToOutput bin/gtk-launch "$out"
244
245 # TODO: patch glib directly
246 for f in $dev/bin/gtk4-encode-symbolic-svg; do
247 wrapProgram $f --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
248 done
249 ''
250 + lib.optionalString broadwaySupport ''
251 # Broadway daemon
252 moveToOutput bin/gtk4-broadwayd "$out"
253 '';
254
255 # Wrap demos
256 postFixup =
257 lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
258 demos=(gtk4-demo gtk4-demo-application gtk4-widget-factory)
259
260 for program in ''${demos[@]}; do
261 wrapProgram $dev/bin/$program \
262 --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${finalAttrs.pname}-${finalAttrs.version}"
263 done
264 ''
265 + lib.optionalString x11Support ''
266 # Cannot be in postInstall, otherwise _multioutDocs hook in preFixup will move right back.
267 moveToOutput "share/doc" "$devdoc"
268 '';
269
270 passthru = {
271 updateScript = gnome.updateScript {
272 packageName = "gtk";
273 versionPolicy = "odd-unstable";
274 attrPath = "gtk4";
275 };
276 tests = {
277 pkg-config = testers.hasPkgConfigModules {
278 package = finalAttrs.finalPackage;
279 };
280 };
281 };
282
283 meta = with lib; {
284 description = "Multi-platform toolkit for creating graphical user interfaces";
285 longDescription = ''
286 GTK is a highly usable, feature rich toolkit for creating
287 graphical user interfaces which boasts cross platform
288 compatibility and an easy to use API. GTK it is written in C,
289 but has bindings to many other popular programming languages
290 such as C++, Python and C# among others. GTK is licensed
291 under the GNU LGPL 2.1 allowing development of both free and
292 proprietary software with GTK without any license fees or
293 royalties.
294 '';
295 homepage = "https://www.gtk.org/";
296 license = licenses.lgpl2Plus;
297 maintainers = with maintainers; [ raskin ];
298 teams = [ teams.gnome ];
299 platforms = platforms.all;
300 changelog = "https://gitlab.gnome.org/GNOME/gtk/-/raw/${finalAttrs.version}/NEWS";
301 pkgConfigModules = [
302 "gtk4"
303 ]
304 ++ lib.optionals broadwaySupport [
305 "gtk4-broadway"
306 ]
307 ++ lib.optionals stdenv.hostPlatform.isUnix [
308 "gtk4-unix-print"
309 ]
310 ++ lib.optionals waylandSupport [
311 "gtk4-wayland"
312 ]
313 ++ lib.optionals x11Support [
314 "gtk4-x11"
315 ];
316 };
317})