Skip to content

Python: the wrapped python breaks nixglhost and NixGL (torch looses cuda support) #1973

Open
@frederiksemmel

Description

@frederiksemmel

Describe the bug

First of all, awesome project, thank you very much!

Using the python environment from devenv on a non-NixOs system doesn't work together with nixglhost. The torch from pypi doesn't work with cuda, but with nixglhost it should work. Changing --prefix to --suffix in the python wrapper would fix this, should I open a PR for this?

nixglhost sets the LD_LIBRARY_PATH such that OpenGL/Cuda drivers are loaded correctly on non-NixOs systems. It is very useful for environments that use pytorch and tensorrt.

The python wrapper from devenv prefixes the LD_LIBRARY_PATH with .devenv/profile/lib. Therefore when torch loads the cuda libraries, it finds the stub from .devenv/profile/lib instead of the version provided by nixghost.

The python wrapper from devenv currently looks like this:

  package = pkgs.callPackage ../../python-wrapper.nix {
    python = cfg.package;
    requiredPythonModules = cfg.package.pkgs.requiredPythonModules;
    makeWrapperArgs = [
      "--prefix"
      "LD_LIBRARY_PATH"
      ":"
      libraries
    ] ++ lib.optionals pkgs.stdenv.isDarwin [
      "--prefix"
      "DYLD_LIBRARY_PATH"
      ":"
      libraries
    ];
  };

The devenv python works nicely with nixglhost if we change --prefix to --suffix in that python wrapper.

Note on a separate python issue: Since this PR #1959 the python wrapper is not used for uv anymore. This is a separate issue, in the gist below, I have set UV_PYTHON="" to work around that.

To reproduce

https://gist.github.com/frederiksemmel/acbb88c69f53e66e80c361a450c0a324

  1. Run on system that is not NixOs with nixglhost installed, an Nvidia GPU, and working cuda setup
  2. Set up devenv python with uv.enable = true
  3. Use uv to add torch and do uv sync to set up the venv
  4. Run nixglhost python -c "import torch; print(torch.cuda.is_available())". This will print "False" and some error about a cuda sub file.

Version

devenv 1.6.1 (x86_64-linux)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions