envision-unwrapped: 0-unstable-2024-10-20 -> 1.1.1 (#360652)
[NixPkgs.git] / pkgs / os-specific / linux / nvidia-x11 / builder.sh
blob00f38b0a30426f9365a54d136244c0544a24b0b4
1 if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
2 source $stdenv/setup
4 unpackManually() {
5 skip=$(sed 's/^skip=//; t; d' $src)
6 tail -n +$skip $src | bsdtar xvf -
7 sourceRoot=.
11 unpackFile() {
12 sh $src -x || unpackManually
16 buildPhase() {
17 runHook preBuild
19 if [ -n "$bin" ]; then
20 # Create the module.
21 echo "Building linux driver against kernel: $kernel";
22 cd kernel
23 unset src # used by the nv makefile
24 make $makeFlags -j $NIX_BUILD_CORES module
26 cd ..
29 runHook postBuild
33 installPhase() {
34 runHook preInstall
36 # Install libGL and friends.
38 # since version 391, 32bit libraries are bundled in the 32/ sub-directory
39 if [ "$i686bundled" = "1" ]; then
40 mkdir -p "$lib32/lib"
41 cp -prd 32/*.so.* "$lib32/lib/"
42 if [ -d 32/tls ]; then
43 cp -prd 32/tls "$lib32/lib/"
47 mkdir -p "$out/lib"
48 cp -prd *.so.* "$out/lib/"
49 if [ -d tls ]; then
50 cp -prd tls "$out/lib/"
53 # Install systemd power management executables
54 if [ -e systemd/nvidia-sleep.sh ]; then
55 mv systemd/nvidia-sleep.sh ./
57 if [ -e nvidia-sleep.sh ]; then
58 sed -E 's#(PATH=).*#\1"$PATH"#' nvidia-sleep.sh > nvidia-sleep.sh.fixed
59 install -Dm755 nvidia-sleep.sh.fixed $out/bin/nvidia-sleep.sh
62 if [ -e systemd/system-sleep/nvidia ]; then
63 mv systemd/system-sleep/nvidia ./
65 if [ -e nvidia ]; then
66 sed -E "s#/usr(/bin/nvidia-sleep.sh)#$out\\1#" nvidia > nvidia.fixed
67 install -Dm755 nvidia.fixed $out/lib/systemd/system-sleep/nvidia
70 for i in $lib32 $out; do
71 rm -f $i/lib/lib{glx,nvidia-wfb}.so.* # handled separately
72 rm -f $i/lib/libnvidia-gtk* # built from source
73 rm -f $i/lib/libnvidia-wayland-client* # built from source
74 if [ "$useGLVND" = "1" ]; then
75 # Pre-built libglvnd
76 rm $i/lib/lib{GL,GLX,EGL,GLESv1_CM,GLESv2,OpenGL,GLdispatch}.so.*
78 # Use ocl-icd instead
79 rm -f $i/lib/libOpenCL.so*
80 # Move VDPAU libraries to their place
81 mkdir $i/lib/vdpau
82 mv $i/lib/libvdpau* $i/lib/vdpau
84 # Compatibility with openssl 1.1, unused
85 rm -f $i/lib/libnvidia-pkcs11.so*
87 # Install ICDs, make absolute paths.
88 # Be careful not to modify any original files because this runs twice.
90 # OpenCL
91 sed -E "s#(libnvidia-opencl)#$i/lib/\\1#" nvidia.icd > nvidia.icd.fixed
92 install -Dm644 nvidia.icd.fixed $i/etc/OpenCL/vendors/nvidia.icd
94 # Vulkan
95 if [ -e nvidia_icd.json.template ] || [ -e nvidia_icd.json ]; then
96 if [ -e nvidia_icd.json.template ]; then
97 # template patching for version < 435
98 sed "s#__NV_VK_ICD__#$i/lib/libGLX_nvidia.so#" nvidia_icd.json.template > nvidia_icd.json.fixed
99 else
100 sed -E "s#(libGLX_nvidia)#$i/lib/\\1#" nvidia_icd.json > nvidia_icd.json.fixed
103 # nvidia currently only supports x86_64 and i686
104 if [ "$i" == "$lib32" ]; then
105 install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia_icd.i686.json
106 else
107 install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia_icd.x86_64.json
111 if [ -e nvidia_layers.json ]; then
112 sed -E "s#(libGLX_nvidia)#$i/lib/\\1#" nvidia_layers.json > nvidia_layers.json.fixed
113 install -Dm644 nvidia_layers.json.fixed $i/share/vulkan/implicit_layer.d/nvidia_layers.json
116 # EGL
117 if [ "$useGLVND" = "1" ]; then
118 mkdir -p "$i/share/egl/egl_external_platform.d"
119 for icdname in $(find . -name '*_nvidia*.json')
121 cat "$icdname" | jq ".ICD.library_path |= \"$i/lib/\(.)\"" | tee "$i/share/egl/egl_external_platform.d/$icdname"
122 done
124 # glvnd icd
125 mkdir -p "$i/share/glvnd/egl_vendor.d"
126 mv "$i/share/egl/egl_external_platform.d/10_nvidia.json" "$i/share/glvnd/egl_vendor.d/10_nvidia.json"
128 if [[ -f "$i/share/egl/egl_external_platform.d/15_nvidia_gbm.json" ]]; then
129 mkdir -p $i/lib/gbm
130 ln -s $i/lib/libnvidia-allocator.so $i/lib/gbm/nvidia-drm_gbm.so
134 # Install libraries needed by Proton to support DLSS
135 if [ -e nvngx.dll ] && [ -e _nvngx.dll ]; then
136 install -Dm644 -t $i/lib/nvidia/wine/ nvngx.dll _nvngx.dll
138 done
141 # OptiX tries loading `$ORIGIN/nvoptix.bin` first
142 if [ -e nvoptix.bin ]; then
143 install -Dm444 -t $out/lib/ nvoptix.bin
146 if [ -n "$bin" ]; then
147 # Install the X drivers.
148 mkdir -p $bin/lib/xorg/modules
149 if [ -f libnvidia-wfb.so ]; then
150 cp -p libnvidia-wfb.* $bin/lib/xorg/modules/
152 mkdir -p $bin/lib/xorg/modules/drivers
153 cp -p nvidia_drv.so $bin/lib/xorg/modules/drivers
154 mkdir -p $bin/lib/xorg/modules/extensions
155 cp -p libglx*.so* $bin/lib/xorg/modules/extensions
157 # Install the kernel module.
158 mkdir -p $bin/lib/modules/$kernelVersion/misc
159 for i in $(find ./kernel -name '*.ko'); do
160 nuke-refs $i
161 cp $i $bin/lib/modules/$kernelVersion/misc/
162 done
164 # Install application profiles.
165 if [ "$useProfiles" = "1" ]; then
166 mkdir -p $bin/share/nvidia
167 cp nvidia-application-profiles-*-rc $bin/share/nvidia/nvidia-application-profiles-rc
168 cp nvidia-application-profiles-*-key-documentation $bin/share/nvidia/nvidia-application-profiles-key-documentation
172 if [ -n "$firmware" ]; then
173 # Install the GSP firmware
174 install -Dm644 -t $firmware/lib/firmware/nvidia/$version firmware/gsp*.bin
177 # All libs except GUI-only are installed now, so fixup them.
178 for libname in $(find "$out/lib/" $(test -n "$lib32" && echo "$lib32/lib/") $(test -n "$bin" && echo "$bin/lib/") -name '*.so.*')
180 # I'm lazy to differentiate needed libs per-library, as the closure is the same.
181 # Unfortunately --shrink-rpath would strip too much.
182 if [[ -n $lib32 && $libname == "$lib32/lib/"* ]]; then
183 patchelf --set-rpath "$lib32/lib:$libPath32" "$libname"
184 else
185 patchelf --set-rpath "$out/lib:$libPath" "$libname"
188 # Manually create the right symlinks for the libraries.
190 # We can't just use ldconfig, because it does not create libfoo.so symlinks,
191 # only libfoo.so.1.
192 # Also, the symlink chain must be libfoo.so -> libfoo.so.1 -> libfoo.so.123.45,
193 # or ldconfig will explode.
194 # See: https://github.com/bminor/glibc/blob/6f3f6c506cdaf981a4374f1f12863b98ac7fea1a/elf/ldconfig.c#L854-L877
196 libbase=$(basename "$libname")
197 libdir=$(dirname "$libname")
198 soname=$(patchelf --print-soname "$libname")
199 unversioned=${libbase/\.so\.[0-9\.]*/.so}
201 if [[ -n "$soname" ]]; then
202 if [[ "$soname" != "$libbase" ]]; then
203 ln -s "$libbase" "$libdir/$soname"
206 if [[ "$soname" != "$unversioned" ]]; then
207 ln -s "$soname" "$libdir/$unversioned"
211 # FIXME: libglxserver_nvidia does not have a soname, but must still be symlinked
212 if [[ "$unversioned" == "libglxserver_nvidia.so" ]]; then
213 ln -s "$libbase" "$libdir/$unversioned"
215 done
217 if [ -n "$bin" ]; then
218 # Install /share files.
219 mkdir -p $bin/share/man/man1
220 cp -p *.1.gz $bin/share/man/man1
221 rm -f $bin/share/man/man1/{nvidia-xconfig,nvidia-settings,nvidia-persistenced}.1.gz
222 if [ -e "nvidia-dbus.conf" ]; then
223 install -Dm644 nvidia-dbus.conf $bin/share/dbus-1/system.d/nvidia-dbus.conf
226 # Install the programs.
227 for i in nvidia-cuda-mps-control nvidia-cuda-mps-server nvidia-smi nvidia-debugdump nvidia-powerd; do
228 if [ -e "$i" ]; then
229 install -Dm755 $i $bin/bin/$i
230 # unmodified binary backup for mounting in containers
231 install -Dm755 $i $bin/origBin/$i
232 patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
233 --set-rpath $out/lib:$libPath $bin/bin/$i
235 done
236 substituteInPlace nvidia-bug-report.sh \
237 --replace /bin/grep grep \
238 --replace /bin/ls ls
239 install -Dm755 nvidia-bug-report.sh $bin/bin/nvidia-bug-report.sh
242 runHook postInstall
245 genericBuild