Python Packaging Issue: How to link and to torch-bin

I’m trying to package a repo I used to use in Windows Subsystem for Linux. I’m about to resort to podman, but I’m so close to getting it to work in Nix. The original repo is here: GitHub - neonbjb/tortoise-tts: A multi-voice TTS system trained with an emphasis on quality

My fork uses poetry2nix here, but poetry was having issues so I was mainly modifying the flake.nix instead of the pyproject.toml: GitHub - Yanall-Boutros/tortoise-tts-poetry2nix: A multi-voice TTS system trained with an emphasis on quality, packaged with nix flakes and poetry

(sorry in advance for the ugly nested buildInputs)

The flake has enough of the dependencies to run voice cloning for the random voice, but it can’t generate conditioning latents on custom voices because the torch-bin (I assume) expects the drivers somewhere in /usr/local/cuda but Nix puts them somewhere in /nix/store. Running nix develop --impure . then cd tortoise and python3 --voice daniel --text test will try and get_conditioning_latents, which calls torch.stft, throwing this runtime error:

  File "/nix/store/qqkakp6j3fyfc542prkig3jlpimdg78r-python3.11-torchaudio-2.2.2/lib/python3.11/site-packages/torchaudio/functional/", line 147, in spectrogram
    return spec_f.abs().pow(power)
RuntimeError: Error in dlopen for library

Solution was to update shell hooks to export LD_LIBRARY_PATH.

          shellHook = ''
            export CUDA_PATH=${pkgs.cudaPackages.cudatoolkit}
            export LD_LIBRARY_PATH=${pkgs.cudaPackages.cuda_nvrtc}/lib
            export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
            export EXTRA_CCFLAGS="-I/usr/include"

Then an unrelated issue was triggered, If using any voice except "random" it is lead to error · Issue #675 · neonbjb/tortoise-tts · GitHub
commenting that arg out allowed me to leverage my GPU in voice cloning on my NVIDIA RTX 3060