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