From 1f79b943c0543b8044441cf41a25ea54ed49d6cc Mon Sep 17 00:00:00 2001
From: Jan Tojnar <jtojnar@gmail.com>
Date: Wed, 15 Nov 2017 03:36:35 +0100
Subject: [PATCH 1/2] glib: recognize NIX_GSETTINGS_OVERRIDES_DIR variable

For some reason, the GNOME 3.26 update broke the overrides. It turns
out the overrides now need to come before the overriden schemas in the
XDG_DATA_DIRS variable. This is not possible in general due to applications
prefixing the variable (e.g. in wrapGAppsHook).

To fix this, a new environment variable NIX_GSETTINGS_OVERRIDES_DIR
was introduced. It has greater priority than XDG_DATA_DIRS but lower
than GSETTINGS_SCHEMA_DIR. A separate variable was chosen in order not
to block the built-in one for users.
---
 pkgs/development/libraries/glib/default.nix          |  3 ++-
 .../libraries/glib/schema-override-variable.patch    | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 pkgs/development/libraries/glib/schema-override-variable.patch

diff --git a/pkgs/development/libraries/glib/default.nix b/pkgs/development/libraries/glib/default.nix
index b82fd5f1e299..e270cd5ea7ba 100644
--- a/pkgs/development/libraries/glib/default.nix
+++ b/pkgs/development/libraries/glib/default.nix
@@ -55,7 +55,8 @@ stdenv.mkDerivation rec {
   };
 
   patches = optional stdenv.isDarwin ./darwin-compilation.patch
-    ++ optional doCheck ./skip-timer-test.patch;
+    ++ optional doCheck ./skip-timer-test.patch
+    ++ [ ./schema-override-variable.patch ];
 
   outputs = [ "out" "dev" "devdoc" ];
   outputBin = "dev";
diff --git a/pkgs/development/libraries/glib/schema-override-variable.patch b/pkgs/development/libraries/glib/schema-override-variable.patch
new file mode 100644
index 000000000000..1cb5a730351b
--- /dev/null
+++ b/pkgs/development/libraries/glib/schema-override-variable.patch
@@ -0,0 +1,12 @@
+--- a/gio/gsettingsschema.c
++++ b/gio/gsettingsschema.c
+@@ -352,6 +352,9 @@
+ 
+       try_prepend_data_dir (g_get_user_data_dir ());
+ 
++      if ((path = g_getenv ("NIX_GSETTINGS_OVERRIDES_DIR")) != NULL)
++        try_prepend_dir (path);
++
+       if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL)
+         try_prepend_dir (path);
+ 

From 510737cca7ef7a15c1b570150bbae71929be6e01 Mon Sep 17 00:00:00 2001
From: Jan Tojnar <jtojnar@gmail.com>
Date: Wed, 15 Nov 2017 03:38:20 +0100
Subject: [PATCH 2/2] nixos/gnome3: override schemas using env variable

For some reason, the GNOME 3.26 update broke the overrides. It turns
out the overrides now need to come before the overriden schemas in the
XDG_DATA_DIRS variable. This is not possible in general due to applications
prefixing the variable (e.g. in wrapGAppsHook).

To fix this, a new environment variable NIX_GSETTINGS_OVERRIDES_DIR
was introduced. It has greater priority than XDG_DATA_DIRS but lower
than GSETTINGS_SCHEMA_DIR. A separate variable was chosen in order not
to block the built-in one for users.
---
 nixos/modules/services/x11/desktop-managers/gnome3.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nixos/modules/services/x11/desktop-managers/gnome3.nix b/nixos/modules/services/x11/desktop-managers/gnome3.nix
index ecf0abb1efd2..cbb06b471093 100644
--- a/nixos/modules/services/x11/desktop-managers/gnome3.nix
+++ b/nixos/modules/services/x11/desktop-managers/gnome3.nix
@@ -150,7 +150,7 @@ in {
           export XDG_DATA_DIRS=$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${mimeAppsList}/share
 
           # Override gsettings-desktop-schema
-          export XDG_DATA_DIRS=${nixos-gsettings-desktop-schemas}/share/gsettings-schemas/nixos-gsettings-overrides''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS
+          export NIX_GSETTINGS_OVERRIDES_DIR=${nixos-gsettings-desktop-schemas}/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas
 
           # Let nautilus find extensions
           export NAUTILUS_EXTENSION_DIR=${config.system.path}/lib/nautilus/extensions-3.0/