Nbxmpp: Namespace Soup not available

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:

# bug.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.runCommandWith {
  name = "no-soup";
  derivationArgs.nativeBuildInputs = [
    (pkgs.python3.withPackages (ps: [ ps.nbxmpp ]))
  ];
}
''
  python -c "import nbxmpp"
  touch $out
''
$ 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
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.34.7
  • channels(root): "nixos"
  • nixpkgs: /nix/store/6klqg5z73bif2jkwxxmnj7x37j9fbd8w-nixos/nixos

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.

{ pkgs ? import <nixpkgs> {} }:
pkgs.runCommandWith {
  name = "warm-soup";
  derivationArgs.nativeBuildInputs = [
    pkgs.gobject-introspection pkgs.libsoup_3
    (pkgs.python3.withPackages (ps: [ ps.nbxmpp ps.precis-i18n ]))
  ];
}
''
  python -c "import nbxmpp"
  touch $out
''

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:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  name = "stone-soup";
  nativeBuildInputs = with pkgs; [
    gobject-introspection
    python3
    python3Packages.nbxmpp
    python3Packages.precis-i18n
  ];
}
[nix-shell:~/project]$ python3 -c "import nbxmpp; print(nbxmpp)"
<module 'nbxmpp' from '/nix/store/jkhw0hfpmwq9kibx2z5yp8j15cgxvs7n-python3.13-nbxmpp-7.1.0/lib/python3.13/site-packages/nbxmpp/__init__.py'>
1 Like

Yes, I want to mkShell. What I now did is this:

# shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShellNoCC {
  packages = [
    pkgs.yt-dlp
    pkgs.gobject-introspection pkgs.libsoup_3 # required for nbxmpp
    (pkgs.python3.withPackages (ps: with ps; [
    	nbxmpp httpx precis-i18n
    ]))
  ];
}

Thank you @twoolie for solving my problem!

2 Likes