Subject: [bug#75688] [PATCH 2/2] gnu: gdk-pixbuf: Respect GUIX_LIBRARY_PATH.

From: [email-masked]
Date: Mon, 20 Jan 2025 20:06:51 +0800

From: 宋文武 <[email-masked]>

This fixes <https://issues.guix.gnu.org/75523>.

* gnu/packages/patches/gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/gtk.scm (gdk-pixbuf)[source]: Apply patch.
[native-search-paths]: Remove GDK_PIXBUF_MODULE_FILE.

Change-Id: I109565e5f506b9335856143f68abe164aff3cd26
---
 gnu/local.mk                                  |  1 +
 gnu/packages/gtk.scm                          | 12 ++----
 ...gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch | 42 +++++++++++++++++++
 3 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 gnu/packages/patches/gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index e06a605712..133512d613 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1400,6 +1400,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/gd-fix-tests-on-i686.patch		\
   %D%/packages/patches/gd-brect-bounds.patch			\
   %D%/packages/patches/gdb-hurd64.patch				\
+  %D%/packages/patches/gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch	\
   %D%/packages/patches/gdm-default-session.patch		\
   %D%/packages/patches/gdm-elogind-support.patch		\
   %D%/packages/patches/gdm-remove-hardcoded-xwayland-path.patch	\
diff --git a/gnu/packages/gtk.scm b/gnu/packages/gtk.scm
index 7ed7d7b7df..4a4069d495 100644
--- a/gnu/packages/gtk.scm
+++ b/gnu/packages/gtk.scm
@@ -726,7 +726,9 @@ (define-public gdk-pixbuf
                                   name "-" version ".tar.xz"))
               (sha256
                (base32
-                "0jz4kziz5lirnjjvbspbqzsigk8vnqknng1fga89d81vs5snr6zf"))))
+                "0jz4kziz5lirnjjvbspbqzsigk8vnqknng1fga89d81vs5snr6zf"))
+              (patches
+               (search-patches "gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch"))))
     (build-system meson-build-system)
     (outputs '("out" "debug"))
     (arguments
@@ -773,14 +775,6 @@ (define-public gdk-pixbuf
            ;; For the documentation.
            gi-docgen
            python-docutils))
-    (native-search-paths
-     ;; This file is produced by the gdk-pixbuf-loaders-cache-file
-     ;; profile hook.
-     (list (search-path-specification
-            (variable "GDK_PIXBUF_MODULE_FILE")
-            (files (list %gdk-pixbuf-loaders-cache-file))
-            (separator #f)              ;single valued
-            (file-type 'regular))))
     (synopsis "Image loading library")
     (description "GdkPixbuf is a library that loads image data in various
 formats and stores it as linear buffers in memory.  The buffers can then be
diff --git a/gnu/packages/patches/gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch b/gnu/packages/patches/gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch
new file mode 100644
index 0000000000..3ec7bc28ab
--- /dev/null
+++ b/gnu/packages/patches/gdk-pixbuf-respect-GUIX_LIBRARY_PATH.patch
@@ -0,0 +1,42 @@
+diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
+index e1df590..e553eba 100644
+--- a/gdk-pixbuf/gdk-pixbuf-io.c
++++ b/gdk-pixbuf/gdk-pixbuf-io.c
+@@ -663,6 +663,19 @@ gdk_pixbuf_io_init_builtin (void)
+ #undef load_one_builtin_module
+ }
+ 
++
++static gchar **
++build_guix_library_path (void)
++{
++        gchar **dirs = NULL;
++        gchar *library_path = g_strdup (g_getenv ("GUIX_LIBRARY_PATH"));
++        if (!library_path || !library_path[0])
++            library_path = g_build_filename (g_get_home_dir (), ".guix-profile", "lib", NULL);
++        dirs = g_strsplit (library_path, G_SEARCHPATH_SEPARATOR_S, 0);
++        g_free (library_path);
++        return dirs;
++}
++
+ static gboolean
+ gdk_pixbuf_io_init (void)
+ {
+@@ -670,6 +683,17 @@ gdk_pixbuf_io_init (void)
+ 	gboolean ret;
+ 
+ 	gdk_pixbuf_io_init_builtin ();
++
++	/* Load loaders from GUIX_LIBRARY_PATH */
++	gchar **guix_libdirs = build_guix_library_path ();
++	for (gsize i = 0; guix_libdirs[i] != NULL; i++) {
++	    module_file = g_build_filename (guix_libdirs[i], "gdk-pixbuf-2.0",
++                                            GDK_PIXBUF_BINARY_VERSION, "loaders.cache", NULL);
++	    gdk_pixbuf_io_init_modules (module_file, NULL);
++	    g_free (module_file);
++	}
++	g_strfreev (guix_libdirs);
++
+ #ifdef USE_GMODULE
+ 	module_file = gdk_pixbuf_get_module_file ();
+ #endif
-- 
2.47.1