about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/gtk
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/gtk')
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/2.x.nix101
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/3.x.nix221
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/4.x.nix233
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/hooks/drop-icon-theme-cache.sh19
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/hooks/gtk2-clean-immodules-cache.sh12
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/hooks/gtk3-clean-immodules-cache.sh11
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/hooks/gtk4-clean-immodules-cache.sh11
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/patches/2.0-darwin-x11.patch22
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/patches/2.0-immodules.cache.patch27
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/patches/3.0-darwin-x11.patch28
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/patches/3.0-immodules.cache.patch27
-rw-r--r--nixpkgs/pkgs/development/libraries/gtk/patches/gtk2-theme-paths.patch40
12 files changed, 752 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/gtk/2.x.nix b/nixpkgs/pkgs/development/libraries/gtk/2.x.nix
new file mode 100644
index 000000000000..4304cb388d1a
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/2.x.nix
@@ -0,0 +1,101 @@
+{ config, lib, stdenv, fetchurl, pkg-config, gettext, glib, atk, pango, cairo, perl, xorg
+, gdk-pixbuf, xlibsWrapper, gobject-introspection
+, xineramaSupport ? stdenv.isLinux
+, cupsSupport ? config.gtk2.cups or stdenv.isLinux, cups ? null
+, gdktarget ? if stdenv.isDarwin then "quartz" else "x11"
+, AppKit, Cocoa
+, fetchpatch
+}:
+
+assert xineramaSupport -> xorg.libXinerama != null;
+assert cupsSupport -> cups != null;
+
+with lib;
+
+stdenv.mkDerivation rec {
+  pname = "gtk+";
+  version = "2.24.32";
+
+  src = fetchurl {
+    url = "mirror://gnome/sources/gtk+/2.24/${pname}-${version}.tar.xz";
+    sha256 = "b6c8a93ddda5eabe3bfee1eb39636c9a03d2a56c7b62828b359bf197943c582e";
+  };
+
+  outputs = [ "out" "dev" "devdoc" ];
+  outputBin = "dev";
+
+  enableParallelBuilding = true;
+
+  setupHooks =  [
+    ./hooks/gtk2-clean-immodules-cache.sh
+    ./hooks/drop-icon-theme-cache.sh
+  ];
+
+  nativeBuildInputs = setupHooks ++ [ perl pkg-config gettext gobject-introspection ];
+
+  patches = [
+    ./patches/2.0-immodules.cache.patch
+    ./patches/gtk2-theme-paths.patch
+  ] ++ optionals stdenv.isDarwin [
+    (fetchpatch {
+      url = "https://bug557780.bugzilla-attachments.gnome.org/attachment.cgi?id=306776";
+      sha256 = "0sp8f1r5c4j2nlnbqgv7s7nxa4cfwigvm033hvhb1ld652pjag4r";
+    })
+    ./patches/2.0-darwin-x11.patch
+  ];
+
+  propagatedBuildInputs = with xorg;
+    [ glib cairo pango gdk-pixbuf atk ]
+    ++ optionals (stdenv.isLinux || stdenv.isDarwin) [
+         libXrandr libXrender libXcomposite libXi libXcursor
+       ]
+    ++ optionals stdenv.isDarwin [ xlibsWrapper libXdamage ]
+    ++ optional xineramaSupport libXinerama
+    ++ optionals cupsSupport [ cups ]
+    ++ optionals stdenv.isDarwin [ AppKit Cocoa ];
+
+  configureFlags = [
+    "--with-gdktarget=${gdktarget}"
+    "--with-xinput=yes"
+  ] ++ optionals stdenv.isDarwin [
+    "--disable-glibtest"
+    "--disable-introspection"
+    "--disable-visibility"
+  ];
+
+  doCheck = false; # needs X11
+
+  postInstall = ''
+    moveToOutput share/gtk-2.0/demo "$devdoc"
+    # The updater is needed for nixos env and it's tiny.
+    moveToOutput bin/gtk-update-icon-cache "$out"
+  '';
+
+  passthru = {
+    gtkExeEnvPostBuild = ''
+      rm $out/lib/gtk-2.0/2.10.0/immodules.cache
+      $out/bin/gtk-query-immodules-2.0 $out/lib/gtk-2.0/2.10.0/immodules/*.so > $out/lib/gtk-2.0/2.10.0/immodules.cache
+    ''; # workaround for bug of nix-mode for Emacs */ '';
+    inherit gdktarget;
+  };
+
+  meta = {
+    description = "A multi-platform toolkit for creating graphical user interfaces";
+    homepage    = "https://www.gtk.org/";
+    license     = licenses.lgpl2Plus;
+    maintainers = with maintainers; [ lovek323 raskin ];
+    platforms   = platforms.all;
+
+    longDescription = ''
+      GTK is a highly usable, feature rich toolkit for creating
+      graphical user interfaces which boasts cross platform
+      compatibility and an easy to use API.  GTK it is written in C,
+      but has bindings to many other popular programming languages
+      such as C++, Python and C# among others.  GTK is licensed
+      under the GNU LGPL 2.1 allowing development of both free and
+      proprietary software with GTK without any license fees or
+      royalties.
+    '';
+    changelog = "https://gitlab.gnome.org/GNOME/gtk/-/raw/${version}/NEWS";
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/gtk/3.x.nix b/nixpkgs/pkgs/development/libraries/gtk/3.x.nix
new file mode 100644
index 000000000000..5180df634604
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/3.x.nix
@@ -0,0 +1,221 @@
+{ lib, stdenv
+, fetchurl
+, fetchpatch
+, pkg-config
+, gettext
+, docbook-xsl-nons
+, docbook_xml_dtd_43
+, gtk-doc
+, meson
+, ninja
+, python3
+, makeWrapper
+, shared-mime-info
+, isocodes
+, expat
+, glib
+, cairo
+, pango
+, gdk-pixbuf
+, atk
+, at-spi2-atk
+, gobject-introspection
+, fribidi
+, xorg
+, epoxy
+, json-glib
+, libxkbcommon
+, libxml2
+, gmp
+, gnome3
+, gsettings-desktop-schemas
+, sassc
+, trackerSupport ? stdenv.isLinux
+, tracker
+, x11Support ? stdenv.isLinux
+, waylandSupport ? stdenv.isLinux
+, mesa
+, wayland
+, wayland-protocols
+, xineramaSupport ? stdenv.isLinux
+, cupsSupport ? stdenv.isLinux
+, withGtkDoc ? stdenv.isLinux
+, cups ? null
+, AppKit
+, Cocoa
+, broadwaySupport ? true
+}:
+
+assert cupsSupport -> cups != null;
+
+stdenv.mkDerivation rec {
+  pname = "gtk+3";
+  version = "3.24.24";
+
+  outputs = [ "out" "dev" ] ++ lib.optional withGtkDoc "devdoc";
+  outputBin = "dev";
+
+  setupHooks = [
+    ./hooks/gtk3-clean-immodules-cache.sh
+    ./hooks/drop-icon-theme-cache.sh
+  ];
+
+  src = fetchurl {
+    url = "mirror://gnome/sources/gtk+/${lib.versions.majorMinor version}/gtk+-${version}.tar.xz";
+    sha256 = "12ipk1d376bai9v820qzhxba93kkh5abi6mhyqr4hwjvqmkl77fc";
+  };
+
+  patches = [
+    ./patches/3.0-immodules.cache.patch
+
+    (fetchpatch {
+      name = "Xft-setting-fallback-compute-DPI-properly.patch";
+      url = "https://bug757142.bugzilla-attachments.gnome.org/attachment.cgi?id=344123";
+      sha256 = "0g6fhqcv8spfy3mfmxpyji93k8d4p4q4fz1v9a1c1cgcwkz41d7p";
+    })
+  ] ++ lib.optionals stdenv.isDarwin [
+    # X11 module requires <gio/gdesktopappinfo.h> which is not installed on Darwin
+    # let’s drop that dependency in similar way to how other parts of the library do it
+    # e.g. https://gitlab.gnome.org/GNOME/gtk/blob/3.24.4/gtk/gtk-launch.c#L31-33
+    # https://gitlab.gnome.org/GNOME/gtk/merge_requests/536
+    ./patches/3.0-darwin-x11.patch
+  ];
+
+  nativeBuildInputs = [
+    gettext
+    gobject-introspection
+    makeWrapper
+    meson
+    ninja
+    pkg-config
+    python3
+    sassc
+  ] ++ setupHooks ++ lib.optionals withGtkDoc [
+    docbook_xml_dtd_43
+    docbook-xsl-nons
+    gtk-doc
+    # For xmllint
+    libxml2
+  ];
+
+  buildInputs = [
+    libxkbcommon
+    epoxy
+    json-glib
+    isocodes
+  ] ++ lib.optionals stdenv.isDarwin [
+    AppKit
+  ] ++ lib.optionals trackerSupport [
+    tracker
+  ];
+  #TODO: colord?
+
+  propagatedBuildInputs = with xorg; [
+    at-spi2-atk
+    atk
+    cairo
+    expat
+    fribidi
+    gdk-pixbuf
+    glib
+    gsettings-desktop-schemas
+    libICE
+    libSM
+    libXcomposite
+    libXcursor
+    libXi
+    libXrandr
+    libXrender
+    pango
+  ] ++ lib.optionals stdenv.isDarwin [
+    # explicitly propagated, always needed
+    Cocoa
+  ] ++ lib.optionals waylandSupport [
+    mesa
+    wayland
+    wayland-protocols
+  ] ++ lib.optionals xineramaSupport [
+    libXinerama
+  ] ++ lib.optionals cupsSupport [
+    cups
+  ];
+
+  mesonFlags = [
+    "-Dgtk_doc=${lib.boolToString withGtkDoc}"
+    "-Dtests=false"
+    "-Dtracker3=${lib.boolToString trackerSupport}"
+    "-Dbroadway_backend=${lib.boolToString broadwaySupport}"
+  ];
+
+  doCheck = false; # needs X11
+
+  separateDebugInfo = stdenv.isLinux;
+
+  # These are the defines that'd you'd get with --enable-debug=minimum (default).
+  # See: https://developer.gnome.org/gtk3/stable/gtk-building.html#extra-configuration-options
+  NIX_CFLAGS_COMPILE = "-DG_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS";
+
+  postPatch = ''
+    files=(
+      build-aux/meson/post-install.py
+      demos/gtk-demo/geninclude.py
+      gdk/broadway/gen-c-array.py
+      gdk/gen-gdk-gresources-xml.py
+      gtk/cursor/dnd-copy.png
+      gtk/gen-gtk-gresources-xml.py
+      gtk/gen-rc.py
+      gtk/gentypefuncs.py
+    )
+
+    chmod +x ''${files[@]}
+    patchShebangs ''${files[@]}
+  '';
+
+  postInstall = lib.optionalString (!stdenv.isDarwin) ''
+    # The updater is needed for nixos env and it's tiny.
+    moveToOutput bin/gtk-update-icon-cache "$out"
+    # Launcher
+    moveToOutput bin/gtk-launch "$out"
+
+    # TODO: patch glib directly
+    for f in $dev/bin/gtk-encode-symbolic-svg; do
+      wrapProgram $f --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
+    done
+  '';
+
+  # Wrap demos
+  postFixup =  lib.optionalString (!stdenv.isDarwin) ''
+    demos=(gtk3-demo gtk3-demo-application gtk3-icon-browser gtk3-widget-factory)
+
+    for program in ''${demos[@]}; do
+      wrapProgram $dev/bin/$program \
+        --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${pname}-${version}"
+    done
+  '';
+
+  passthru = {
+    updateScript = gnome3.updateScript {
+      packageName = "gtk+";
+      attrPath = "gtk3";
+    };
+  };
+
+  meta = with lib; {
+    description = "A multi-platform toolkit for creating graphical user interfaces";
+    longDescription = ''
+      GTK is a highly usable, feature rich toolkit for creating
+      graphical user interfaces which boasts cross platform
+      compatibility and an easy to use API.  GTK it is written in C,
+      but has bindings to many other popular programming languages
+      such as C++, Python and C# among others.  GTK is licensed
+      under the GNU LGPL 2.1 allowing development of both free and
+      proprietary software with GTK without any license fees or
+      royalties.
+    '';
+    homepage = "https://www.gtk.org/";
+    license = licenses.lgpl2Plus;
+    maintainers = with maintainers; [ raskin vcunat lethalman worldofpeace ];
+    platforms = platforms.all;
+    changelog = "https://gitlab.gnome.org/GNOME/gtk/-/raw/${version}/NEWS";
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/gtk/4.x.nix b/nixpkgs/pkgs/development/libraries/gtk/4.x.nix
new file mode 100644
index 000000000000..59b0b080a52a
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/4.x.nix
@@ -0,0 +1,233 @@
+{ lib
+, stdenv
+, fetchurl
+, pkg-config
+, gettext
+, graphene
+, docbook-xsl-nons
+, docbook_xml_dtd_43
+, gtk-doc
+, meson
+, ninja
+, python3
+, makeWrapper
+, shared-mime-info
+, isocodes
+, glib
+, cairo
+, pango
+, pandoc
+, gdk-pixbuf
+, gobject-introspection
+, fribidi
+, xorg
+, epoxy
+, json-glib
+, libxkbcommon
+, libxml2
+, librest
+, libsoup
+, ffmpeg
+, gmp
+, gnome3
+, gsettings-desktop-schemas
+, gst_all_1
+, sassc
+, trackerSupport ? stdenv.isLinux
+, tracker
+, x11Support ? stdenv.isLinux
+, waylandSupport ? stdenv.isLinux
+, mesa
+, vulkan-loader
+, vulkan-headers
+, wayland
+, wayland-protocols
+, xineramaSupport ? stdenv.isLinux
+, cupsSupport ? stdenv.isLinux
+, withGtkDoc ? stdenv.isLinux
+, cups ? null
+, AppKit
+, Cocoa
+, broadwaySupport ? true
+}:
+
+assert cupsSupport -> cups != null;
+
+stdenv.mkDerivation rec {
+  pname = "gtk4";
+  version = "4.0.2";
+
+  outputs = [ "out" "dev" ] ++ lib.optional withGtkDoc "devdoc";
+  outputBin = "dev";
+
+  setupHooks = [
+    ./hooks/gtk4-clean-immodules-cache.sh
+    ./hooks/drop-icon-theme-cache.sh
+  ];
+
+  src = fetchurl {
+    url = "mirror://gnome/sources/gtk/${lib.versions.majorMinor version}/gtk-${version}.tar.xz";
+    sha256 = "115w3mzwm1xsi1q85qvwfm2yxpsjs2rcajgddzbnwhjicyn0frv2";
+  };
+
+  nativeBuildInputs = [
+    gettext
+    gobject-introspection
+    makeWrapper
+    meson
+    ninja
+    pkg-config
+    python3
+    sassc
+  ] ++ setupHooks ++ lib.optionals withGtkDoc [
+    pandoc
+    docbook_xml_dtd_43
+    docbook-xsl-nons
+    gtk-doc
+    # For xmllint
+    libxml2
+  ];
+
+  buildInputs = [
+    libxkbcommon
+    epoxy
+    json-glib
+    isocodes
+    vulkan-headers
+    librest
+    libsoup
+    ffmpeg
+    gst_all_1.gst-plugins-base
+    gst_all_1.gst-plugins-bad
+    fribidi
+  ] ++ (with xorg; [
+    libICE
+    libSM
+    libXcomposite
+    libXcursor
+    libXi
+    libXrandr
+    libXrender
+  ]) ++ lib.optionals stdenv.isDarwin [
+    AppKit
+  ] ++ lib.optionals trackerSupport [
+    tracker
+  ] ++ lib.optionals waylandSupport [
+    mesa
+    wayland
+    wayland-protocols
+  ] ++ lib.optionals xineramaSupport [
+    xorg.libXinerama
+  ] ++ lib.optionals cupsSupport [
+    cups
+  ] ++ lib.optionals stdenv.isDarwin [
+    Cocoa
+  ];
+  #TODO: colord?
+
+  propagatedBuildInputs = [
+    # Required by pkg-config files.
+    cairo
+    gdk-pixbuf
+    glib
+    graphene
+    pango
+    vulkan-loader # TODO: Possibly not used on Darwin
+
+    # Required for GSettings schemas at runtime.
+    # Will be picked up by wrapGAppsHook.
+    gsettings-desktop-schemas
+  ];
+
+  mesonFlags = [
+    "-Dgtk_doc=${lib.boolToString withGtkDoc}"
+    "-Dtests=false"
+    "-Dtracker3=${lib.boolToString trackerSupport}"
+    "-Dbroadway_backend=${lib.boolToString broadwaySupport}"
+  ];
+
+  doCheck = false; # needs X11
+
+  separateDebugInfo = stdenv.isLinux;
+
+  # These are the defines that'd you'd get with --enable-debug=minimum (default).
+  # See: https://developer.gnome.org/gtk3/stable/gtk-building.html#extra-configuration-options
+  NIX_CFLAGS_COMPILE = "-DG_ENABLE_DEBUG -DG_DISABLE_CAST_CHECKS";
+
+  postPatch = ''
+    files=(
+      build-aux/meson/post-install.py
+      demos/gtk-demo/geninclude.py
+      gdk/broadway/gen-c-array.py
+      gdk/gen-gdk-gresources-xml.py
+      gtk/gen-gtk-gresources-xml.py
+      gtk/gentypefuncs.py
+      docs/reference/gtk/gtk-markdown-to-docbook
+    )
+
+    chmod +x ''${files[@]}
+    patchShebangs ''${files[@]}
+  '';
+
+  postBuild =  lib.optionalString withGtkDoc ''
+    # Meson not building `custom_target`s passed to `custom_files` argument of `gnome.gtkdoc` function
+    # as part of the `install` target. We have to build the docs manually first.
+    # https://github.com/mesonbuild/meson/issues/2831
+    ninja g{t,d,s}k4-doc
+  '';
+
+  preInstall = ''
+    OLD_PATH="$PATH"
+    PATH="$PATH:$dev/bin" # so the install script finds gtk4-update-icon-cache
+  '';
+
+  postInstall = ''
+    PATH="$OLD_PATH"
+  '' + lib.optionalString (!stdenv.isDarwin) ''
+    # The updater is needed for nixos env and it's tiny.
+    moveToOutput bin/gtk4-update-icon-cache "$out"
+    # Launcher
+    moveToOutput bin/gtk-launch "$out"
+
+    # TODO: patch glib directly
+    for f in $dev/bin/gtk4-encode-symbolic-svg; do
+      wrapProgram $f --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
+    done
+  '';
+
+  # Wrap demos
+  postFixup =  lib.optionalString (!stdenv.isDarwin) ''
+    demos=(gtk4-demo gtk4-demo-application gtk4-icon-browser gtk4-widget-factory)
+
+    for program in ''${demos[@]}; do
+      wrapProgram $dev/bin/$program \
+        --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${pname}-${version}"
+    done
+  '';
+
+  passthru = {
+    updateScript = gnome3.updateScript {
+      packageName = "gtk";
+      attrPath = "gtk4";
+    };
+  };
+
+  meta = with lib; {
+    description = "A multi-platform toolkit for creating graphical user interfaces";
+    longDescription = ''
+      GTK is a highly usable, feature rich toolkit for creating
+      graphical user interfaces which boasts cross platform
+      compatibility and an easy to use API.  GTK it is written in C,
+      but has bindings to many other popular programming languages
+      such as C++, Python and C# among others.  GTK is licensed
+      under the GNU LGPL 2.1 allowing development of both free and
+      proprietary software with GTK without any license fees or
+      royalties.
+    '';
+    homepage = "https://www.gtk.org/";
+    license = licenses.lgpl2Plus;
+    maintainers = with maintainers; [ raskin vcunat lethalman worldofpeace ];
+    platforms = platforms.all;
+    changelog = "https://gitlab.gnome.org/GNOME/gtk/-/raw/${version}/NEWS";
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/gtk/hooks/drop-icon-theme-cache.sh b/nixpkgs/pkgs/development/libraries/gtk/hooks/drop-icon-theme-cache.sh
new file mode 100644
index 000000000000..f28a856c4f50
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/hooks/drop-icon-theme-cache.sh
@@ -0,0 +1,19 @@
+# shellcheck shell=bash
+
+# Packages often run gtk-update-icon-cache to include their icons in themes’ icon cache.
+# However, since each package is installed to its own prefix, the files will only collide.
+dropIconThemeCache() {
+    if [[ -z "${dontDropIconThemeCache:-}" ]]; then
+        local icondir="${out:?}/share/icons"
+        if [[ -d "${icondir}" ]]; then
+            # App icons are supposed to go to hicolor theme, since it is a fallback theme as per [icon-theme-spec], but some might still choose to install stylized icons to other themes.
+            find "${icondir}" -name 'icon-theme.cache' -print0 \
+              | while IFS= read -r -d '' file; do
+                echo "Removing ${file}"
+                rm -f "${file}"
+            done
+        fi
+    fi
+}
+
+preFixupPhases="${preFixupPhases-} dropIconThemeCache"
diff --git a/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk2-clean-immodules-cache.sh b/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk2-clean-immodules-cache.sh
new file mode 100644
index 000000000000..dde991fd27cd
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk2-clean-immodules-cache.sh
@@ -0,0 +1,12 @@
+# shellcheck shell=bash
+
+fixupOutputHooks+=(_gtk2CleanComments)
+
+# Clean comments that link to generator of the file
+_gtk2CleanComments() {
+    local f="${prefix:?}/lib/gtk-2.0/2.10.0/immodules.cache"
+    if [ -f "$f" ]; then
+        sed 's|Created by .*bin/gtk-query-|Created by bin/gtk-query-|' -i "$f"
+    fi
+}
+
diff --git a/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk3-clean-immodules-cache.sh b/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk3-clean-immodules-cache.sh
new file mode 100644
index 000000000000..d2d5287831a0
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk3-clean-immodules-cache.sh
@@ -0,0 +1,11 @@
+# shellcheck shell=bash
+
+fixupOutputHooks+=(_gtk3CleanComments)
+
+# Clean comments that link to generator of the file
+_gtk3CleanComments() {
+    local f="${prefix:?}/lib/gtk-3.0/3.0.0/immodules.cache"
+    if [ -f "$f" ]; then
+        sed 's|Created by .*bin/gtk-query-|Created by bin/gtk-query-|' -i "$f"
+    fi
+}
diff --git a/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk4-clean-immodules-cache.sh b/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk4-clean-immodules-cache.sh
new file mode 100644
index 000000000000..49f7051aabb6
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/hooks/gtk4-clean-immodules-cache.sh
@@ -0,0 +1,11 @@
+# shellcheck shell=bash
+
+fixupOutputHooks+=(_gtk4CleanComments)
+
+# Clean comments that link to generator of the file
+_gtk4CleanComments() {
+    local f="${prefix:?}/lib/gtk-4.0/4.0.0/immodules.cache"
+    if [ -f "$f" ]; then
+        sed 's|Created by .*bin/gtk-query-|Created by bin/gtk-query-|' -i "$f"
+    fi
+}
diff --git a/nixpkgs/pkgs/development/libraries/gtk/patches/2.0-darwin-x11.patch b/nixpkgs/pkgs/development/libraries/gtk/patches/2.0-darwin-x11.patch
new file mode 100644
index 000000000000..9725cfb84260
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/patches/2.0-darwin-x11.patch
@@ -0,0 +1,22 @@
+--- a/gdk/x11/gdkapplaunchcontext-x11.c
++++ b/gdk/x11/gdkapplaunchcontext-x11.c
+@@ -26,7 +26,6 @@
+ #include <unistd.h>
+ 
+ #include <glib.h>
+-#include <gio/gdesktopappinfo.h>
+ 
+ #include "gdkx.h"
+ #include "gdkapplaunchcontext.h"
+@@ -363,10 +362,7 @@
+   else
+     workspace_str = NULL;
+ 
+-  if (G_IS_DESKTOP_APP_INFO (info))
+-    application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info));
+-  else
+-    application_id = NULL;
++  application_id = NULL;
+ 
+   startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
+                                 g_get_prgname (),
diff --git a/nixpkgs/pkgs/development/libraries/gtk/patches/2.0-immodules.cache.patch b/nixpkgs/pkgs/development/libraries/gtk/patches/2.0-immodules.cache.patch
new file mode 100644
index 000000000000..1b8231756e71
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/patches/2.0-immodules.cache.patch
@@ -0,0 +1,27 @@
+--- a/gtk/gtkrc.c	2014-09-30 05:02:17.000000000 +0900
++++ b/gtk/gtkrc.c	2016-04-09 17:39:51.363288355 +0900
+@@ -445,5 +445,23 @@
+   if (var)
+     result = g_strdup (var);
+ 
++  // check NIX_PROFILES paths.
++  const gchar *nixProfilesEnv = g_getenv ("NIX_PROFILES");
++  gchar *cachePath;
++  guint i;
++
++  if(nixProfilesEnv && !result){
++    gchar **paths = g_strsplit(nixProfilesEnv, " ", -1);
++    for (i = 0; paths[i] != NULL; i++){
++      cachePath = g_build_filename(paths[i], "etc", "gtk-2.0", "immodules.cache", NULL);
++      if( g_file_test( cachePath, G_FILE_TEST_EXISTS) ){
++        if(result) g_free(result);
++        result = g_strdup(cachePath);
++      }
++      g_free(cachePath);
++    }
++    g_strfreev(paths);
++  }
++
+   if (!result)
+     {
+
diff --git a/nixpkgs/pkgs/development/libraries/gtk/patches/3.0-darwin-x11.patch b/nixpkgs/pkgs/development/libraries/gtk/patches/3.0-darwin-x11.patch
new file mode 100644
index 000000000000..86631634b5bd
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/patches/3.0-darwin-x11.patch
@@ -0,0 +1,28 @@
+--- a/gdk/x11/gdkapplaunchcontext-x11.c
++++ b/gdk/x11/gdkapplaunchcontext-x11.c
+@@ -27,7 +27,9 @@
+ #include "gdkprivate-x11.h"
+ 
+ #include <glib.h>
++#if defined(HAVE_GIO_UNIX) && !defined(__APPLE__)
+ #include <gio/gdesktopappinfo.h>
++#endif
+ 
+ #include <string.h>
+ #include <unistd.h>
+@@ -352,10 +354,15 @@
+   else
+     workspace_str = NULL;
+ 
++#if defined(HAVE_GIO_UNIX) && !defined(__APPLE__)
+   if (G_IS_DESKTOP_APP_INFO (info))
+     application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info));
+   else
+     application_id = NULL;
++#else
++  application_id = NULL;
++#warning Please add support for creating AppInfo from id for your OS
++#endif
+ 
+   startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
+                                 g_get_prgname (),
diff --git a/nixpkgs/pkgs/development/libraries/gtk/patches/3.0-immodules.cache.patch b/nixpkgs/pkgs/development/libraries/gtk/patches/3.0-immodules.cache.patch
new file mode 100644
index 000000000000..bbe5f28dbd3e
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/patches/3.0-immodules.cache.patch
@@ -0,0 +1,27 @@
+--- a/gtk/deprecated/gtkrc.c	2016-04-02 18:43:08.401663112 +0900
++++ b/gtk/deprecated/gtkrc.c	2016-04-02 18:29:19.927608592 +0900
+@@ -774,5 +774,23 @@
+   if (var)
+     result = g_strdup (var);
+ 
++  // check NIX_PROFILES paths.
++  const gchar *nixProfilesEnv = g_getenv ("NIX_PROFILES");
++  gchar *cachePath;
++  guint i;
++
++  if(nixProfilesEnv && !result){
++    gchar **paths = g_strsplit(nixProfilesEnv, " ", -1);
++    for (i = 0; paths[i] != NULL; i++){
++      cachePath = g_build_filename(paths[i], "etc", "gtk-3.0", "immodules.cache", NULL);
++      if( g_file_test( cachePath, G_FILE_TEST_EXISTS) ){
++        if(result) g_free(result);
++        result = g_strdup(cachePath);
++      }
++      g_free(cachePath);
++    }
++    g_strfreev(paths);
++  }
++
+   if (!result)
+     {
+ 
diff --git a/nixpkgs/pkgs/development/libraries/gtk/patches/gtk2-theme-paths.patch b/nixpkgs/pkgs/development/libraries/gtk/patches/gtk2-theme-paths.patch
new file mode 100644
index 000000000000..edd69b078076
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/gtk/patches/gtk2-theme-paths.patch
@@ -0,0 +1,40 @@
+Subject: [PATCHv2] gtk: Patch GTK+ to look for themes in profiles.
+To: guix-devel@gnu.org
+Date: Sun, 13 Mar 2016 15:17:37 +1100
+Url: https://lists.gnu.org/archive/html/guix-devel/2016-03/msg00492.html
+
+diff -Naur gtk+-2.24.28.new/gtk/gtkrc.c gtk+-2.24.28/gtk/gtkrc.c
+--- gtk+-2.24.28.new/gtk/gtkrc.c	2016-03-13 10:31:14.413644362 +1100
++++ gtk+-2.24.28/gtk/gtkrc.c	2016-03-13 12:51:34.723398423 +1100
+@@ -808,6 +808,8 @@
+   gchar *path = NULL;
+   const gchar *home_dir;
+   gchar *subpath;
++  const gchar * const *xdg_data_dirs;
++  gint i;
+ 
+   if (type)
+     subpath = g_strconcat ("gtk-2.0-", type,
+@@ -830,6 +832,22 @@
+     }
+ 
+   if (!path)
++    {
++      xdg_data_dirs = g_get_system_data_dirs ();
++      for (i = 0; xdg_data_dirs[i]; i++)
++        {
++          path = g_build_filename (xdg_data_dirs[i], "themes", name, subpath, NULL);
++          if (g_file_test (path, G_FILE_TEST_EXISTS))
++            break;
++          else
++            {
++              g_free (path);
++              path = NULL;
++            }
++        }
++    }
++
++  if (!path)
+     {
+       gchar *theme_dir = gtk_rc_get_theme_dir ();
+       path = g_build_filename (theme_dir, name, subpath, NULL);