at 17.09-beta 172 lines 5.2 kB view raw
1{ stdenv, fetchurl, elfutils, mesa_noglu 2, xorg, patchelf, openssl, libdrm, libudev 3, libxcb, libxshmfence, epoxy, perl, zlib 4, fetchFromGitHub, ncurses 5, libsOnly ? false, kernel ? null 6}: 7 8assert (!libsOnly) -> kernel != null; 9 10with stdenv.lib; 11 12let 13 14 kernelDir = if libsOnly then null else kernel.dev; 15 16 inherit (mesa_noglu) driverLink; 17 18 bitness = if stdenv.is64bit then "64" else "32"; 19 20 libArch = 21 if stdenv.system == "i686-linux" then 22 "i386-linux-gnu" 23 else if stdenv.system == "x86_64-linux" then 24 "x86_64-linux-gnu" 25 else throw "amdgpu-pro is Linux only. Sorry. The build was stopped."; 26 27 libReplaceDir = "/usr/lib/${libArch}"; 28 29 ncurses5 = ncurses.override { abiVersion = "5"; }; 30 31in stdenv.mkDerivation rec { 32 33 version = "17.10"; 34 pname = "amdgpu-pro"; 35 build = "${version}-401251"; 36 37 libCompatDir = "/run/lib/${libArch}"; 38 39 name = pname + "-" + version + (optionalString (!libsOnly) "-${kernelDir.version}"); 40 41 src = fetchurl { 42 url = 43 "https://www2.ati.com/drivers/linux/ubuntu/amdgpu-pro-${build}.tar.xz"; 44 sha256 = "004n0df8acjpjz72z3bjxb2a0b7qwln13jlknfn7xxqvhhwwy40a"; 45 curlOpts = "--referer http://support.amd.com/en-us/kb-articles/Pages/AMD-Radeon-GPU-PRO-Linux-Beta-Driver%e2%80%93Release-Notes.aspx"; 46 }; 47 48 hardeningDisable = [ "pic" "format" ]; 49 50 inherit libsOnly; 51 52 postUnpack = '' 53 cd $sourceRoot 54 mkdir root 55 cd root 56 for deb in ../*_all.deb ../*_i386.deb '' + optionalString stdenv.is64bit "../*_amd64.deb" + ''; do echo $deb; ar p $deb data.tar.xz | tar -xJ; done 57 sourceRoot=. 58 ''; 59 60 modulePatches = [ 61 ./patches/0001-disable-firmware-copy.patch 62 ./patches/0002-linux-4.9-fixes.patch 63 ./patches/0003-Change-seq_printf-format-for-64-bit-context.patch 64 ./patches/0004-fix-warnings-for-Werror.patch 65 ]; 66 67 patchPhase = optionalString (!libsOnly) '' 68 pushd usr/src/amdgpu-pro-${build} 69 for patch in $modulePatches 70 do 71 echo $patch 72 patch -f -p1 < $patch || true 73 done 74 popd 75 ''; 76 77 preBuild = optionalString (!libsOnly) '' 78 pushd usr/src/amdgpu-pro-${build} 79 makeFlags="$makeFlags M=$(pwd)" 80 patchShebangs pre-build.sh 81 ./pre-build.sh ${kernel.version} 82 popd 83 ''; 84 85 modules = [ 86 "amd/amdgpu/amdgpu.ko" 87 "amd/amdkcl/amdkcl.ko" 88 "ttm/amdttm.ko" 89 ]; 90 91 postBuild = optionalString (!libsOnly) 92 (concatMapStrings (m: "xz usr/src/amdgpu-pro-${build}/${m}\n") modules); 93 94 NIX_CFLAGS_COMPILE = "-Werror"; 95 96 makeFlags = optionalString (!libsOnly) 97 "-C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build modules"; 98 99 depLibPath = makeLibraryPath [ 100 stdenv.cc.cc.lib xorg.libXext xorg.libX11 xorg.libXdamage xorg.libXfixes zlib 101 xorg.libXxf86vm libxcb libxshmfence epoxy openssl libdrm elfutils libudev ncurses5 102 ]; 103 104 installPhase = '' 105 mkdir -p $out 106 107 cp -r etc $out/etc 108 cp -r lib $out/lib 109 110 pushd usr 111 cp -r lib/${libArch}/* $out/lib 112 '' + optionalString (!libsOnly) '' 113 cp -r src/amdgpu-pro-${build}/firmware $out/lib/firmware 114 '' + '' 115 cp -r share $out/share 116 popd 117 118 pushd opt/amdgpu-pro 119 '' + optionalString (!stdenv.is64bit) '' 120 cp -r bin $out/bin 121 '' + '' 122 cp -r include $out/include 123 cp -r lib/${libArch}/* $out/lib 124 '' + optionalString (!libsOnly) '' 125 mv lib/xorg $out/lib/xorg 126 '' + '' 127 popd 128 129 '' + optionalString (!libsOnly) 130 (concatMapStrings (m: 131 "install -Dm444 usr/src/amdgpu-pro-${build}/${m}.xz $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/gpu/drm/${m}.xz\n") modules) 132 + '' 133 mv $out/etc/vulkan $out/share 134 interpreter="$(cat $NIX_CC/nix-support/dynamic-linker)" 135 libPath="$out/lib:$out/lib/gbm:$depLibPath" 136 '' + optionalString (!stdenv.is64bit) '' 137 for prog in clinfo modetest vbltest kms-universal-planes kms-steal-crtc modeprint amdgpu_test kmstest proptest; do 138 patchelf --interpreter "$interpreter" --set-rpath "$libPath" "$out/bin/$prog" 139 done 140 '' + '' 141 ln -s ${makeLibraryPath [ncurses5]}/libncursesw.so.5 $out/lib/libtinfo.so.5 142 ''; 143 144 # we'll just set the full rpath on everything to avoid having to track down dlopen problems 145 postFixup = assert (stringLength libReplaceDir == stringLength libCompatDir); '' 146 libPath="$out/lib:$out/lib/gbm:$depLibPath" 147 for lib in `find "$out/lib/" -name '*.so*' -type f`; do 148 patchelf --set-rpath "$libPath" "$lib" 149 done 150 for lib in libEGL.so.1 libGL.so.1.2 ${optionalString (!libsOnly) "xorg/modules/extensions/libglx.so"} dri/amdgpu_dri.so; do 151 perl -pi -e 's:${libReplaceDir}:${libCompatDir}:g' "$out/lib/$lib" 152 done 153 substituteInPlace "$out/share/vulkan/icd.d/amd_icd${bitness}.json" --replace "/opt/amdgpu-pro/lib/${libArch}" "$out/lib" 154 ''; 155 156 buildInputs = [ 157 patchelf 158 perl 159 ]; 160 161 enableParallelBuilding = true; 162 163 meta = with stdenv.lib; { 164 description = "AMDGPU-PRO drivers"; 165 homepage = http://support.amd.com/en-us/kb-articles/Pages/AMDGPU-PRO-Beta-Driver-for-Vulkan-Release-Notes.aspx ; 166 license = licenses.unfree; 167 platforms = platforms.linux; 168 maintainers = with maintainers; [ corngood ]; 169 # Copied from the nvidia default.nix to prevent a store collision. 170 priority = 4; 171 }; 172}