gnome.gpaste: Fix typelib path adjustment

I attempted to fix this in af9e3ddc1d
but it looks like my mental model of module loader was incorrect so the fix there was insufficient.
Therefore the only option appears to be using a top-level await with a dynamic import.
To avoid having to figure out which imports need to be dynamicized, we just wrap the whole entrypoints.
This commit is contained in:
Jan Tojnar
2023-12-08 23:24:55 +01:00
parent 2c7f3c0fb7
commit e75decf46b
3 changed files with 19 additions and 49 deletions
+14 -4
View File
@@ -35,10 +35,6 @@ stdenv.mkDerivation rec {
# TODO: switch to substituteAll with placeholder
# https://github.com/NixOS/nix/issues/1846
postPatch = ''
substituteInPlace src/gnome-shell/extension.js \
--subst-var-by typelibPath "${placeholder "out"}/lib/girepository-1.0"
substituteInPlace src/gnome-shell/prefs.js \
--subst-var-by typelibPath "${placeholder "out"}/lib/girepository-1.0"
substituteInPlace src/libgpaste/gpaste/gpaste-settings.c \
--subst-var-by gschemasCompiled ${glib.makeSchemaPath (placeholder "out") "${pname}-${version}"}
'';
@@ -69,6 +65,20 @@ stdenv.mkDerivation rec {
"-Dsystemd-user-unit-dir=${placeholder "out"}/etc/systemd/user"
];
postInstall = ''
# We do not have central location to install typelibs to,
# lets ensure GNOME Shell can still find them.
extensionDir="$out/share/gnome-shell/extensions/GPaste@gnome-shell-extensions.gnome.org"
mv "$extensionDir/"{extension,.extension-wrapped}.js
mv "$extensionDir/"{prefs,.prefs-wrapped}.js
substitute "${./wrapper.js}" "$extensionDir/extension.js" \
--subst-var-by originalName "extension" \
--subst-var-by typelibPath "${placeholder "out"}/lib/girepository-1.0"
substitute "${./wrapper.js}" "$extensionDir/prefs.js" \
--subst-var-by originalName "prefs" \
--subst-var-by typelibPath "${placeholder "out"}/lib/girepository-1.0"
'';
meta = with lib; {
homepage = "https://github.com/Keruspe/GPaste";
description = "Clipboard management system with GNOME 3 integration";
@@ -1,48 +1,3 @@
diff --git a/src/gnome-shell/__nix-prepend-search-paths.js b/src/gnome-shell/__nix-prepend-search-paths.js
new file mode 100644
index 00000000..e8e20c67
--- /dev/null
+++ b/src/gnome-shell/__nix-prepend-search-paths.js
@@ -0,0 +1,3 @@
+import GIRepository from 'gi://GIRepository';
+
+GIRepository.Repository.prepend_search_path('@typelibDir@');
diff --git a/src/gnome-shell/extension.js b/src/gnome-shell/extension.js
index cb862a30..980767c9 100644
--- a/src/gnome-shell/extension.js
+++ b/src/gnome-shell/extension.js
@@ -4,6 +4,8 @@
* Copyright (c) 2010-2023, Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
*/
+import './__nix-prepend-search-paths.js';
+
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
diff --git a/src/gnome-shell/meson.build b/src/gnome-shell/meson.build
index 86cbb0b2..80fc4d67 100644
--- a/src/gnome-shell/meson.build
+++ b/src/gnome-shell/meson.build
@@ -1,4 +1,5 @@
shell_extension_files = [
+ '__nix-prepend-search-paths.js',
'aboutItem.js',
'actionButton.js',
'actionButtonActor.js',
diff --git a/src/gnome-shell/prefs.js b/src/gnome-shell/prefs.js
index 4c0d9bde..58f54f9a 100644
--- a/src/gnome-shell/prefs.js
+++ b/src/gnome-shell/prefs.js
@@ -4,6 +4,8 @@
* Copyright (c) 2010-2023, Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
*/
+import './__nix-prepend-search-paths.js';
+
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import GPasteGtk from 'gi://GPasteGtk?version=4';
diff --git a/src/libgpaste/gpaste/gpaste-settings.c b/src/libgpaste/gpaste/gpaste-settings.c
index 830f5e0b..c8df0e11 100644
--- a/src/libgpaste/gpaste/gpaste-settings.c
@@ -0,0 +1,5 @@
import GIRepository from 'gi://GIRepository';
GIRepository.Repository.prepend_search_path('@typelibDir@');
export default (await import('./.@originalName@-wrapped.js')).default;