24 , gobject-introspection
26 , withIntrospection ? lib.meta.availableOn stdenv.hostPlatform gobject-introspection && stdenv.hostPlatform.emulatorAvailable buildPackages
27 , compileSchemas ? stdenv.hostPlatform.emulatorAvailable buildPackages
35 , gsettings-desktop-schemas
37 , trackerSupport ? stdenv.isLinux && (stdenv.buildPlatform == stdenv.hostPlatform)
39 , x11Support ? stdenv.isLinux
40 , waylandSupport ? stdenv.isLinux
44 , xineramaSupport ? stdenv.isLinux
45 , cupsSupport ? stdenv.isLinux
50 , broadwaySupport ? true
57 gtkCleanImmodulesCache = substituteAll {
58 src = ./hooks/clean-immodules-cache.sh;
59 gtk_module_path = "gtk-3.0";
60 gtk_binary_version = "3.0.0";
65 stdenv.mkDerivation (finalAttrs: {
69 outputs = [ "out" "dev" ] ++ lib.optional withIntrospection "devdoc";
73 ./hooks/drop-icon-theme-cache.sh
74 gtkCleanImmodulesCache
78 inherit (finalAttrs) version;
80 url = "mirror://gnome/sources/gtk+/${lib.versions.majorMinor version}/gtk+-${version}.tar.xz";
81 sha256 = "sha256-zhHezwGLJb3YUFVEpPhyQoVOyIvgVNmt5fOiBETdjuc=";
85 ./patches/3.0-immodules.cache.patch
86 ./patches/3.0-Xft-setting-fallback-compute-DPI-properly.patch
87 ] ++ lib.optionals stdenv.isDarwin [
88 # X11 module requires <gio/gdesktopappinfo.h> which is not installed on Darwin
89 # let’s drop that dependency in similar way to how other parts of the library do it
90 # e.g. https://gitlab.gnome.org/GNOME/gtk/blob/3.24.4/gtk/gtk-launch.c#L31-33
91 # https://gitlab.gnome.org/GNOME/gtk/merge_requests/536
92 ./patches/3.0-darwin-x11.patch
107 ] ++ finalAttrs.setupHooks ++ lib.optionals withIntrospection [
108 gobject-introspection
114 ] ++ lib.optionals ((withIntrospection || compileSchemas) && !stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
116 ] ++ lib.optionals waylandSupport [
122 (libepoxy.override { inherit x11Support; })
124 ] ++ lib.optionals stdenv.isDarwin [
126 ] ++ lib.optionals trackerSupport [
131 propagatedBuildInputs = with xorg; [
139 gsettings-desktop-schemas
150 ] ++ lib.optionals stdenv.isDarwin [
151 # explicitly propagated, always needed
154 ] ++ lib.optionals waylandSupport [
158 ] ++ lib.optionals xineramaSupport [
160 ] ++ lib.optionals cupsSupport [
165 "-Dgtk_doc=${lib.boolToString withIntrospection}"
167 "-Dtracker3=${lib.boolToString trackerSupport}"
168 "-Dbroadway_backend=${lib.boolToString broadwaySupport}"
169 "-Dx11_backend=${lib.boolToString x11Support}"
170 "-Dquartz_backend=${lib.boolToString (stdenv.isDarwin && !x11Support)}"
171 "-Dintrospection=${lib.boolToString withIntrospection}"
174 doCheck = false; # needs X11
176 separateDebugInfo = stdenv.isLinux;
178 # These are the defines that'd you'd get with --enable-debug=minimum (default).
179 # See: https://developer.gnome.org/gtk3/stable/gtk-building.html#extra-configuration-options
180 env.NIX_CFLAGS_COMPILE = "-DG_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS";
183 # See https://github.com/NixOS/nixpkgs/issues/132259
184 substituteInPlace meson.build \
185 --replace "x11_enabled = false" ""
187 # this conditional gates the installation of share/gsettings-schemas/.../glib-2.0/schemas/gschemas.compiled.
188 substituteInPlace meson.build \
189 --replace 'if not meson.is_cross_build()' 'if ${lib.boolToString compileSchemas}'
192 build-aux/meson/post-install.py
193 demos/gtk-demo/geninclude.py
194 gdk/broadway/gen-c-array.py
195 gdk/gen-gdk-gresources-xml.py
196 gtk/cursor/dnd-copy.png
197 gtk/gen-gtk-gresources-xml.py
202 chmod +x ''${files[@]}
203 patchShebangs ''${files[@]}
206 postInstall = lib.optionalString (!stdenv.isDarwin) ''
207 # The updater is needed for nixos env and it's tiny.
208 moveToOutput bin/gtk-update-icon-cache "$out"
210 moveToOutput bin/gtk-launch "$out"
212 moveToOutput bin/broadwayd "$out"
214 # TODO: patch glib directly
215 for f in $dev/bin/gtk-encode-symbolic-svg; do
216 wrapProgram $f --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
218 '' + lib.optionalString (stdenv.buildPlatform == stdenv.hostPlatform) ''
219 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"
223 postFixup = lib.optionalString (!stdenv.isDarwin) ''
224 demos=(gtk3-demo gtk3-demo-application gtk3-icon-browser gtk3-widget-factory)
226 for program in ''${demos[@]}; do
227 wrapProgram $dev/bin/$program \
228 --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${finalAttrs.pname}-${finalAttrs.version}"
230 '' + lib.optionalString stdenv.isDarwin ''
231 # a comment created a cycle between outputs
232 sed '/^# ModulesPath =/d' -i "$out"/lib/gtk-*/*/immodules.cache
236 updateScript = gnome.updateScript {
237 packageName = "gtk+";
241 tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
245 description = "A multi-platform toolkit for creating graphical user interfaces";
247 GTK is a highly usable, feature rich toolkit for creating
248 graphical user interfaces which boasts cross platform
249 compatibility and an easy to use API. GTK it is written in C,
250 but has bindings to many other popular programming languages
251 such as C++, Python and C# among others. GTK is licensed
252 under the GNU LGPL 2.1 allowing development of both free and
253 proprietary software with GTK without any license fees or
256 homepage = "https://www.gtk.org/";
257 license = licenses.lgpl2Plus;
258 maintainers = with maintainers; [ raskin ] ++ teams.gnome.members;
262 ] ++ lib.optionals x11Support [
266 platforms = platforms.all;
267 changelog = "https://gitlab.gnome.org/GNOME/gtk/-/raw/${version}/NEWS";