@@ -1,210 +1,15 @@
1−{ lib, stdenv, makeWrapper, fetchurl, requireFile, perl, ncurses5, expat, python27, zlib
2−, gcc48, gcc49, gcc5, gcc6, gcc7
3−, xorg, gtk2, gdk-pixbuf, glib, fontconfig, freetype, unixODBC, alsaLib, glibc
4−, addOpenGLRunpath
1+{ lib
2+, callPackage
3+, fetchurl
4+, gcc48
5+, gcc49
6+, gcc5
7+, gcc6
8+, gcc7
59}:
610
711let
8−
9− common =
10− args@{ gcc, version, sha256
11− , url ? ""
12− , name ? ""
13− , developerProgram ? false
14− , python ? python27
15− , runPatches ? []
16− }:
17−
18− stdenv.mkDerivation rec {
19− pname = "cudatoolkit";
20− inherit version runPatches;
21−
22− dontPatchELF = true;
23− dontStrip = true;
24−
25− src =
26− if developerProgram then
27− requireFile {
28− message = ''
29− This nix expression requires that ${args.name} is already part of the store.
30− Register yourself to NVIDIA Accelerated Computing Developer Program, retrieve the CUDA toolkit
31− at https://developer.nvidia.com/cuda-toolkit, and run the following command in the download directory:
32− nix-prefetch-url file://\$PWD/${args.name}
33− '';
34− inherit (args) name sha256;
35− }
36− else
37− fetchurl {
38− inherit (args) url sha256;
39− };
40−
41− outputs = [ "out" "lib" "doc" ];
42−
43− nativeBuildInputs = [ perl makeWrapper addOpenGLRunpath ];
44− buildInputs = [ gdk-pixbuf ]; # To get $GDK_PIXBUF_MODULE_FILE via setup-hook
45− runtimeDependencies = [
46− ncurses5 expat python zlib glibc
47− xorg.libX11 xorg.libXext xorg.libXrender xorg.libXt xorg.libXtst xorg.libXi xorg.libXext
48− gtk2 glib fontconfig freetype unixODBC alsaLib
49− ];
50−
51− rpath = "${stdenv.lib.makeLibraryPath runtimeDependencies}:${stdenv.cc.cc.lib}/lib64";
52−
53− unpackPhase = ''
54− sh $src --keep --noexec
55−
56− ${lib.optionalString (lib.versionOlder version "10.1") ''
57− cd pkg/run_files
58− sh cuda-linux*.run --keep --noexec
59− sh cuda-samples*.run --keep --noexec
60− mv pkg ../../$(basename $src)
61− cd ../..
62− rm -rf pkg
63−
64− for patch in $runPatches; do
65− sh $patch --keep --noexec
66− mv pkg $(basename $patch)
67− done
68− ''}
69− '';
70−
71− installPhase = ''
72− runHook preInstall
73− mkdir $out
74− ${lib.optionalString (lib.versionOlder version "10.1") ''
75− cd $(basename $src)
76− export PERL5LIB=.
77− perl ./install-linux.pl --prefix="$out"
78− cd ..
79− for patch in $runPatches; do
80− cd $(basename $patch)
81− perl ./install_patch.pl --silent --accept-eula --installdir="$out"
82− cd ..
83− done
84− ''}
85− ${lib.optionalString (lib.versionAtLeast version "10.1") ''
86− cd pkg/builds/cuda-toolkit
87− mv * $out/
88− ''}
89−
90− rm $out/tools/CUDA_Occupancy_Calculator.xls # FIXME: why?
91−
92− ${lib.optionalString (lib.versionOlder version "10.1") ''
93− # let's remove the 32-bit libraries, they confuse the lib64->lib mover
94− rm -rf $out/lib
95− ''}
96−
97− # Remove some cruft.
98− ${lib.optionalString ((lib.versionAtLeast version "7.0") && (lib.versionOlder version "10.1"))
99− "rm $out/bin/uninstall*"}
100−
101− # Fixup path to samples (needed for cuda 6.5 or else nsight will not find them)
102− if [ -d "$out"/cuda-samples ]; then
103− mv "$out"/cuda-samples "$out"/samples
104− fi
105−
106− # Change the #error on GCC > 4.9 to a #warning.
107− sed -i $out/include/host_config.h -e 's/#error\(.*unsupported GNU version\)/#warning\1/'
108−
109− # Fix builds with newer glibc version
110− sed -i "1 i#define _BITS_FLOATN_H" "$out/include/host_defines.h"
111−
112− # Ensure that cmake can find CUDA.
113− mkdir -p $out/nix-support
114− echo "cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'" >> $out/nix-support/setup-hook
115−
116− # Move some libraries to the lib output so that programs that
117− # depend on them don't pull in this entire monstrosity.
118− mkdir -p $lib/lib
119− mv -v $out/lib64/libcudart* $lib/lib/
120−
121− # Remove OpenCL libraries as they are provided by ocl-icd and driver.
122− rm -f $out/lib64/libOpenCL*
123− ${lib.optionalString (lib.versionAtLeast version "10.1") ''
124− mv $out/lib64 $out/lib
125− ''}
126−
127− # Set compiler for NVCC.
128− wrapProgram $out/bin/nvcc \
129− --prefix PATH : ${gcc}/bin
130−
131− # nvprof do not find any program to profile if LD_LIBRARY_PATH is not set
132− wrapProgram $out/bin/nvprof \
133− --prefix LD_LIBRARY_PATH : $out/lib
134− '' + lib.optionalString (lib.versionOlder version "8.0") ''
135− # Hack to fix building against recent Glibc/GCC.
136− echo "NIX_CFLAGS_COMPILE+=' -D_FORCE_INLINES'" >> $out/nix-support/setup-hook
137− '' + ''
138− runHook postInstall
139− '';
140−
141− postInstall = ''
142− for b in nvvp nsight; do
143− wrapProgram "$out/bin/$b" \
144− --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE"
145− done
146− '';
147−
148− preFixup = ''
149− while IFS= read -r -d ''$'\0' i; do
150− if ! isELF "$i"; then continue; fi
151− echo "patching $i..."
152− if [[ ! $i =~ \.so ]]; then
153− patchelf \
154− --set-interpreter "''$(cat $NIX_CC/nix-support/dynamic-linker)" $i
155− fi
156− if [[ $i =~ libcudart ]]; then
157− rpath2=
158− else
159− rpath2=$rpath:$lib/lib:$out/jre/lib/amd64/jli:$out/lib:$out/lib64:$out/nvvm/lib:$out/nvvm/lib64
160− fi
161− patchelf --set-rpath "$rpath2" --force-rpath $i
162− done < <(find $out $lib $doc -type f -print0)
163− '';
164−
165− # Set RPATH so that libcuda and other libraries in
166− # /run/opengl-driver(-32)/lib can be found. See the explanation in
167− # addOpenGLRunpath. Don't try to figure out which libraries really need
168− # it, just patch all (but not the stubs libraries). Note that
169− # --force-rpath prevents changing RPATH (set above) to RUNPATH.
170− postFixup = ''
171− addOpenGLRunpath --force-rpath {$out,$lib}/lib/lib*.so
172− '';
173−
174− # cuda-gdb doesn't run correctly when not using sandboxing, so
175− # temporarily disabling the install check. This should be set to true
176− # when we figure out how to get `cuda-gdb --version` to run correctly
177− # when not using sandboxing.
178− doInstallCheck = false;
179− postInstallCheck = let
180− in ''
181− # Smoke test binaries
182− pushd $out/bin
183− for f in *; do
184− case $f in
185− crt) continue;;
186− nvcc.profile) continue;;
187− nsight_ee_plugins_manage.sh) continue;;
188− uninstall_cuda_toolkit_6.5.pl) continue;;
189− computeprof|nvvp|nsight) continue;; # GUIs don't feature "--version"
190− *) echo "Executing '$f --version':"; ./$f --version;;
191− esac
192− done
193− popd
194− '';
195− passthru = {
196− cc = gcc;
197− majorVersion = lib.versions.majorMinor version;
198− };
199−
200− meta = with stdenv.lib; {
201− description = "A compiler for NVIDIA GPUs, math libraries, and tools";
202− homepage = "https://developer.nvidia.com/cuda-toolkit";
203− platforms = [ "x86_64-linux" ];
204− license = licenses.unfree;
205− };
206− };
207−
12+ common = callPackage ./common.nix;
20813in rec {
20914 cudatoolkit_6 = common {
21015 version = "6.0.37";