1{
2 lib,
3 stdenv,
4 replaceVars,
5 fetchurl,
6 pkg-config,
7 gettext,
8 docbook-xsl-nons,
9 docbook_xml_dtd_43,
10 gtk-doc,
11 meson,
12 mesonEmulatorHook,
13 ninja,
14 python3,
15 makeWrapper,
16 shared-mime-info,
17 isocodes,
18 expat,
19 glib,
20 cairo,
21 pango,
22 gdk-pixbuf,
23 atk,
24 at-spi2-atk,
25 gobject-introspection,
26 buildPackages,
27 withIntrospection ?
28 lib.meta.availableOn stdenv.hostPlatform gobject-introspection
29 && stdenv.hostPlatform.emulatorAvailable buildPackages,
30 compileSchemas ? stdenv.hostPlatform.emulatorAvailable buildPackages,
31 fribidi,
32 xorg,
33 libepoxy,
34 libxkbcommon,
35 libxml2,
36 gnome,
37 gsettings-desktop-schemas,
38 sassc,
39 trackerSupport ? stdenv.hostPlatform.isLinux && (stdenv.buildPlatform == stdenv.hostPlatform),
40 tinysparql,
41 x11Support ? stdenv.hostPlatform.isLinux,
42 waylandSupport ? stdenv.hostPlatform.isLinux,
43 libGL,
44 wayland,
45 wayland-protocols,
46 xineramaSupport ? stdenv.hostPlatform.isLinux,
47 cupsSupport ? stdenv.hostPlatform.isLinux,
48 cups,
49 broadwaySupport ? true,
50 wayland-scanner,
51 testers,
52}:
53
54let
55
56 gtkCleanImmodulesCache = replaceVars ./hooks/clean-immodules-cache.sh {
57 gtk_module_path = "gtk-3.0";
58 gtk_binary_version = "3.0.0";
59 };
60
61in
62
63stdenv.mkDerivation (finalAttrs: {
64 pname = "gtk+3";
65 version = "3.24.49";
66
67 outputs = [
68 "out"
69 "dev"
70 ]
71 ++ lib.optional withIntrospection "devdoc";
72 outputBin = "dev";
73
74 setupHooks = [
75 ./hooks/drop-icon-theme-cache.sh
76 gtkCleanImmodulesCache
77 ];
78
79 src =
80 let
81 inherit (finalAttrs) version;
82 in
83 fetchurl {
84 url = "mirror://gnome/sources/gtk/${lib.versions.majorMinor version}/gtk-${version}.tar.xz";
85 hash = "sha256-XqUsaijw5ezy6aPC+suzDQQLc4cfzV8zzRMX6QGKFG4=";
86 };
87
88 patches = [
89 ./patches/3.0-immodules.cache.patch
90 ./patches/3.0-Xft-setting-fallback-compute-DPI-properly.patch
91 ]
92 ++ lib.optionals stdenv.hostPlatform.isDarwin [
93 # X11 module requires <gio/gdesktopappinfo.h> which is not installed on Darwin
94 # let’s drop that dependency in similar way to how other parts of the library do it
95 # e.g. https://gitlab.gnome.org/GNOME/gtk/blob/3.24.4/gtk/gtk-launch.c#L31-33
96 # https://gitlab.gnome.org/GNOME/gtk/merge_requests/536
97 ./patches/3.0-darwin-x11.patch
98 ];
99
100 depsBuildBuild = [
101 pkg-config
102 ];
103 nativeBuildInputs = [
104 gettext
105 makeWrapper
106 meson
107 ninja
108 pkg-config
109 python3
110 sassc
111 gdk-pixbuf
112 ]
113 ++ finalAttrs.setupHooks
114 ++ lib.optionals withIntrospection [
115 gobject-introspection
116 docbook_xml_dtd_43
117 docbook-xsl-nons
118 gtk-doc
119 # For xmllint
120 libxml2
121 ]
122 ++
123 lib.optionals
124 ((withIntrospection || compileSchemas) && !stdenv.buildPlatform.canExecute stdenv.hostPlatform)
125 [
126 mesonEmulatorHook
127 ]
128 ++ lib.optionals waylandSupport [
129 wayland-scanner
130 ];
131
132 buildInputs =
133 lib.optionals (x11Support || waylandSupport) [
134 # TODO: Reorder me on `staging`.
135 libxkbcommon
136 ]
137 ++ [
138 (libepoxy.override { inherit x11Support; })
139 ]
140 ++ lib.optionals (x11Support || waylandSupport) [
141 isocodes
142 ]
143 ++ lib.optionals trackerSupport [
144 tinysparql
145 ];
146 #TODO: colord?
147
148 propagatedBuildInputs = [
149 at-spi2-atk
150 atk
151 cairo
152 expat
153 fribidi
154 gdk-pixbuf
155 glib
156 gsettings-desktop-schemas
157 ]
158 ++ lib.optionals x11Support (
159 with xorg;
160 [
161 libICE
162 libSM
163 libXcomposite
164 libXcursor
165 libXdamage
166 libXfixes
167 libXi
168 libXrandr
169 libXrender
170 ]
171 )
172 ++ [
173 # TODO: Reorder me on `staging`.
174 pango
175 ]
176 ++ lib.optionals waylandSupport [
177 libGL
178 wayland
179 wayland-protocols
180 ]
181 ++ lib.optionals xineramaSupport [
182 xorg.libXinerama
183 ]
184 ++ lib.optionals cupsSupport [
185 cups
186 ];
187
188 mesonFlags = [
189 "-Dgtk_doc=${lib.boolToString withIntrospection}"
190 "-Dtests=false"
191 "-Dtracker3=${lib.boolToString trackerSupport}"
192 "-Dbroadway_backend=${lib.boolToString broadwaySupport}"
193 "-Dx11_backend=${lib.boolToString x11Support}"
194 "-Dquartz_backend=${lib.boolToString (stdenv.hostPlatform.isDarwin && !x11Support)}"
195 "-Dintrospection=${lib.boolToString withIntrospection}"
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.NIX_CFLAGS_COMPILE = "-DG_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS";
205
206 postPatch = ''
207 # See https://github.com/NixOS/nixpkgs/issues/132259
208 substituteInPlace meson.build \
209 --replace "x11_enabled = false" ""
210
211 # this conditional gates the installation of share/gsettings-schemas/.../glib-2.0/schemas/gschemas.compiled.
212 substituteInPlace meson.build \
213 --replace 'if not meson.is_cross_build()' 'if ${lib.boolToString compileSchemas}'
214
215 files=(
216 build-aux/meson/post-install.py
217 demos/gtk-demo/geninclude.py
218 gdk/broadway/gen-c-array.py
219 gdk/gen-gdk-gresources-xml.py
220 gtk/cursor/dnd-copy.png
221 gtk/gen-gtk-gresources-xml.py
222 gtk/gen-rc.py
223 gtk/gentypefuncs.py
224 )
225
226 chmod +x ''${files[@]}
227 patchShebangs ''${files[@]}
228 '';
229
230 postInstall =
231 lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
232 # The updater is needed for nixos env and it's tiny.
233 moveToOutput bin/gtk-update-icon-cache "$out"
234 # Launcher
235 moveToOutput bin/gtk-launch "$out"
236 # Broadway daemon
237 moveToOutput bin/broadwayd "$out"
238
239 # TODO: patch glib directly
240 for f in $dev/bin/gtk-encode-symbolic-svg; do
241 wrapProgram $f --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
242 done
243 ''
244 + lib.optionalString (stdenv.buildPlatform == stdenv.hostPlatform) ''
245 GTK_PATH="''${out:?}/lib/gtk-3.0/3.0.0/immodules/" ''${dev:?}/bin/gtk-query-immodules-3.0 > "''${out:?}/lib/gtk-3.0/3.0.0/immodules.cache"
246 '';
247
248 # Wrap demos
249 postFixup =
250 lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
251 demos=(gtk3-demo gtk3-demo-application gtk3-icon-browser gtk3-widget-factory)
252
253 for program in ''${demos[@]}; do
254 wrapProgram $dev/bin/$program \
255 --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${finalAttrs.pname}-${finalAttrs.version}"
256 done
257 ''
258 + lib.optionalString stdenv.hostPlatform.isDarwin ''
259 # a comment created a cycle between outputs
260 sed '/^# ModulesPath =/d' -i "$out"/lib/gtk-*/*/immodules.cache
261 '';
262
263 passthru = {
264 updateScript = gnome.updateScript {
265 packageName = "gtk";
266 attrPath = "gtk3";
267 freeze = true;
268 };
269 tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
270 };
271
272 meta = with lib; {
273 description = "Multi-platform toolkit for creating graphical user interfaces";
274 longDescription = ''
275 GTK is a highly usable, feature rich toolkit for creating
276 graphical user interfaces which boasts cross platform
277 compatibility and an easy to use API. GTK it is written in C,
278 but has bindings to many other popular programming languages
279 such as C++, Python and C# among others. GTK is licensed
280 under the GNU LGPL 2.1 allowing development of both free and
281 proprietary software with GTK without any license fees or
282 royalties.
283 '';
284 homepage = "https://www.gtk.org/";
285 license = licenses.lgpl2Plus;
286 maintainers = with maintainers; [ raskin ];
287 teams = [ teams.gnome ];
288 pkgConfigModules = [
289 "gdk-3.0"
290 "gtk+-3.0"
291 ]
292 ++ lib.optionals x11Support [
293 "gdk-x11-3.0"
294 "gtk+-x11-3.0"
295 ];
296 platforms = platforms.all;
297 changelog = "https://gitlab.gnome.org/GNOME/gtk/-/raw/${finalAttrs.version}/NEWS";
298 };
299})