No module named 'gi'

Hello, I am trying to package a GNOME app for NixOS, this is my package .nix:

{ lib,
  fetchFromGitHub,
  stdenv,
  meson,
  gettext,
  blueprint-compiler,
  python3,
  gtk4,
  cmake,
  pkg-config,
  desktop-file-utils,
  ninja,
  libadwaita,
  wrapGAppsHook3,
  gobject-introspection,
  glib
}:

stdenv.mkDerivation rec {
  pname = "high-tide";
  version = "0.1.0";

  src = fetchFromGitHub {
    owner = "Nokse22";
    repo = pname;
    rev = "e95312f";
    hash = "sha256-ZYbeBOs9eOtV18WScwaPAs/pAVPKc+GXceQRi9V6zww=";
  };

  buildInputs = with python3.pkgs; [ pycairo pygobject3 ] ++ [ python3 ];

  nativeBuildInputs = [
    meson
    cmake
    desktop-file-utils
    ninja
    glib
    gettext
    blueprint-compiler
    wrapGAppsHook3
    gobject-introspection
    pkg-config
    gtk4
    libadwaita
  ];

  meta = {
    description = "Linux client for TIDAL streaming service ";
    homepage = "https://github.com/Nokse22/high-tide";
    source = "https://github.com/Nokse22/high-tide";
    license = lib.licenses.gpl3;
    maintainers = with lib.maintainers; [ totaltax ];
    platforms = lib.platforms.linux;
  };
}

However no matter what I do (I have looked at the other help posts) I still get this when attempting to run the program:

Traceback (most recent call last):
  File "/nix/store/22wrc3sgy2bhhxvp0acz71n4wwy0sla2-high-tide-0.1.0/bin/.HighTide-wrapped", line 39, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

May not solve your issue, but you’re using gtk4 for the build, perhaps wrapGAppsHook4 would work better instead of 3?

That is provided by the pygobject3 Python package.

However, just adding something to buildInputs on its own does nothing to ensure the dependencies are actually available at runtime. The builder is responsible for that. stdenv.mkDerivation can do that for ELF libraries but, in the case of Python libraries, you need e.g. buildPythonApplication or manually adding the PYTHONPATH environment variable to the wrapper.

Thanks, I was able to use python3.withPackages (pypkgs: with pypkgs; [ pygobject3 ];). I don’t think I can use buildPythonApplication because this specific package is meant to be built by GNOME builder and does not have a setup.py

That works too.

Though, you can use buildPythonApplication with pyproject = false, and it will use the standard build logic. But you will want to handle double wrapping then.