From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1342985-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 18C19158086
	for <garchives@archives.gentoo.org>; Wed, 24 Nov 2021 19:55:11 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id C6B36E0830;
	Wed, 24 Nov 2021 19:55:09 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 98839E0830
	for <gentoo-commits@lists.gentoo.org>; Wed, 24 Nov 2021 19:55:09 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 8F2B8342B68
	for <gentoo-commits@lists.gentoo.org>; Wed, 24 Nov 2021 19:55:06 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 371FC8E
	for <gentoo-commits@lists.gentoo.org>; Wed, 24 Nov 2021 19:55:05 +0000 (UTC)
From: "Ionen Wolkens" <ionen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Ionen Wolkens" <ionen@gentoo.org>
Message-ID: <1637783474.bafd825d6a8f528e36d80a166682fe929ffa8654.ionen@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: x11-drivers/nvidia-drivers/
X-VCS-Repository: repo/gentoo
X-VCS-Files: x11-drivers/nvidia-drivers/Manifest x11-drivers/nvidia-drivers/nvidia-drivers-470.62.13.ebuild
X-VCS-Directories: x11-drivers/nvidia-drivers/
X-VCS-Committer: ionen
X-VCS-Committer-Name: Ionen Wolkens
X-VCS-Revision: bafd825d6a8f528e36d80a166682fe929ffa8654
X-VCS-Branch: master
Date: Wed, 24 Nov 2021 19:55:05 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 66b084ba-71c3-4e2a-85a3-211b588d1e64
X-Archives-Hash: f148f166350ad169ec6d4515d833846e

commit:     bafd825d6a8f528e36d80a166682fe929ffa8654
Author:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
AuthorDate: Wed Nov 24 19:50:58 2021 +0000
Commit:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
CommitDate: Wed Nov 24 19:51:14 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=bafd825d

x11-drivers/nvidia-drivers: add 470.62.13:0/vulkan

Signed-off-by: Ionen Wolkens <ionen <AT> gentoo.org>

 x11-drivers/nvidia-drivers/Manifest                |   1 +
 .../nvidia-drivers/nvidia-drivers-470.62.13.ebuild | 490 +++++++++++++++++++++
 2 files changed, 491 insertions(+)

diff --git a/x11-drivers/nvidia-drivers/Manifest b/x11-drivers/nvidia-drivers/Manifest
index 427a75137709..488daea1eb04 100644
--- a/x11-drivers/nvidia-drivers/Manifest
+++ b/x11-drivers/nvidia-drivers/Manifest
@@ -6,6 +6,7 @@ DIST NVIDIA-Linux-x86-390.144.run 49210937 BLAKE2B b7e6edb55af88be74e4322ff1d270
 DIST NVIDIA-Linux-x86_64-390.144.run 85000417 BLAKE2B 8ecfa768fb8fe92170ff5b82698a7fb22da8bc557ab2036464bf5650b6fffc7028e25a68e1f5638f6bc171eb45a4aba459465490c7a99aacd36dc769994062e8 SHA512 9503ebf41037a14deba995288a364768cb03fb682de8653a4b0c05955b23603443c41c4216c93eac7d7efc301734416012864ede728324ab47b93ff167d93da4
 DIST NVIDIA-Linux-x86_64-460.91.03.run 178201292 BLAKE2B 4d407b7bb3a99ab71c62c3cd18dc3549c98a24e7af28276e6e6a21dd33efcab017fed3f782f6dfb060c4437cd718f19c2f9900de367cc47bf19fa2718a18ad55 SHA512 4ac11130fe5a8f1c26f459e9c19660b3ff6f23011e9f77b09ca948fc42609e523ecea70d3bf6def50a75b4a3079ab280018753fb6e53875d9bb8093a033e3b70
 DIST NVIDIA-Linux-x86_64-470.62.12.run 271962238 BLAKE2B a09c36f6c44f8cd56b24dd2dc1f8de930ca517a928b19a5a0c6ada91eac8338b1e42f64510cacdb50734c4e605c14f7eb4fb9f4910aad15c7fec2172b1677ec6 SHA512 e7d21ce7bf4cf034cb7e6162dfc8b7cfb9bb3144fbb70c0c2e6b8aeaf6379665f15117edbb685ea7d97f0956f89d2a58f4c77645af967d33072cbc3186d5e503
+DIST NVIDIA-Linux-x86_64-470.62.13.run 272974366 BLAKE2B 08f8e5828adf3823f0988abb67c0a2b92b80637b2a28e24f056884aabad69c7ac929c8c32594c3d63d8a1ee69f58f9a99cadab9b1a2bc3e42ddab3146ab7376c SHA512 5228bdb88a005bec9cd66f23197b0f1ee8b9d7c5c68b3d13352102125d21da67c6800cbe18215d77f2b3dc59a7ab9cdaf78f42b21e87b7eb8123bbc9f3b6a42e
 DIST NVIDIA-Linux-x86_64-470.82.00.run 272296454 BLAKE2B f28f4a66fb27ccf7967ad66f9dcacc306653895a5f9c63f49e7833f5ca37e6260df37fe28abff89cc2ff9e54491b39594117235e4e87d3b1e22e58de8e69fe5b SHA512 f4135efd748d8835e9719e6ef93a86c5646a4d771c63e31f0bdaa0cf6ddf25ce9356eca58c27addb988f4cbe88c9bdcc0536512a46915826261d8f4f4247ebd8
 DIST NVIDIA-Linux-x86_64-470.86.run 273149806 BLAKE2B c7f5a64dfb6547856d5bccdce0fcce0f6180966961245508cdc96e672ae500940f35fad0a9b8e8e9692b5cc67d68504371e041364e3a367deb4e1c3c75222c20 SHA512 e541549967ee992b8e6812cb6a294307217e66c7380ec17ff143ddc637f6e3a5b6c807ba8e29bf4c3d6813d7589a41aa124e8a5709a484ecf7fedfe420598a06
 DIST NVIDIA-Linux-x86_64-495.44.run 282259831 BLAKE2B ca11406a5b1b25d9691ec61d4125457c22438b8f0af0651043235f72ee75c4b264cfde7b04840bbec15c22bc5eb657a46326b49941e6c776a8990430cf052818 SHA512 bc9054e6028ba172906e6eb9a0b8f5cfc3ae74d57f3e95e0f9057879e3af07a4b19479e80d81e948872bc47bbd674f77f5f81d4debd2e2c3ce45058cd9211802

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-470.62.13.ebuild b/x11-drivers/nvidia-drivers/nvidia-drivers-470.62.13.ebuild
new file mode 100644
index 000000000000..0cc7549b27a9
--- /dev/null
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-470.62.13.ebuild
@@ -0,0 +1,490 @@
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+MODULES_OPTIONAL_USE="driver"
+inherit desktop linux-info linux-mod multilib-build \
+	readme.gentoo-r1 systemd toolchain-funcs unpacker
+
+NV_KERNEL_MAX="5.15"
+NV_URI="https://download.nvidia.com/XFree86/"
+NV_PIN="470.63.01"
+
+DESCRIPTION="NVIDIA Accelerated Graphics Driver"
+HOMEPAGE="https://www.nvidia.com/download/index.aspx"
+SRC_URI="
+	https://developer.nvidia.com/vulkan-beta-${PV//./}-linux -> NVIDIA-Linux-x86_64-${PV}.run
+	${NV_URI}nvidia-installer/nvidia-installer-${NV_PIN}.tar.bz2
+	${NV_URI}nvidia-modprobe/nvidia-modprobe-${NV_PIN}.tar.bz2
+	${NV_URI}nvidia-persistenced/nvidia-persistenced-${NV_PIN}.tar.bz2
+	${NV_URI}nvidia-settings/nvidia-settings-${NV_PIN}.tar.bz2
+	${NV_URI}nvidia-xconfig/nvidia-xconfig-${NV_PIN}.tar.bz2"
+# nvidia-installer is unused but here for GPL-2's "distribute sources"
+S="${WORKDIR}"
+
+LICENSE="GPL-2 MIT NVIDIA-r2 ZLIB"
+SLOT="0/vulkan"
+KEYWORDS="-* ~amd64"
+IUSE="+X +driver static-libs +tools wayland"
+
+COMMON_DEPEND="
+	acct-group/video
+	acct-user/nvpd
+	net-libs/libtirpc:=
+	tools? (
+		dev-libs/atk
+		dev-libs/glib:2
+		dev-libs/jansson
+		media-libs/harfbuzz:=
+		x11-libs/cairo
+		x11-libs/gdk-pixbuf:2
+		x11-libs/gtk+:3
+		x11-libs/libX11
+		x11-libs/libXext
+		x11-libs/libXxf86vm
+		x11-libs/pango
+	)"
+RDEPEND="
+	${COMMON_DEPEND}
+	X? (
+		media-libs/libglvnd[X,${MULTILIB_USEDEP}]
+		x11-libs/libX11[${MULTILIB_USEDEP}]
+		x11-libs/libXext[${MULTILIB_USEDEP}]
+	)
+	wayland? (
+		>=gui-libs/egl-wayland-1.1.7-r1
+		media-libs/libglvnd
+	)"
+DEPEND="
+	${COMMON_DEPEND}
+	static-libs? (
+		x11-libs/libX11
+		x11-libs/libXext
+	)
+	tools? (
+		media-libs/libglvnd
+		sys-apps/dbus
+		x11-base/xorg-proto
+		x11-libs/libXrandr
+		x11-libs/libXv
+		x11-libs/libvdpau
+	)"
+BDEPEND="
+	app-misc/pax-utils
+	sys-devel/m4
+	virtual/pkgconfig"
+
+QA_PREBUILT="lib/firmware/* opt/bin/* usr/lib*"
+
+PATCHES=(
+	"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
+)
+
+DOCS=(
+	README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
+	nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
+)
+HTML_DOCS=( html/. )
+
+pkg_setup() {
+	use driver || return
+
+	local CONFIG_CHECK="
+		PROC_FS
+		~DRM_KMS_HELPER
+		~SYSVIPC
+		~!DRM_SIMPLEDRM
+		~!LOCKDEP
+		~!SLUB_DEBUG_ON
+		!DEBUG_MUTEXES"
+	local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
+	of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
+	Cannot be directly selected in the kernel's menuconfig, and may need
+	selection of a DRM device even if unused, e.g. CONFIG_DRM_AMDGPU=m or
+	DRM_I915=y, DRM_NOUVEAU=m also acceptable if a module and not built-in.
+	Note: DRM_SIMPLEDRM may cause issues and is better disabled for now."
+
+	kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
+
+	MODULE_NAMES="
+		nvidia(video:kernel)
+		nvidia-drm(video:kernel)
+		nvidia-modeset(video:kernel)
+		nvidia-peermem(video:kernel)
+		nvidia-uvm(video:kernel)"
+
+	linux-mod_pkg_setup
+
+	[[ ${MERGE_TYPE} == binary ]] && return
+
+	BUILD_PARAMS='NV_VERBOSE=1 IGNORE_CC_MISMATCH=yes SYSSRC="${KV_DIR}" SYSOUT="${KV_OUT_DIR}"'
+	BUILD_TARGETS="modules" # defaults' clean sometimes deletes modules
+
+	if linux_chkconfig_present CC_IS_CLANG; then
+		ewarn "Warning: building ${PN} with a clang-built kernel is experimental."
+
+		BUILD_PARAMS+=' CC=${CHOST}-clang'
+		if linux_chkconfig_present LD_IS_LLD; then
+			BUILD_PARAMS+=' LD=ld.lld'
+			if linux_chkconfig_present LTO_CLANG_THIN; then
+				# kernel enables cache by default leading to sandbox violations
+				BUILD_PARAMS+=' ldflags-y=--thinlto-cache-dir= LDFLAGS_MODULE=--thinlto-cache-dir='
+			fi
+		fi
+	fi
+
+	if kernel_is -gt ${NV_KERNEL_MAX/./ }; then
+		ewarn "Kernel ${KV_MAJOR}.${KV_MINOR} is either known to break this version of nvidia-drivers"
+		ewarn "or was not tested with it. It is recommended to use one of:"
+		ewarn "  <=sys-kernel/gentoo-kernel-${NV_KERNEL_MAX}"
+		ewarn "  <=sys-kernel/gentoo-sources-${NV_KERNEL_MAX}"
+		ewarn "You are free to try or use /etc/portage/patches, but support will"
+		ewarn "not be given and issues wait until NVIDIA releases a fixed version."
+		ewarn
+		ewarn "Do _not_ file a bug report if run into issues."
+		ewarn
+	fi
+}
+
+src_prepare() {
+	# make user patches usable across versions
+	rm nvidia-modprobe && mv nvidia-modprobe{-${NV_PIN},} || die
+	rm nvidia-persistenced && mv nvidia-persistenced{-${NV_PIN},} || die
+	rm nvidia-settings && mv nvidia-settings{-${NV_PIN},} || die
+	rm nvidia-xconfig && mv nvidia-xconfig{-${NV_PIN},} || die
+
+	default
+
+	# prevent detection of incomplete kernel DRM support (bug #603818)
+	sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
+		-i kernel/conftest.sh || die
+
+	sed -e '/Exec=\|Icon=/s/_.*/nvidia-settings/' \
+		-e '/Categories=/s/_.*/System;Settings;/' \
+		-i nvidia-settings/doc/nvidia-settings.desktop || die
+
+	# remove gtk2 support (bug #592730)
+	sed '/^GTK2LIB = /d;/INSTALL.*GTK2LIB/,+1d' \
+		-i nvidia-settings/src/Makefile || die
+
+	sed 's/__USER__/nvpd/' \
+		nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
+		> nvidia-persistenced.service || die
+
+	# enable nvidia-drm.modeset=1 by default with USE=wayland
+	cp "${FILESDIR}"/nvidia-470.conf "${T}"/nvidia.conf || die
+	if use wayland; then
+		sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
+	fi
+
+	gzip -d nvidia-{cuda-mps-control,smi}.1.gz || die
+}
+
+src_compile() {
+	nvidia-drivers_make() {
+		emake -C nvidia-${1} ${2} \
+			PREFIX="${EPREFIX}/usr" \
+			HOST_CC="$(tc-getBUILD_CC)" \
+			HOST_LD="$(tc-getBUILD_LD)" \
+			NV_USE_BUNDLED_LIBJANSSON=0 \
+			NV_VERBOSE=1 DO_STRIP= OUTPUTDIR=out
+	}
+
+	tc-export AR CC LD OBJCOPY
+
+	# may no longer be relevant but kept as a safety
+	export DISTCC_DISABLE=1 CCACHE_DISABLE=1
+
+	use driver && linux-mod_src_compile
+
+	nvidia-drivers_make modprobe
+	nvidia-drivers_make persistenced
+	use X && nvidia-drivers_make xconfig
+
+	if use tools; then
+		nvidia-drivers_make settings
+	elif use static-libs; then
+		nvidia-drivers_make settings/src out/libXNVCtrl.a
+	fi
+}
+
+src_install() {
+	nvidia-drivers_make_install() {
+		emake -C nvidia-${1} install \
+			DESTDIR="${D}" \
+			PREFIX="${EPREFIX}/usr" \
+			LIBDIR="${ED}/usr/$(get_libdir)" \
+			NV_USE_BUNDLED_LIBJANSSON=0 \
+			NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
+	}
+
+	nvidia-drivers_libs_install() {
+		local libs=(
+			EGL_nvidia
+			GLESv1_CM_nvidia
+			GLESv2_nvidia
+			cuda
+			nvcuvid
+			nvidia-allocator
+			nvidia-compiler
+			nvidia-eglcore
+			nvidia-encode
+			nvidia-glcore
+			nvidia-glsi
+			nvidia-glvkspirv
+			nvidia-ml
+			nvidia-opencl
+			nvidia-opticalflow
+			nvidia-ptxjitcompiler
+			nvidia-tls
+		)
+
+		if use X; then
+			libs+=(
+				GLX_nvidia
+				nvidia-fbc
+				nvidia-ifr
+				vdpau_nvidia
+			)
+		fi
+
+		local libdir=.
+		if [[ ${ABI} == x86 ]]; then
+			libdir+=/32
+		else
+			libs+=(
+				libnvidia-nvvm.so.4.0.0
+				nvidia-cfg
+				nvidia-ngx
+				nvidia-rtcore
+				nvoptix
+			)
+			use wayland && libs+=( nvidia-vulkan-producer )
+		fi
+
+		local lib soname
+		for lib in "${libs[@]}"; do
+			[[ ${lib:0:3} != lib ]] && lib=lib${lib}.so.${PV}
+
+			# auto-detect soname and create appropriate symlinks
+			soname=$(scanelf -qF'%S#F' ${lib}) || die "Scanning ${lib} failed"
+			if [[ ${soname} && ${soname} != ${lib} ]]; then
+				ln -s ${lib} ${libdir}/${soname} || die
+			fi
+			ln -s ${lib} ${libdir}/${lib%.so*}.so || die
+
+			dolib.so ${libdir}/${lib%.so*}*
+		done
+	}
+
+	if use driver; then
+		linux-mod_src_install
+
+		insinto /etc/modprobe.d
+		doins "${T}"/nvidia.conf
+
+		insinto /lib/firmware/nvidia/${PV}
+		doins firmware/gsp.bin
+
+		# used for gpu verification with binpkgs (not kept)
+		insinto /usr/share/nvidia
+		doins supported-gpus/supported-gpus.json
+	fi
+
+	if use X; then
+		exeinto /usr/$(get_libdir)/xorg/modules/drivers
+		doexe nvidia_drv.so
+
+		exeinto /usr/$(get_libdir)/xorg/modules/extensions
+		newexe libglxserver_nvidia.so{.${PV},}
+
+		insinto /usr/share/X11/xorg.conf.d
+		newins {,50-}nvidia-drm-outputclass.conf
+
+		# vulkan icd uses libGLX_nvidia.so and so requires X
+		insinto /usr/share/vulkan/icd.d
+		doins nvidia_icd.json
+		insinto /usr/share/vulkan/implicit_layer.d
+		doins nvidia_layers.json
+	fi
+
+	insinto /usr/share/glvnd/egl_vendor.d
+	doins 10_nvidia.json
+
+	insinto /etc/OpenCL/vendors
+	doins nvidia.icd
+
+	insinto /etc/nvidia
+	newins nvidia-application-profiles{-${PV},}-rc
+
+	# install built helpers
+	nvidia-drivers_make_install modprobe
+	# allow video group to load mods and create devs (bug #505092)
+	fowners :video /usr/bin/nvidia-modprobe
+	fperms 4710 /usr/bin/nvidia-modprobe
+
+	nvidia-drivers_make_install persistenced
+	newconfd "${FILESDIR}/nvidia-persistenced.confd" nvidia-persistenced
+	newinitd "${FILESDIR}/nvidia-persistenced.initd" nvidia-persistenced
+	systemd_dounit nvidia-persistenced.service
+
+	use X && nvidia-drivers_make_install xconfig
+
+	if use tools; then
+		nvidia-drivers_make_install settings
+		doicon nvidia-settings/doc/nvidia-settings.png
+		domenu nvidia-settings/doc/nvidia-settings.desktop
+
+		insinto /usr/share/nvidia
+		newins nvidia-application-profiles{-${PV},}-key-documentation
+
+		exeinto /etc/X11/xinit/xinitrc.d
+		newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
+	fi
+
+	if use static-libs; then
+		dolib.a nvidia-settings/src/out/libXNVCtrl.a
+
+		insinto /usr/include/NVCtrl
+		doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
+	fi
+
+	# install prebuilt-only helpers
+	exeinto /opt/bin
+
+	doexe nvidia-cuda-mps-control
+	doman nvidia-cuda-mps-control.1
+	doexe nvidia-cuda-mps-server
+
+	doexe nvidia-debugdump
+	dobin nvidia-bug-report.sh
+
+	doexe nvidia-smi
+	doman nvidia-smi.1
+
+	# install prebuilt-only libraries
+	multilib_foreach_abi nvidia-drivers_libs_install
+
+	# install dlls for optional use with proton/wine
+	insinto /usr/$(get_libdir)/nvidia/wine
+	doins {_,}nvngx.dll
+
+	# install systemd sleep services
+	exeinto /lib/systemd/system-sleep
+	doexe systemd/system-sleep/nvidia
+	dobin systemd/nvidia-sleep.sh
+	systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend}.service
+
+	# create README.gentoo
+	local DISABLE_AUTOFORMATTING="yes"
+	local DOC_CONTENTS=\
+"Trusted users should be in the 'video' group to use NVIDIA devices.
+You can add yourself by using: gpasswd -a my-user video
+
+See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.
+
+For general information on using nvidia-drivers, please see:
+https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers"
+	readme.gentoo_create_doc
+
+	einstalldocs
+}
+
+pkg_preinst() {
+	has_version "${CATEGORY}/${PN}[abi_x86_32]" && NV_HAD_ABI32=1
+	has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=1
+
+	use driver || return
+	linux-mod_pkg_preinst
+
+	# set video group id based on live system (bug #491414)
+	local g=$(getent group video | cut -d: -f3)
+	[[ ${g} ]] || die "Failed to determine video group id"
+	sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
+
+	# try to find driver mismatches using temporary supported-gpus.json
+	for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
+		g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
+			"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
+		if [[ ${g} ]]; then
+			g=$((${g##*\"}+1))
+			if ver_test -ge ${g}; then
+				NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
+				break
+			fi
+		fi
+	done
+	rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
+}
+
+pkg_postinst() {
+	use driver && linux-mod_pkg_postinst
+
+	readme.gentoo_print_elog
+
+	if [[ -r /proc/driver/nvidia/version &&
+		$(grep -o '  [0-9.]*  ' /proc/driver/nvidia/version) != "  ${PV}  " ]]; then
+		ewarn "Currently loaded NVIDIA modules do not match the newly installed"
+		ewarn "libraries and will lead to GPU-using application issues."
+		use driver && ewarn "The easiest way to fix this is usually to reboot."
+	fi
+
+	if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
+		ewarn "Detected that the current kernel command line is using 'slub_debug=',"
+		ewarn "this may lead to system instability/freezes with this version of"
+		ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
+	fi
+
+	if [[ ${NV_LEGACY_MASK} ]]; then
+		ewarn "***WARNING***"
+		ewarn "You are installing a version of nvidia-drivers known not to work"
+		ewarn "with a GPU of the current system. If unwanted, add the mask:"
+		if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
+			ewarn "  echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
+		else
+			ewarn "  echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
+		fi
+		ewarn "...then downgrade to a legacy branch if possible. For details, see:"
+		ewarn "https://www.nvidia.com/object/IO_32667.html"
+	fi
+
+	if use !abi_x86_32 && [[ ${NV_HAD_ABI32} ]]; then
+		elog
+		elog "USE=abi_x86_32 is disabled, 32bit applications will not be able to"
+		elog "use nvidia-drivers for acceleration without it (e.g. commonly used"
+		elog "with app-emulation/wine-*). Re-enable if needed."
+	fi
+
+	if use wayland && use driver && [[ ! ${NV_HAD_WAYLAND} ]]; then
+		elog
+		elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
+		elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
+		elog "experimental but is required for EGLStream (used for wayland acceleration"
+		elog "in compositors that support it)."
+		elog
+		elog "If you experience issues, please comment out the option from nvidia.conf."
+		elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
+		if has_version "gnome-base/gdm[wayland]"; then
+			elog
+			elog "This also cause gnome-base/gdm to use a wayland session by default,"
+			elog "select 'GNOME on Xorg' if you wish to continue using it."
+		fi
+	fi
+
+	# Try to show this message only to users that may really need it
+	# given the workaround is discouraged and usage isn't widespread.
+	if use X && [[ ${REPLACING_VERSIONS} ]] &&
+		ver_test ${REPLACING_VERSIONS} -lt 460.73.01 &&
+		grep -qr Coolbits "${EROOT}"/etc/X11/{xorg.conf,xorg.conf.d/*.conf} 2>/dev/null; then
+		elog
+		elog "Coolbits support with ${PN} has been restricted to require Xorg"
+		elog "with root privilege by NVIDIA (being in video group is not sufficient)."
+		elog "e.g. attempting to change fan speed with nvidia-settings would fail."
+		elog
+		elog "Depending on your display manager (e.g. sddm starts X as root, gdm doesn't)"
+		elog "or if using startx, it may be necessary to emerge x11-base/xorg-server with"
+		elog 'USE="suid -elogind -systemd" if wish to keep using this feature.'
+		elog "Bug: https://bugs.gentoo.org/784248"
+	fi
+}