22 , gobject-introspection
33 , gsettings-desktop-schemas
36 , trackerSupport ? stdenv.hostPlatform.isLinux
38 , x11Support ? stdenv.hostPlatform.isLinux
39 , waylandSupport ? stdenv.hostPlatform.isLinux
41 , vulkanSupport ? stdenv.hostPlatform.isLinux
49 , xineramaSupport ? stdenv.hostPlatform.isLinux
50 , cupsSupport ? stdenv.hostPlatform.isLinux
51 , compileSchemas ? stdenv.hostPlatform.emulatorAvailable buildPackages
54 , broadwaySupport ? true
58 , darwinMinVersionHook
63 gtkCleanImmodulesCache = substituteAll {
64 src = ./hooks/clean-immodules-cache.sh;
65 gtk_module_path = "gtk-4.0";
66 gtk_binary_version = "4.0.0";
71 stdenv.mkDerivation (finalAttrs: {
75 outputs = [ "out" "dev" ] ++ lib.optionals x11Support [ "devdoc" ];
79 ./hooks/drop-icon-theme-cache.sh
80 gtkCleanImmodulesCache
84 url = with finalAttrs; "mirror://gnome/sources/gtk/${lib.versions.majorMinor version}/gtk-${version}.tar.xz";
85 hash = "sha256-LsU+B9GMnwA7OeSmqDgFTZJZ4Ei2xMBdgMDQWqch2UQ=";
93 docutils # for rst2man, rst2html5
103 libxml2 # for xmllint
104 ] ++ lib.optionals (compileSchemas && !stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
106 ] ++ lib.optionals waylandSupport [
108 ] ++ lib.optionals vulkanSupport [
110 ] ++ finalAttrs.setupHooks;
117 (libepoxy.override { inherit x11Support; })
119 ] ++ lib.optionals vulkanSupport [
123 gst_all_1.gst-plugins-base
124 gst_all_1.gst-plugins-bad
135 ]) ++ lib.optionals trackerSupport [
137 ] ++ lib.optionals waylandSupport [
141 ] ++ lib.optionals xineramaSupport [
143 ] ++ lib.optionals cupsSupport [
145 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
150 propagatedBuildInputs = [
151 # Required by pkg-config files.
157 ] ++ lib.optionals waylandSupport [
159 ] ++ lib.optionals vulkanSupport [
162 # Required for GSettings schemas at runtime.
163 # Will be picked up by wrapGAppsHook4.
164 gsettings-desktop-schemas
165 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
166 (darwinMinVersionHook "15.0")
167 ] ++ lib.optionals (stdenv.hostPlatform.isDarwin
168 && lib.versionOlder apple-sdk.version "10.15") [
173 # ../docs/tools/shooter.c:4:10: fatal error: 'cairo-xlib.h' file not found
174 (lib.mesonBool "documentation" x11Support)
175 "-Dbuild-tests=false"
176 (lib.mesonEnable "tracker" trackerSupport)
177 (lib.mesonBool "broadway-backend" broadwaySupport)
178 (lib.mesonEnable "vulkan" vulkanSupport)
179 (lib.mesonEnable "print-cups" cupsSupport)
180 (lib.mesonBool "x11-backend" x11Support)
181 ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isAarch64) [
182 "-Dmedia-gstreamer=disabled" # requires gstreamer-gl
185 doCheck = false; # needs X11
187 separateDebugInfo = stdenv.hostPlatform.isLinux;
189 # These are the defines that'd you'd get with --enable-debug=minimum (default).
190 # See: https://developer.gnome.org/gtk3/stable/gtk-building.html#extra-configuration-options
192 NIX_CFLAGS_COMPILE = "-DG_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS";
193 } // lib.optionalAttrs stdenv.hostPlatform.isMusl {
194 NIX_LDFLAGS = "-lexecinfo";
198 # this conditional gates the installation of share/gsettings-schemas/.../glib-2.0/schemas/gschemas.compiled.
199 substituteInPlace meson.build \
200 --replace 'if not meson.is_cross_build()' 'if ${lib.boolToString compileSchemas}'
203 build-aux/meson/gen-profile-conf.py
204 build-aux/meson/gen-visibility-macros.py
205 demos/gtk-demo/geninclude.py
206 gdk/broadway/gen-c-array.py
207 gdk/gen-gdk-gresources-xml.py
208 gtk/gen-gtk-gresources-xml.py
212 chmod +x ''${files[@]}
213 patchShebangs ''${files[@]}
219 PATH="$PATH:$dev/bin" # so the install script finds gtk4-update-icon-cache
224 '' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
225 # The updater is needed for nixos env and it's tiny.
226 moveToOutput bin/gtk4-update-icon-cache "$out"
228 moveToOutput bin/gtk-launch "$out"
230 # TODO: patch glib directly
231 for f in $dev/bin/gtk4-encode-symbolic-svg; do
232 wrapProgram $f --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
234 '' + lib.optionalString broadwaySupport ''
236 moveToOutput bin/gtk4-broadwayd "$out"
240 postFixup = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
241 demos=(gtk4-demo gtk4-demo-application gtk4-icon-browser gtk4-widget-factory)
243 for program in ''${demos[@]}; do
244 wrapProgram $dev/bin/$program \
245 --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${finalAttrs.pname}-${finalAttrs.version}"
247 '' + lib.optionalString x11Support ''
248 # Cannot be in postInstall, otherwise _multioutDocs hook in preFixup will move right back.
249 moveToOutput "share/doc" "$devdoc"
253 updateScript = gnome.updateScript {
255 versionPolicy = "odd-unstable";
259 pkg-config = testers.hasPkgConfigModules {
260 package = finalAttrs.finalPackage;
266 description = "Multi-platform toolkit for creating graphical user interfaces";
268 GTK is a highly usable, feature rich toolkit for creating
269 graphical user interfaces which boasts cross platform
270 compatibility and an easy to use API. GTK it is written in C,
271 but has bindings to many other popular programming languages
272 such as C++, Python and C# among others. GTK is licensed
273 under the GNU LGPL 2.1 allowing development of both free and
274 proprietary software with GTK without any license fees or
277 homepage = "https://www.gtk.org/";
278 license = licenses.lgpl2Plus;
279 maintainers = teams.gnome.members ++ (with maintainers; [ raskin ]);
280 platforms = platforms.all;
281 changelog = "https://gitlab.gnome.org/GNOME/gtk/-/raw/${finalAttrs.version}/NEWS";
284 ] ++ lib.optionals broadwaySupport [
286 ] ++ lib.optionals stdenv.hostPlatform.isUnix [
288 ] ++ lib.optionals waylandSupport [
290 ] ++ lib.optionals x11Support [