gnome-shell-system-monitor-applet icon indicating copy to clipboard operation
gnome-shell-system-monitor-applet copied to clipboard

[NixOS] Requiring GTop, version none: Typelib file for namespace 'GTop' (any version) not found

Open kropochev opened this issue 1 year ago • 7 comments

Ubuntu 23.10 Gnome 45.1

After install extension from https://extensions.gnome.org/extension/3010/system-monitor-next/ getting error:

Screenshot from 2023-11-30 21-17-39

$ sudo apt install gir1.2-gtop-2.0 gir1.2-nm-1.0 gir1.2-clutter-1.0 gnome-system-monitor
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gir1.2-gtop-2.0 is already the newest version (2.40.0-2build3).
gir1.2-nm-1.0 is already the newest version (1.44.2-1ubuntu1.2).
gir1.2-clutter-1.0 is already the newest version (1.26.4+git2779b932+dfsg-5).
gnome-system-monitor is already the newest version (45.0.2-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

kropochev avatar Nov 30 '23 16:11 kropochev

Also getting this on NixOS 24.05 beta.

amsam0 avatar Dec 01 '23 17:12 amsam0

I solved this problem by rebooting the PC.

kropochev avatar Dec 01 '23 17:12 kropochev

Tried installing libgtop and restarting my machine, no success. Will try installing gtop itself now

amsam0 avatar Dec 01 '23 17:12 amsam0

Wasn't able to fix this, but the Vitals extension worked just fine as a replacement.

amsam0 avatar Dec 01 '23 17:12 amsam0

@naturecodevoid I did a quick search of NixOS packages and wasn't able to find any gir1.2 libgtop packages. I guess we'd need to provide a fallback when not installed (which must be what Vitals is doing).

I'm tempted to close this but will leave it open in case anyone else wants to vote for NixOS support.

mgalgs avatar Dec 14 '23 04:12 mgalgs

Yes, I agree. NixOS does not seem to have any gir binding packages.

amsam0 avatar Dec 15 '23 00:12 amsam0

Added [NixOS] to the title. If anyone on Nix gets the extension working (I assume a gir bindings package will land in Nix at some point) please drop a comment!

mgalgs avatar Mar 26 '24 17:03 mgalgs

Human error - read UPD4

The issue is probably already resolved downstream

Original text follows

There's working extension in binary cache (nixpkgs 7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856), but I can't replicate local build - I get the same error then. I found that while trying to patch this extension.

See diff between derivation from binary cache and my patched derivation:

diff -r /nix/store/kal8grlbk152abhflqsr6agi873p0qfd-gnome-shell-extension-system-monitor-next-66/share/gnome-shell/extensions/[email protected]/extension.js /nix/store/67dqh8bd9ahmf2f5i50hx71f2j9vgi2b-gnome-shell-extension-system-monitor-next-66/share/gnome-shell/extensions/[email protected]/extension.js
24d23
< import GIRepository from "gi://GIRepository";
31a31
> import GTop from "gi://GTop";
42,44d41
< GIRepository.Repository.prepend_search_path('/nix/store/wfy3z72ybx253xf3xm1xwwypjy2bl42j-libgtop-2.41.2/lib/girepository-1.0');
< const GTop = (await import("gi://GTop")).default;
< 
2166c2163
<             let script = ['/bin/bash', path + '/gpu_usage.sh'];
---
>             let script = ['/usr/bin/env', 'bash', path + '/gpu_usage.sh'];

And that's my patch (you left hardcoded bin path, I found it and tried to fix, but alas)

--- a/extension.js
+++ b/extension.js
@@ -2161,7 +2161,7 @@ const Gpu = class SystemMonitor_Gpu extends ElementBase {
         // Run asynchronously, to avoid shell freeze
         try {
             let path = this.extension.path;
-            let script = ['/bin/bash', path + '/gpu_usage.sh'];
+            let script = ['/usr/bin/env', 'bash', path + '/gpu_usage.sh'];

             // Create subprocess and capture STDOUT
             let proc = new Gio.Subprocess({argv: script, flags: Gio.SubprocessFlags.STDOUT_PIPE});
NixOS related information

That's my derivation:

{gnomeExtensions}: gnomeExtensions.system-monitor-next.overrideAttrs {
  patches = [
    ./usr-bin-env.patch
  ];
}

And I assure you, I used the same nixpkgs (24.05.20240425.7bb2ccd) in both derivations:

  environment.systemPackages = with pkgs; [
    ...
#    gnomeExtensions.system-monitor-next
    (pkgs.callPackage ../../packages/system-monitor-next {})
    ...
  ];

I don't want to open source my flake for now (it has some "secret" information)

See const GTop = (await import("gi://GTop")).default;? I couldn't find it in this repo, but it somehow got to binary cache, and it fixes this error.

Also, it means the binary cache (default one, I believe it is cache.nixos.org) and e.g.o have different sources and somehow nix is sure that both have the same hash - looks like cache is damaged. Or it is my /nix/store, but my drive is in good condition and I did not mess with /nix/store by hand.

UPD: Hold on for a moment, I was trying to patch to test before sending PR but forgot that I can add new patch (the first diff in this message) to my derivation too. I'm testing this right now.

UPD2:

Actually, the fix is GIRepository.Repository.prepend_search_path call. So, this issue probably cannot be fixed in this repository and should be downstreamed.

I've got this patch to work (including GPU usage):

The patch, it's big
--- a/extension.js
+++ b/extension.js
@@ -21,6 +21,7 @@
 import { Extension, gettext as _ } from "resource:///org/gnome/shell/extensions/extension.js";

 import Clutter from "gi://Clutter";
+import GIRepository from "gi://GIRepository";
 import GLib from "gi://GLib";
 import GObject from "gi://GObject";

@@ -28,7 +29,6 @@ import Gio from "gi://Gio";
 import Shell from "gi://Shell";
 import St from "gi://St";
 import UPowerGlib from "gi://UPowerGlib";
-import GTop from "gi://GTop";
 import NM from "gi://NM";

 import * as ExtensionSystem from "resource:///org/gnome/shell/ui/extensionSystem.js";
@@ -39,6 +39,9 @@ import * as PopupMenu from "resource:///org/gnome/shell/ui/popupMenu.js";

 import * as Util from "resource:///org/gnome/shell/misc/util.js";

+GIRepository.Repository.prepend_search_path('/nix/store/wfy3z72ybx253xf3xm1xwwypjy2bl42j-libgtop-2.41.2/lib/girepository-1.0');
+const GTop = (await import("gi://GTop")).default;
+
 const NetworkManager = NM;
 const UPower = UPowerGlib;
 // Copied as of https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/5fa08fe53376f5dca755360bd005a4a51ca78917/js/ui/panel.js#L45
@@ -2161,7 +2164,7 @@ const Gpu = class SystemMonitor_Gpu extends ElementBase {
         // Run asynchronously, to avoid shell freeze
         try {
             let path = this.extension.path;
-            let script = ['/bin/bash', path + '/gpu_usage.sh'];
+            let script = ['/usr/bin/env', 'bash', path + '/gpu_usage.sh'];

             // Create subprocess and capture STDOUT
             let proc = new Gio.Subprocess({argv: script, flags: Gio.SubprocessFlags.STDOUT_PIPE});

The override is the same, or you can split this patch to two. It can be a temporary solution to this issue.

The problem is path to libgtop derivation. I'm going to figure out how to patch the patch with proper path or simply prepend search path without patching, but no guarantees here.

UPD3: Forget cache poisoning, this extension is actually patched downstream:

https://github.com/NixOS/nixpkgs/blob/58a1abdbae3217ca6b702f03d3b35125d88a2994/pkgs/desktops/gnome/extensions/extensionOverrides.nix#L126-L134


UPD4

I should have started with reading overrides. I overrode the patch above. What a shame. I don't know what's this issue then. If you want to debug this, try diff between source code and your actual extension, probably patch is not applied so it does not work.

Good news - I'm going to submit a PR with fixes for GPU.


UPD5: I re-read the issue and finally understood it. e.g.o doesn't have aforementioned patch, so on NixOS it does not work. Use nixpkgs for that, even home-manager should probably work.

HeroBrine1st avatar May 02 '24 18:05 HeroBrine1st

I got this to work accidentally, because of what https://github.com/AstraExt/astra-monitor said to do to get theirs to work.

    environment.systemPackages = with pkgs; [
        ....
       gnomeExtensions.system-monitor-next
       libgtop
       ....
    ];

   environment.variables = {
       GI_TYPELIB_PATH = "/run/current-system/sw/lib/girepository-1.0";
   };

After I did that and rebooted, system-monitor-next just popped up happy as you can be. :-)

JollyDevelopment avatar Jun 22 '24 22:06 JollyDevelopment