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