CUDA setup on NixOS

EDIT: Tested this recently in 19.03pre167858.f2a1a4e93be (Koi) and it works (just be warned that it takes a lot of time to get the first time).

Hey @ludflu, I’ve used this setup for using CUDA inside a Nix-Shell* (stolen from this PR) on my system, so no need to install it globally.

In a shell.nix:

{ pkgs ? import <nixpkgs> {} }:

pkgs.stdenv.mkDerivation {
  name = "cuda-env-shell";
  buildInputs = with pkgs; [
    autoconf
    binutils
    cudatoolkit
    curl
    freeglut
    git
    gitRepo
    gnumake
    gnupg
    gperf
    libGLU_combined
    linuxPackages.nvidia_x11
    m4
    ncurses5
    procps
    stdenv.cc
    unzip
    utillinux
    xorg.libX11
    xorg.libXext
    xorg.libXi
    xorg.libXmu
    xorg.libXrandr
    xorg.libXv
    zlib
  ];
  shellHook = ''
    export CUDA_PATH=${pkgs.cudatoolkit}
    export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
    export EXTRA_CCFLAGS="-I/usr/include"
  '';
}

Extra:

My current shell setups also includes the following .envrc with direnv.

2 Likes