REUPLOAD: PyGObject NM (NetworkManager?) not found/available inside container.

I’m trying to get the device’s network info inside a container running on balenaOS 2.94.4 (supervisor version 14.3.3) on a Raspberry Pi Compute Module 4 using PyGObject (using Python 3.9.2). I’ve been using these examples, which are also mentioned in this video (I followed along to satisfy other dependencies/prerequisites, listed below).

In order to get this working, there are a few things that need be done:

  1. docker-compose.yml:
    set network-mode: "host"
    add the following label: io.balena.features.dbus: '1'
    (optional?) add:

the container already had privileged: true, so in this case the cap_add shouldn’t make a difference
add following environment variable: DBUS_SYSTEM_BUS_ADDRESS: "unix:path=/host/run/dbus/system_bus_socket"

  1. add dependencies, I’ve tried both ways, but they both don’t seem to work properly (see later)
    2.1. install network-manager package in the desired container, this allows for the usage of the nmcli command, which does work for me and shows the correct info. The network-manager should also include libnm, although I’m not entirely sure of this. (In these docs the same implementation is used as in the examples linked above, as well as in the next section.)

In both cases (point 2), here’s what I get:

  • import gi
    → no problem
  • gi.require_version('NM', '1.0') (I’m assuming NM stands for NetworkManager?)
    ValueError: Namespace NM not available
  • from gi.repository import NM
    ImportError: cannot import name NM, introspection typelib not found

Off course I’ve tried searching for these errors online, but documentation/information seems extremely sparse.
Running this inside docker on my local machine, or using balena push to push it to my device (local mode enabled for testing), these errors occur.
When I run this in a virtual environment (using Python 3.9.10) on ZorinOS 16.2 (heavily based on Ubuntu 22.04) it works without issues, leading me to believe there’s still some package or setting missing…

What am I missing or doing wrong?

Little late, but adding gir1.2-nm-1.0 via apt worked for me.