Subject: [bug#77780] [PATCH] gnu: gpaste: version bump + fix build

From: Grigory Shepelev <[email-masked]>
Date: Sat, 12 Apr 2025 07:26:15 +0300

Bumped version + completely copied build from Nixpkgs.

Change-Id: I8506dcb11617f82cbbf4dbe446f37ec0b91083a1
---
 gnu/packages/aux-files/gpaste/wrapper.js    |  5 +++
 gnu/packages/gnome-xyz.scm                  | 37 +++++++++++++++++----
 gnu/packages/patches/gpaste-fix-paths.patch | 35 ++-----------------
 3 files changed, 38 insertions(+), 39 deletions(-)
 create mode 100644 gnu/packages/aux-files/gpaste/wrapper.js

diff --git a/gnu/packages/aux-files/gpaste/wrapper.js b/gnu/packages/aux-files/gpaste/wrapper.js
new file mode 100644
index 0000000000..ea6a9cba6f
--- /dev/null
+++ b/gnu/packages/aux-files/gpaste/wrapper.js
@@ -0,0 +1,5 @@
+import GIRepository from 'gi://GIRepository';
+
+GIRepository.Repository.prepend_search_path('@typelibDir@');
+
+export default (await import('./.@[email-masked]')).default;
diff --git a/gnu/packages/gnome-xyz.scm b/gnu/packages/gnome-xyz.scm
index 8e2ffb49cb..a41033df70 100644
--- a/gnu/packages/gnome-xyz.scm
+++ b/gnu/packages/gnome-xyz.scm
@@ -1045,7 +1045,7 @@ (define-public gnome-shell-extension-night-theme-switcher
 (define-public gpaste
   (package
     (name "gpaste")
-    (version "44.1")
+    (version "45.2")
     (source (origin
               (method git-fetch)
               (uri (git-reference
@@ -1054,7 +1054,7 @@ (define-public gpaste
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "1amfr8hwf7401xa3fzaa8w17w3v3lxx0fkr7rqkkyfy57iavrykk"))
+                "1x8rqxqzggvzs0hr9hkwq9gmzn1m16jwllml4m4bxrdib4c9lh8q"))
               (patches
                (search-patches "gpaste-fix-paths.patch"))))
     (build-system meson-build-system)
@@ -1088,11 +1088,34 @@ (define-public gpaste
                  (lambda _
                    (substitute* "src/libgpaste/gpaste/gpaste-settings.c"
                      (("@gschemasCompiled@")
-                      (string-append #$output "/share/glib-2.0/schemas/")))
-                   (substitute* '("src/gnome-shell/extension.js"
-                                  "src/gnome-shell/prefs.js")
-                     (("@typelibPath@")
-                      (string-append #$output "/lib/girepository-1.0/"))))))))
+                      (string-append #$output "/share/glib-2.0/schemas/")))))
+               (add-after 'install 'wrap-typelib
+                 ;; absolute copy from nixpkgs
+                 ;; https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/gp/gpaste/package.nix#L67
+                 (lambda _
+                   (let* [(extension-dir
+                           (string-append
+                            #$output
+                            "/share"
+                            "/gnome-shell"
+                            "/extensions"
+                            "/[email-masked]"))
+                          (extension.js (string-append extension-dir "/extension.js"))
+                          (extension-wrapped.js (string-append extension-dir "/.extension-wrapped.js"))
+                          (prefs.js (string-append extension-dir "/prefs.js"))
+                          (prefs-wrapped.js (string-append extension-dir "/.prefs-wrapped.js"))
+                          (wrapper.js #$(local-file (search-auxiliary-file "gpaste/wrapper.js")))
+                          (typelibdir (string-append #$output "/lib/girepository-1.0"))]
+                     (rename-file extension.js extension-wrapped.js)
+                     (rename-file prefs.js prefs-wrapped.js)
+                     (copy-file wrapper.js extension.js)
+                     (copy-file wrapper.js prefs.js)
+                     (substitute* extension.js
+                       (("@originalName@") "extension")
+                       (("@typelibDir@") typelibdir))
+                     (substitute* prefs.js
+                       (("@originalName@") "prefs")
+                       (("@typelibDir@") typelibdir))))))))
     (home-page "https://github.com/Keruspe/GPaste")
     (synopsis "Clipboard management system for GNOME Shell")
     (description "GPaste is a clipboard manager, a tool which allows you to
diff --git a/gnu/packages/patches/gpaste-fix-paths.patch b/gnu/packages/patches/gpaste-fix-paths.patch
index bacecd61a9..ebebc8a20b 100644
--- a/gnu/packages/patches/gpaste-fix-paths.patch
+++ b/gnu/packages/patches/gpaste-fix-paths.patch
@@ -1,44 +1,15 @@
-This is copied from NixOS, which is under MIT licence.
-https://github.com/NixOS/nixpkgs/blob/master/pkgs/desktops/gnome/misc/gpaste/
-diff --git a/src/gnome-shell/extension.js b/src/gnome-shell/extension.js
-index c8773fd6..9efbed67 100644
---- a/src/gnome-shell/extension.js
-+++ b/src/gnome-shell/extension.js
-@@ -6,6 +6,8 @@
-
- const Config = imports.misc.config;
-
-+imports.gi.GIRepository.Repository.prepend_search_path('@typelibPath@');
-+
- imports.gi.versions.Clutter = Config.LIBMUTTER_API_VERSION;
- imports.gi.versions.GLib = '2.0';
- imports.gi.versions.GPaste = '2';
-diff --git a/src/gnome-shell/prefs.js b/src/gnome-shell/prefs.js
-index 32244ab2..74b85572 100644
---- a/src/gnome-shell/prefs.js
-+++ b/src/gnome-shell/prefs.js
-@@ -6,6 +6,8 @@
-
- imports.gi.versions.GPasteGtk = '4';
-
-+imports.gi.GIRepository.Repository.prepend_search_path('@typelibPath@');
-+
- const ExtensionUtils = imports.misc.extensionUtils;
-
- const { GPasteGtk } = imports.gi;
 diff --git a/src/libgpaste/gpaste/gpaste-settings.c b/src/libgpaste/gpaste/gpaste-settings.c
-index 7e53eb64..57c399fc 100644
+index 830f5e0b..c8df0e11 100644
 --- a/src/libgpaste/gpaste/gpaste-settings.c
 +++ b/src/libgpaste/gpaste/gpaste-settings.c
-@@ -1013,7 +1013,11 @@ create_g_settings (void)
+@@ -1039,7 +1039,10 @@ create_g_settings (void)
      }
      else
      {
 -        return g_settings_new (G_PASTE_SETTINGS_NAME);
 +        // library used by introspection requires schemas but we cannot set XDG_DATA_DIRS for the library
-+        GSettingsSchemaSource *schema_source = g_settings_schema_source_new_from_directory ("@gschemasCompiled@", NULL, FALSE, NULL);
++        g_autoptr (GSettingsSchemaSource) schema_source = g_settings_schema_source_new_from_directory ("@gschemasCompiled@", NULL, FALSE, NULL);
 +        g_autoptr (GSettingsSchema) schema = g_settings_schema_source_lookup (schema_source, G_PASTE_SETTINGS_NAME, FALSE);
-+        g_settings_schema_source_unref (schema_source);
 +        return g_settings_new_full (schema, NULL, NULL);
      }
  }
--
2.48.1