1{ lib, stdenv, fetchurl, patchelf, perl, ncurses, expat, python27, zlib
2, xorg, gtk2, glib, fontconfig, freetype, unixODBC, alsaLib, glibc
3}:
4
5let
6
7 common =
8 { version, url, sha256
9 , python ? python27
10 }:
11
12 stdenv.mkDerivation rec {
13 name = "cudatoolkit-${version}";
14
15 dontPatchELF = true;
16 dontStrip = true;
17
18 src =
19 if stdenv.system == "x86_64-linux" then
20 fetchurl {
21 inherit url sha256;
22 }
23 else throw "cudatoolkit does not support platform ${stdenv.system}";
24
25 outputs = [ "out" "doc" ];
26
27 buildInputs = [ perl ];
28
29 runtimeDependencies = [
30 ncurses expat python zlib glibc
31 xorg.libX11 xorg.libXext xorg.libXrender xorg.libXt xorg.libXtst xorg.libXi xorg.libXext
32 gtk2 glib fontconfig freetype unixODBC alsaLib
33 ];
34
35 rpath = "${stdenv.lib.makeLibraryPath runtimeDependencies}:${stdenv.cc.cc.lib}/lib64";
36
37 unpackPhase = ''
38 sh $src --keep --noexec
39 cd pkg/run_files
40 sh cuda-linux64-rel-${version}-*.run --keep --noexec
41 sh cuda-samples-linux-${version}-*.run --keep --noexec
42 cd pkg
43 '';
44
45 buildPhase = ''
46 chmod -R u+w .
47 while IFS= read -r -d ''$'\0' i; do
48 if ! isELF "$i"; then continue; fi
49 echo "patching $i..."
50 if [[ ! $i =~ \.so ]]; then
51 patchelf \
52 --set-interpreter "''$(cat $NIX_CC/nix-support/dynamic-linker)" $i
53 fi
54 rpath2=$rpath:$lib/lib:$out/jre/lib/amd64/jli:$out/lib:$out/lib64:$out/nvvm/lib:$out/nvvm/lib64
55 patchelf --set-rpath $rpath2 --force-rpath $i
56 done < <(find . -type f -print0)
57 '';
58
59 installPhase = ''
60 mkdir $out
61 perl ./install-linux.pl --prefix="$out"
62
63 rm $out/tools/CUDA_Occupancy_Calculator.xls # FIXME: why?
64
65 # let's remove the 32-bit libraries, they confuse the lib64->lib mover
66 rm -rf $out/lib
67
68 # Remove some cruft.
69 rm $out/bin/uninstall*
70
71 # Fixup path to samples (needed for cuda 6.5 or else nsight will not find them)
72 if [ -d "$out"/cuda-samples ]; then
73 mv "$out"/cuda-samples "$out"/samples
74 fi
75
76 # Change the #error on GCC > 4.9 to a #warning.
77 sed -i $out/include/host_config.h -e 's/#error\(.*unsupported GNU version\)/#warning\1/'
78
79 # Ensure that cmake can find CUDA.
80 mkdir -p $out/nix-support
81 echo "cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'" >> $out/nix-support/setup-hook
82
83 # Remove OpenCL libraries as they are provided by ocl-icd and driver.
84 rm -f $out/lib64/libOpenCL*
85
86 '' + lib.optionalString (lib.versionOlder version "8.0") ''
87 # Hack to fix building against recent Glibc/GCC.
88 echo "NIX_CFLAGS_COMPILE+=' -D_FORCE_INLINES'" >> $out/nix-support/setup-hook
89 '';
90
91 meta = with stdenv.lib; {
92 description = "A compiler for NVIDIA GPUs, math libraries, and tools";
93 homepage = https://developer.nvidia.com/cuda-toolkit;
94 platforms = platforms.linux;
95 license = licenses.unfree;
96 };
97 };
98
99in {
100
101 cudatoolkit6 = common {
102 version = "6.0.37";
103 url = http://developer.download.nvidia.com/compute/cuda/6_0/rel/installers/cuda_6.0.37_linux_64.run;
104 sha256 = "991e436c7a6c94ec67cf44204d136adfef87baa3ded270544fa211179779bc40";
105 };
106
107 cudatoolkit65 = common {
108 version = "6.5.19";
109 url = http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.19_linux_64.run;
110 sha256 = "1x9zdmk8z784d3d35vr2ak1l4h5v4jfjhpxfi9fl9dvjkcavqyaj";
111 };
112
113 cudatoolkit7 = common {
114 version = "7.0.28";
115 url = http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run;
116 sha256 = "1km5hpiimx11jcazg0h3mjzk220klwahs2vfqhjavpds5ff2wafi";
117 };
118
119 cudatoolkit75 = common {
120 version = "7.5.18";
121 url = http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run;
122 sha256 = "1v2ylzp34ijyhcxyh5p6i0cwawwbbdhni2l5l4qm21s1cx9ish88";
123 };
124
125 cudatoolkit8 = common {
126 version = "8.0.61";
127 url = https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run;
128 sha256 = "1i4xrsqbad283qffvysn88w2pmxzxbbby41lw0j1113z771akv4w";
129 };
130
131}
132