2014-12-24 00:01:04 +01:00
|
|
|
source $stdenv/setup
|
|
|
|
|
2017-01-29 22:29:39 +01:00
|
|
|
unpackManually() {
|
2014-12-24 00:01:04 +01:00
|
|
|
skip=$(sed 's/^skip=//; t; d' $src)
|
|
|
|
tail -n +$skip $src | xz -d | tar xvf -
|
|
|
|
sourceRoot=.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-29 22:29:39 +01:00
|
|
|
unpackFile() {
|
|
|
|
sh $src -x || unpackManually
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-24 00:01:04 +01:00
|
|
|
buildPhase() {
|
2017-01-29 22:29:39 +01:00
|
|
|
if [ -n "$bin" ]; then
|
2014-12-24 00:01:04 +01:00
|
|
|
# Create the module.
|
|
|
|
echo "Building linux driver against kernel: $kernel";
|
|
|
|
cd kernel
|
|
|
|
sysSrc=$(echo $kernel/lib/modules/$kernelVersion/source)
|
|
|
|
sysOut=$(echo $kernel/lib/modules/$kernelVersion/build)
|
|
|
|
unset src # used by the nv makefile
|
2017-02-11 23:29:37 +01:00
|
|
|
make SYSSRC=$sysSrc SYSOUT=$sysOut module -j$NIX_BUILD_CORES
|
2015-07-30 14:07:45 +02:00
|
|
|
|
2014-12-24 00:01:04 +01:00
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:32:00 +02:00
|
|
|
|
2014-12-24 00:01:04 +01:00
|
|
|
installPhase() {
|
2015-02-21 16:05:09 +01:00
|
|
|
# Install libGL and friends.
|
2018-08-11 17:32:00 +02:00
|
|
|
|
|
|
|
# since version 391, 32bit libraries are bundled in the 32/ sub-directory
|
|
|
|
if [ "$i686bundled" = "1" ]; then
|
|
|
|
mkdir -p "$lib32/lib"
|
2018-11-20 23:25:58 +01:00
|
|
|
cp -prd 32/*.so.* "$lib32/lib/"
|
|
|
|
if [ -d 32/tls ]; then
|
|
|
|
cp -prd 32/tls "$lib32/lib/"
|
|
|
|
fi
|
2018-08-11 17:32:00 +02:00
|
|
|
fi
|
|
|
|
|
2017-01-20 00:50:32 +01:00
|
|
|
mkdir -p "$out/lib"
|
2018-11-20 23:25:58 +01:00
|
|
|
cp -prd *.so.* "$out/lib/"
|
|
|
|
if [ -d tls ]; then
|
|
|
|
cp -prd tls "$out/lib/"
|
|
|
|
fi
|
2018-08-11 17:32:00 +02:00
|
|
|
|
2019-11-16 20:27:16 +01:00
|
|
|
# Install systemd power management executables
|
|
|
|
if [ -e nvidia-sleep.sh ]; then
|
|
|
|
sed -E 's#(PATH=).*#\1"$PATH"#' nvidia-sleep.sh > nvidia-sleep.sh.fixed
|
|
|
|
install -Dm755 nvidia-sleep.sh.fixed $out/bin/nvidia-sleep.sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e nvidia ]; then
|
|
|
|
sed -E "s#/usr(/bin/nvidia-sleep.sh)#$out\\1#" nvidia > nvidia.fixed
|
|
|
|
install -Dm755 nvidia.fixed $out/lib/systemd/system-sleep/nvidia
|
|
|
|
fi
|
|
|
|
|
2018-08-11 17:32:00 +02:00
|
|
|
for i in $lib32 $out; do
|
|
|
|
rm -f $i/lib/lib{glx,nvidia-wfb}.so.* # handled separately
|
|
|
|
rm -f $i/lib/libnvidia-gtk* # built from source
|
|
|
|
if [ "$useGLVND" = "1" ]; then
|
|
|
|
# Pre-built libglvnd
|
|
|
|
rm $i/lib/lib{GL,GLX,EGL,GLESv1_CM,GLESv2,OpenGL,GLdispatch}.so.*
|
|
|
|
fi
|
|
|
|
# Use ocl-icd instead
|
|
|
|
rm -f $i/lib/libOpenCL.so*
|
|
|
|
# Move VDPAU libraries to their place
|
|
|
|
mkdir $i/lib/vdpau
|
|
|
|
mv $i/lib/libvdpau* $i/lib/vdpau
|
|
|
|
|
2019-06-08 17:54:17 +02:00
|
|
|
# Install ICDs, make absolute paths.
|
2019-09-28 12:35:03 +02:00
|
|
|
# Be careful not to modify any original files because this runs twice.
|
|
|
|
|
|
|
|
# OpenCL
|
2019-06-08 17:54:17 +02:00
|
|
|
sed -E "s#(libnvidia-opencl)#$i/lib/\\1#" nvidia.icd > nvidia.icd.fixed
|
|
|
|
install -Dm644 nvidia.icd.fixed $i/etc/OpenCL/vendors/nvidia.icd
|
2019-09-28 12:35:03 +02:00
|
|
|
|
|
|
|
# Vulkan
|
|
|
|
if [ -e nvidia_icd.json.template ] || [ -e nvidia_icd.json ]; then
|
|
|
|
if [ -e nvidia_icd.json.template ]; then
|
|
|
|
# template patching for version < 435
|
|
|
|
sed "s#__NV_VK_ICD__#$i/lib/libGLX_nvidia.so#" nvidia_icd.json.template > nvidia_icd.json.fixed
|
|
|
|
else
|
|
|
|
sed -E "s#(libGLX_nvidia)#$i/lib/\\1#" nvidia_icd.json > nvidia_icd.json.fixed
|
|
|
|
fi
|
2020-05-05 19:03:56 +02:00
|
|
|
|
|
|
|
if [ "$system" = "i686-linux" ]; then
|
|
|
|
install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia_icd.i686.json
|
|
|
|
else
|
|
|
|
install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia_icd.json
|
|
|
|
fi
|
2018-08-11 17:32:00 +02:00
|
|
|
fi
|
2020-05-05 19:03:56 +02:00
|
|
|
|
2019-09-06 21:00:18 +02:00
|
|
|
if [ -e nvidia_layers.json ]; then
|
|
|
|
sed -E "s#(libGLX_nvidia)#$i/lib/\\1#" nvidia_layers.json > nvidia_layers.json.fixed
|
|
|
|
install -Dm644 nvidia_layers.json.fixed $i/share/vulkan/implicit_layer.d/nvidia_layers.json
|
|
|
|
fi
|
2019-09-28 12:35:03 +02:00
|
|
|
|
|
|
|
# EGL
|
2018-08-11 17:32:00 +02:00
|
|
|
if [ "$useGLVND" = "1" ]; then
|
2019-06-08 17:54:17 +02:00
|
|
|
sed -E "s#(libEGL_nvidia)#$i/lib/\\1#" 10_nvidia.json > 10_nvidia.json.fixed
|
2019-09-06 21:00:18 +02:00
|
|
|
sed -E "s#(libnvidia-egl-wayland)#$i/lib/\\1#" 10_nvidia_wayland.json > 10_nvidia_wayland.json.fixed
|
|
|
|
|
2019-06-08 17:54:17 +02:00
|
|
|
install -Dm644 10_nvidia.json.fixed $i/share/glvnd/egl_vendor.d/nvidia.json
|
2019-09-06 21:00:18 +02:00
|
|
|
install -Dm644 10_nvidia_wayland.json.fixed $i/share/glvnd/egl_vendor.d/nvidia_wayland.json
|
2018-08-11 17:32:00 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
|
2017-01-29 22:29:39 +01:00
|
|
|
if [ -n "$bin" ]; then
|
2015-02-24 13:08:08 +01:00
|
|
|
# Install the X drivers.
|
2017-01-29 22:29:39 +01:00
|
|
|
mkdir -p $bin/lib/xorg/modules
|
2019-02-22 19:00:19 +01:00
|
|
|
if [ -f libnvidia-wfb.so ]; then
|
|
|
|
cp -p libnvidia-wfb.* $bin/lib/xorg/modules/
|
|
|
|
fi
|
2017-01-29 22:29:39 +01:00
|
|
|
mkdir -p $bin/lib/xorg/modules/drivers
|
|
|
|
cp -p nvidia_drv.so $bin/lib/xorg/modules/drivers
|
|
|
|
mkdir -p $bin/lib/xorg/modules/extensions
|
2018-08-11 17:32:00 +02:00
|
|
|
cp -p libglx*.so* $bin/lib/xorg/modules/extensions
|
2015-02-24 13:08:08 +01:00
|
|
|
|
|
|
|
# Install the kernel module.
|
2017-01-29 22:29:39 +01:00
|
|
|
mkdir -p $bin/lib/modules/$kernelVersion/misc
|
2015-07-30 14:07:45 +02:00
|
|
|
for i in $(find ./kernel -name '*.ko'); do
|
2015-07-26 12:11:17 +02:00
|
|
|
nuke-refs $i
|
2017-01-29 22:29:39 +01:00
|
|
|
cp $i $bin/lib/modules/$kernelVersion/misc/
|
2015-07-26 12:11:17 +02:00
|
|
|
done
|
2017-02-11 15:11:18 +01:00
|
|
|
|
|
|
|
# Install application profiles.
|
|
|
|
if [ "$useProfiles" = "1" ]; then
|
|
|
|
mkdir -p $bin/share/nvidia
|
|
|
|
cp nvidia-application-profiles-*-rc $bin/share/nvidia/nvidia-application-profiles-rc
|
|
|
|
cp nvidia-application-profiles-*-key-documentation $bin/share/nvidia/nvidia-application-profiles-key-documentation
|
|
|
|
fi
|
2015-02-24 13:08:08 +01:00
|
|
|
fi
|
|
|
|
|
2017-01-29 22:29:39 +01:00
|
|
|
# All libs except GUI-only are installed now, so fixup them.
|
2018-08-11 17:32:00 +02:00
|
|
|
for libname in $(find "$out/lib/" $(test -n "$lib32" && echo "$lib32/lib/") $(test -n "$bin" && echo "$bin/lib/") -name '*.so.*')
|
2015-02-21 16:05:09 +01:00
|
|
|
do
|
|
|
|
# I'm lazy to differentiate needed libs per-library, as the closure is the same.
|
|
|
|
# Unfortunately --shrink-rpath would strip too much.
|
2019-06-08 15:23:05 +02:00
|
|
|
if [[ -n $lib32 && $libname == "$lib32/lib/"* ]]; then
|
|
|
|
patchelf --set-rpath "$lib32/lib:$libPath32" "$libname"
|
|
|
|
else
|
|
|
|
patchelf --set-rpath "$out/lib:$libPath" "$libname"
|
|
|
|
fi
|
2015-02-21 16:05:09 +01:00
|
|
|
|
|
|
|
libname_short=`echo -n "$libname" | sed 's/so\..*/so/'`
|
2015-07-28 07:54:09 +02:00
|
|
|
|
2016-01-09 20:01:51 +01:00
|
|
|
if [[ "$libname" != "$libname_short" ]]; then
|
|
|
|
ln -srnf "$libname" "$libname_short"
|
|
|
|
fi
|
2016-04-06 15:50:01 +02:00
|
|
|
|
2017-01-29 04:47:25 +01:00
|
|
|
if [[ $libname_short =~ libEGL.so || $libname_short =~ libEGL_nvidia.so || $libname_short =~ libGLX.so || $libname_short =~ libGLX_nvidia.so ]]; then
|
2016-04-06 15:50:01 +02:00
|
|
|
major=0
|
|
|
|
else
|
|
|
|
major=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$libname" != "$libname_short.$major" ]]; then
|
|
|
|
ln -srnf "$libname" "$libname_short.$major"
|
2016-01-09 20:01:51 +01:00
|
|
|
fi
|
2015-02-21 16:05:09 +01:00
|
|
|
done
|
|
|
|
|
2017-01-29 22:29:39 +01:00
|
|
|
if [ -n "$bin" ]; then
|
|
|
|
# Install /share files.
|
|
|
|
mkdir -p $bin/share/man/man1
|
|
|
|
cp -p *.1.gz $bin/share/man/man1
|
|
|
|
rm -f $bin/share/man/man1/{nvidia-xconfig,nvidia-settings,nvidia-persistenced}.1.gz
|
2015-02-24 13:08:08 +01:00
|
|
|
|
|
|
|
# Install the programs.
|
2017-01-29 22:29:39 +01:00
|
|
|
for i in nvidia-cuda-mps-control nvidia-cuda-mps-server nvidia-smi nvidia-debugdump; do
|
|
|
|
if [ -e "$i" ]; then
|
|
|
|
install -Dm755 $i $bin/bin/$i
|
2019-02-27 09:44:05 +01:00
|
|
|
# unmodified binary backup for mounting in containers
|
|
|
|
install -Dm755 $i $bin/origBin/$i
|
2017-01-29 22:29:39 +01:00
|
|
|
patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
|
|
|
|
--set-rpath $out/lib:$libPath $bin/bin/$i
|
|
|
|
fi
|
2015-02-24 13:08:08 +01:00
|
|
|
done
|
2017-01-29 22:29:39 +01:00
|
|
|
# FIXME: needs PATH and other fixes
|
|
|
|
# install -Dm755 nvidia-bug-report.sh $bin/bin/nvidia-bug-report.sh
|
2014-12-24 00:01:04 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
genericBuild
|