6 , developerProgram ? false
31 stdenv.mkDerivation rec {
32 pname = "cudatoolkit";
33 inherit version runPatches;
39 if developerProgram then
42 This nix expression requires that ${args.name} is already part of the store.
43 Register yourself to NVIDIA Accelerated Computing Developer Program, retrieve the CUDA toolkit
44 at https://developer.nvidia.com/cuda-toolkit, and run the following command in the download directory:
45 nix-prefetch-url file://\$PWD/${args.name}
47 inherit (args) name sha256;
51 inherit (args) url sha256;
54 outputs = [ "out" "lib" "doc" ];
56 nativeBuildInputs = [ perl makeWrapper addOpenGLRunpath ];
57 buildInputs = [ gdk-pixbuf ]; # To get $GDK_PIXBUF_MODULE_FILE via setup-hook
58 runtimeDependencies = [
59 ncurses5 expat python27 zlib glibc
60 xorg.libX11 xorg.libXext xorg.libXrender xorg.libXt xorg.libXtst xorg.libXi xorg.libXext
61 gtk2 glib fontconfig freetype unixODBC alsaLib
64 rpath = "${lib.makeLibraryPath runtimeDependencies}:${stdenv.cc.cc.lib}/lib64";
67 sh $src --keep --noexec
69 ${lib.optionalString (lib.versionOlder version "10.1") ''
71 sh cuda-linux*.run --keep --noexec
72 sh cuda-samples*.run --keep --noexec
73 mv pkg ../../$(basename $src)
77 for patch in $runPatches; do
78 sh $patch --keep --noexec
79 mv pkg $(basename $patch)
87 ${lib.optionalString (lib.versionOlder version "10.1") ''
90 perl ./install-linux.pl --prefix="$out"
92 for patch in $runPatches; do
94 perl ./install_patch.pl --silent --accept-eula --installdir="$out"
98 ${lib.optionalString (lib.versionAtLeast version "10.1" && lib.versionOlder version "11") ''
99 cd pkg/builds/cuda-toolkit
102 ${lib.optionalString (lib.versionAtLeast version "11") ''
103 mkdir -p $out/bin $out/lib64 $out/include $out/doc
104 for dir in pkg/builds/* pkg/builds/cuda_nvcc/nvvm pkg/builds/cuda_cupti/extras/CUPTI; do
105 if [ -d $dir/bin ]; then
106 mv $dir/bin/* $out/bin
108 if [ -d $dir/doc ]; then
109 (cd $dir/doc && find . -type d -exec mkdir -p $out/doc/\{} \;)
110 (cd $dir/doc && find . \( -type f -o -type l \) -exec mv \{} $out/doc/\{} \;)
112 if [ -L $dir/include ] || [ -d $dir/include ]; then
113 (cd $dir/include && find . -type d -exec mkdir -p $out/include/\{} \;)
114 (cd $dir/include && find . \( -type f -o -type l \) -exec mv \{} $out/include/\{} \;)
116 if [ -L $dir/lib64 ] || [ -d $dir/lib64 ]; then
117 (cd $dir/lib64 && find . -type d -exec mkdir -p $out/lib64/\{} \;)
118 (cd $dir/lib64 && find . \( -type f -o -type l \) -exec mv \{} $out/lib64/\{} \;)
121 mv pkg/builds/cuda_nvcc/nvvm $out/nvvm
124 rm -f $out/tools/CUDA_Occupancy_Calculator.xls # FIXME: why?
126 ${lib.optionalString (lib.versionOlder version "10.1") ''
127 # let's remove the 32-bit libraries, they confuse the lib64->lib mover
132 ${lib.optionalString ((lib.versionAtLeast version "7.0") && (lib.versionOlder version "10.1"))
133 "rm $out/bin/uninstall*"}
135 # Fixup path to samples (needed for cuda 6.5 or else nsight will not find them)
136 if [ -d "$out"/cuda-samples ]; then
137 mv "$out"/cuda-samples "$out"/samples
140 # Change the #error on GCC > 4.9 to a #warning.
141 sed -i $out/include/host_config.h -e 's/#error\(.*unsupported GNU version\)/#warning\1/'
143 # Fix builds with newer glibc version
144 sed -i "1 i#define _BITS_FLOATN_H" "$out/include/host_defines.h"
146 # Ensure that cmake can find CUDA.
147 mkdir -p $out/nix-support
148 echo "cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'" >> $out/nix-support/setup-hook
150 # Move some libraries to the lib output so that programs that
151 # depend on them don't pull in this entire monstrosity.
153 mv -v $out/lib64/libcudart* $lib/lib/
155 # Remove OpenCL libraries as they are provided by ocl-icd and driver.
156 rm -f $out/lib64/libOpenCL*
157 ${lib.optionalString (lib.versionAtLeast version "10.1" && (lib.versionOlder version "11")) ''
158 mv $out/lib64 $out/lib
159 mv $out/extras/CUPTI/lib64/libcupti* $out/lib
162 # Set compiler for NVCC.
163 wrapProgram $out/bin/nvcc \
164 --prefix PATH : ${gcc}/bin
166 # nvprof do not find any program to profile if LD_LIBRARY_PATH is not set
167 wrapProgram $out/bin/nvprof \
168 --prefix LD_LIBRARY_PATH : $out/lib
169 '' + lib.optionalString (lib.versionOlder version "8.0") ''
170 # Hack to fix building against recent Glibc/GCC.
171 echo "NIX_CFLAGS_COMPILE+=' -D_FORCE_INLINES'" >> $out/nix-support/setup-hook
177 for b in nvvp ${lib.optionalString (lib.versionOlder version "11") "nsight"}; do
178 wrapProgram "$out/bin/$b" \
179 --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE"
184 while IFS= read -r -d ''$'\0' i; do
185 if ! isELF "$i"; then continue; fi
186 echo "patching $i..."
187 if [[ ! $i =~ \.so ]]; then
189 --set-interpreter "''$(cat $NIX_CC/nix-support/dynamic-linker)" $i
191 if [[ $i =~ libcudart ]]; then
194 rpath2=$rpath:$lib/lib:$out/jre/lib/amd64/jli:$out/lib:$out/lib64:$out/nvvm/lib:$out/nvvm/lib64
196 patchelf --set-rpath "$rpath2" --force-rpath $i
197 done < <(find $out $lib $doc -type f -print0)
200 # Set RPATH so that libcuda and other libraries in
201 # /run/opengl-driver(-32)/lib can be found. See the explanation in
202 # addOpenGLRunpath. Don't try to figure out which libraries really need
203 # it, just patch all (but not the stubs libraries). Note that
204 # --force-rpath prevents changing RPATH (set above) to RUNPATH.
206 addOpenGLRunpath --force-rpath {$out,$lib}/lib/lib*.so
209 # cuda-gdb doesn't run correctly when not using sandboxing, so
210 # temporarily disabling the install check. This should be set to true
211 # when we figure out how to get `cuda-gdb --version` to run correctly
212 # when not using sandboxing.
213 doInstallCheck = false;
214 postInstallCheck = let
216 # Smoke test binaries
221 nvcc.profile) continue;;
222 nsight_ee_plugins_manage.sh) continue;;
223 uninstall_cuda_toolkit_6.5.pl) continue;;
224 computeprof|nvvp|nsight) continue;; # GUIs don't feature "--version"
225 *) echo "Executing '$f --version':"; ./$f --version;;
232 majorVersion = lib.versions.majorMinor version;
236 description = "A compiler for NVIDIA GPUs, math libraries, and tools";
237 homepage = "https://developer.nvidia.com/cuda-toolkit";
238 platforms = [ "x86_64-linux" ];
239 license = licenses.unfree;