Hi, I’m trying to set up a Python development environment where the Python module nbxmpp is available. However I’m getting this strange error that I cannot explain:
$ nix-build bug.nix
this derivation will be built:
/nix/store/8iq0na19kjyhc424h3pb97w1szjljciw-no-soup.drv
building '/nix/store/8iq0na19kjyhc424h3pb97w1szjljciw-no-soup.drv'...
Traceback (most recent call last):
File "<string>", line 1, in <module>
import nbxmpp
File "/nix/store/n465iasgxchvrbsl2lfdibg46ic8r7r5-python3-3.13.13-env/lib/python3.13/site-packages/nbxmpp/__init__.py", line 3, in <module>
gi.require_version("Soup", "3.0")
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/nix/store/n465iasgxchvrbsl2lfdibg46ic8r7r5-python3-3.13.13-env/lib/python3.13/site-packages/gi/__init__.py", line 150, in require_version
raise ValueError(f"Namespace {namespace} not available")
ValueError: Namespace Soup not available
error: Cannot build '/nix/store/8iq0na19kjyhc424h3pb97w1szjljciw-no-soup.drv'.
It feels like there is an undeclared dependency, but unit tests and dependencies of that package seem to work fine.
System metadata
system: "x86_64-linux"
host os: Linux 7.0.12, NixOS, 26.11 (Zokor), 26.11pre1014179.9ae611a455b9
That’s gobject. To use gobject bindings you need the wrapGappsHook.
That said, from your code I can’t really tell what you’re trying to do. As-is it will just run a python import in a nix build env, exit, and then create an empty file in the nix store.
If you want a development environment, you should be using mkShell. If you want a binary that launches a python script, you probably want pkgs.writers.writePython3. What exactly do you want to do with your “development environment”?
It looks like nbxmpp is correctly propagating the gobject-introspection dependency, and adding libsoup to the closure. as @TLATER said, wrapGapps usually takes care of collecting all the GI objects into GI_TYPELIB_PATH and passing it to your program. If you want to make this work in a dev environment, you need to use the gobject-introspection hook directly in your shell derivation.
I don’t know why pkgs.libsoup_3 needs to be in nativeBuildInputs when it should be propagated forward by nbxmpp, but something about the way python3.withPackages works masks it from the gobject-introspection hook machinery.
Alternate form as a shell, pulling in python deps directly seems to be allowing gobject-introspection to see the underlying glibs: