I started out on Reddit (link), but with the limited feedback I received, I still could not get my setup working.
I am new to NixOS. For a few weeks now, I have been having fun and am ready to migrate some projects to my new install. Unfortunately, I am stuck getting some python projects to work.
I want to setup a nix-shell for a MkDocs python project that uses mkdocs-with-pdf. I have got MkDocs working where I can “build” and “serve” the html version of the documentation, but the PDF stuff always gets stuck at OSError: cannot load library 'gobject-2.0-0':.... It appears that this is related to weasyprint needing this library.
I would greatly appreciate any input on how to get this library issue configured correctly.
This is the full error as the last line on the stack trace: OSError: cannot load library 'gobject-2.0-0': gobject-2.0-0: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'
I have tried a bunch of different shell.nix at this point. For now, while I get the feeling that one day I can replace my virtualenv entirely with a nix-shell, I have found that this basic version works okay if still do the whole python -m venv .venv with pip install -r requirements.txt once I am in the nix-shell as I would have done on my last setup.
So that doesn’t cause gobject problems? That’s surprising. If anything, I would expect that to break C library support, since the default implementation of ctypes.util.find_library() is too naïve to find libraries on NixOS. Last time I looked it was patched in nixpkgs, at least.
If you’re using a proper python shell, just adding gtk3might be enough, otherwise you might have to patch your cython sources and maybe recompile python as much as this is possible with a virtualenv.
Anyway, even then gobject stuff is very awkward. You usually need to have a bunch of environment variables set to make gobject things work on NixOS, since they default to fhs paths which do not exist on this distro.
This hasn’t cause problems yet. Though, I am still learning, new to nixos, and have yet to do anything too complex at all. This MkDocs PDF package issue is the first project that I have migrated to really halt my progress. Also, its been difficult to find much online even related.
I did see online that people were recommending gtk3, but that by itself hasn’t work. A Redditor said gtk4 and some other stuff, but that too hasn’t work.
This is basically a foreign language to me. Maybe this is why my basic searches about nix-shell, nix, python, pip, gobject, etc didn’t turn up positive results. Time to go search for some learning materials and look into wrapGAppsHook also.