Getting cv2 / opencv working on python / ComfyUI?

I’ve been using ComfyUI for weeks now with this configuration and following the manual installation, using uv pip install.

    environment.systemPackages = [  
    pkgs.uv
    ]
    
    programs.nix-ld = {
    enable = true;
    libraries = [ config.boot.kernelPackages.nvidia_x11 ]; 
    }

Most custom nodes work fine, there’s just one glaring issue: import cv2. When I start ComfyUI with uv run python main.py I get this error:

      File "/home/user/Assets/ComfyUI/custom_nodes/comfyui-easy-use/py/nodes/image.py", line 1799, in <module>
        import cv2
    ImportError: libxcb.so.1: cannot open shared object file: No such file or directory

Apparently many other users have issues with opencv as well. I found one workaround: running comfyui inside nix-shell -p python313Packages.opencv4Full, it doesn’t work when I addpython313Packages.opencv4Full to programs.nix-ld.libraries.