Python/gobject-introspection hell

Hi there :wave:

I’m trying to make my qtile package to reach Gdk stuff. And seems like I hit a wall.

Here is a part from my config:

import gi
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk

def get_monitors():
    monitors = []

    gdkdsp = Gdk.Display.get_default()
    for i in range(gdkdsp.get_n_monitors()):
        monitor = gdkdsp.get_monitor(i)
        scale = monitor.get_scale_factor()
        geo = monitor.get_geometry()
        allmonitors.append([
            monitor.get_model()] + [n * scale for n in [
                geo.x, geo.y, geo.width, geo.height
            ]
        ])

    return allmonitors

And when I have some nix-shell like this:

nix-shell -p python3Packages.pygobject3 -p gobjectIntrospection -p gtk3 --pure

This code works in the shell. But when I override the package and set these inside pythonPath like this:

  nixpkgs.config = {                               
    enable = true;                                                                                                                                          
    packageOverrides = pkgs: rec {                                                                     
      myQtile = pkgs.qtile.overrideAttrs  (_: {    
        pythonPath = with pkgs.python37Packages; [                                                     
          setuptools                                         
          xlib                                                          
          pyusb                                                       
          dbus-python    
          pygobject3                                                                                   
          pkgs.gobjectIntrospection                
          pkgs.gtk3                                
        ] ++ pkgs.qtile.pythonPath;                                                                    
      });                                                                                              
    };                                                                                                 
  };           

It doesn’t work. All other dependencies of the scripts are fine except GI stuff. Here is the error I get:

Traceback (most recent call last):
  File "/nix/store/k6mzrqj986x7m8zjm0myx1x37sjvgpmh-qtile-0.13.0/lib/python3.7/site-packages/libqtile/s
cripts/qtile.py", line 107, in make_qtile          
    config = confreader.Config.from_file(options.configfile)
  File "/nix/store/k6mzrqj986x7m8zjm0myx1x37sjvgpmh-qtile-0.13.0/lib/python3.7/site-packages/libqtile/c
onfreader.py", line 89, in from_file               
    raise ConfigError(tb) 
libqtile.confreader.ConfigError: Traceback (most recent call last):
  File "/nix/store/k6mzrqj986x7m8zjm0myx1x37sjvgpmh-qtile-0.13.0/lib/python3.7/site-packages/libqtile/c
onfreader.py", line 83, in from_file                                                                   
    config = __import__(os.path.basename(path)[:-3])                                   
  File "/home/gurkan/.config/qtile/config.py", line 30, in <module>
    gi.require_version("Gdk", "3.0")               
  File "/nix/store/bny83l5v5ky1kwzsxaf9c7ayqggdc45a-python3.7-pygobject-3.32.1/lib/python3.7/site-packa
ges/gi/__init__.py", line 129, in require_version  
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gdk not available

Shall I just create an override package instead? Any help would be appreciated :man_facepalming:

gobject-introspection needs to be in nativeBuildInputs and gtk3 in buildInputs. Also you will need to add wrapGAppsHook hook to nativeBuildInputs to pass the environment variables to the program (see GNOME section of the nixpkgs manual). You might also need to disable strictDeps see https://github.com/NixOS/nixpkgs/issues/56943

2 Likes

Ahh, that was it. Thanks! :tada: