I could then source ./.pytorch_env/bin/activate for a working environment. I proceeded with installing Pytorch with pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.2 which completed without issues. I then cloned ComfyUI, installed the requirements in requirements.txt with pip and proceeded to run the main.py application, and this is where I ran into problems:
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
(.pytorch_env)
How do I properly fix this the NixOS way? I’ve been looking into creating a shell.nix file but I’m not sure how to set it up. Normally it seems Python packages should be pulled from nixpkgs, but python312Packages.torchWithRocm seems to be based on rocmPackages_5 which is vastly out of date (and the newest ROCm package in NixOS seems to be 6.0.2 which is also ancient in the context of ML).
Well, you either use purely nixpkgs packages and accept the delay in updates, or you use poetry2nix to generate stuff from a python package. The latter can be quite tricky, since you’re depending on non-nixpkgs packages, and some of the stuff you depend on might not build properly out of the box on NixOS, so can require a fair bit of intervention.
Alternatively, if you want to use venv like you would on other distros, and that venv depends on python packages with precompiled bits of cython that link to non-python libraries, you can use nix-ld to set up a dynamic linker in the location most stuff expects and the host libraries your dependencies depend on.
Thanks. Unfortunately, this wasn’t as easy as I was hoping it would be. I think I might have to run a container instead, which I suppose is just as well.
For me I figured the easiest solution to be a buildFHSUserEnv like this NixOS module. It provides an fhs (or fhs -c 'my long command) command which yeets you into an environment where the prebuilt Python packages I use just work as usual. Your use case might require some adjustments maybe.
This is my quick’n’dirty solution if I just want to ‘make Python work’. If I care more about a project, I use poetry2nix.