CUDA app in non-NixOS Linux

I recently solved the problem of launching a CUDA app with nix run in Ubuntu and Fedora and I 'm going to post this code here because I haven’t seen this technique posted anywhere.

I have a manufacia3 flake package which is built with poetry2nix and uses the CUDA version of torch.

This code declares a manufacia3-cuda flake package which is a wrapper script that uses nixglhost to discover the system CUDA driver paths at runtime.

    packages.manufacia3-cuda = pkgs.writeShellApplication {
      name = "manufacia3-cuda";
      runtimeInputs = [ inputs.nix-gl-host.defaultPackage.${system} ];
      text = ''
        nixglhost ${self'.packages.manufacia3}/bin/manufacia3
      '';
    };

If I run

nix run .#manufacia3

then the app runs without CUDA support.

If I run

nix run .#manufacia3-cuda

then the app runs with CUDA support.

I can also build a CUDA-enabled .deb package by

nix bundle --bundler github:NixOS/bundlers#toDEB .#manufacia3-cuda

This is working great for me and if this is a bad idea then I hope someone will explain why.

1 Like