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