commit:     8c062caccf596d19a3c886901865309f567cdab4
Author:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
AuthorDate: Sun Jun  4 11:23:12 2023 +0000
Commit:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
CommitDate: Sun Jun  4 13:35:44 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8c062cac

x11-drivers/nvidia-drivers: migrate all remaining to linux-mod-r1

Bit of a risky move (stable), but given just did a revbump for
sandbox.d and that IUSE=+modules/+strip will cause a rebuild
as well, it makes some sense to do this at same time.

Migration did mostly prove itself with ~arch's 0/530 so far
and other notable modules are using the eclass already, and
no known issues. So let's hope.

*Should* have no real impact on users unless they were disabling
USE=driver given renamed to modules to match global IUSE, but
will fix asap if something else comes up.

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

 x11-drivers/nvidia-drivers/metadata.xml            |   1 -
 .../nvidia-drivers/nvidia-drivers-390.157.ebuild   | 130 +++--------------
 .../nvidia-drivers-470.182.03-r1.ebuild            | 133 +++---------------
 .../nvidia-drivers-515.105.01-r1.ebuild            | 151 +++++---------------
 .../nvidia-drivers-525.116.04-r1.ebuild            | 151 +++++---------------
 .../nvidia-drivers-525.47.26-r1.ebuild             | 153 +++++----------------
 .../nvidia-drivers-530.41.03-r1.ebuild             |   2 +-
 .../nvidia-drivers-535.43.02-r1.ebuild             |   2 +-
 8 files changed, 140 insertions(+), 583 deletions(-)

diff --git a/x11-drivers/nvidia-drivers/metadata.xml 
b/x11-drivers/nvidia-drivers/metadata.xml
index c62fb35fe442..04a446c9f79c 100644
--- a/x11-drivers/nvidia-drivers/metadata.xml
+++ b/x11-drivers/nvidia-drivers/metadata.xml
@@ -10,7 +10,6 @@
                <name>David Seifert</name>
        </maintainer>
        <use>
-               <flag name="driver">Install kernel driver modules</flag>
                <flag name="kernel-open">Use the open source variant of drivers 
(Turing/Ampere+ GPUs only, aka GTX 1650+, very experimental)</flag>
                <flag name="persistenced">Install the persistence daemon for 
keeping devices state when unused (e.g. for headless)</flag>
                <flag name="static-libs">Install the XNVCtrl static library for 
accessing sensors and other features</flag>

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-390.157.ebuild 
b/x11-drivers/nvidia-drivers/nvidia-drivers-390.157.ebuild
index 3f4ed7b4373b..3cef13920232 100644
--- a/x11-drivers/nvidia-drivers/nvidia-drivers-390.157.ebuild
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-390.157.ebuild
@@ -3,11 +3,11 @@
 
 EAPI=8
 
-MODULES_OPTIONAL_USE="driver"
-inherit desktop flag-o-matic linux-mod multilib readme.gentoo-r1 \
-       systemd toolchain-funcs unpacker user-info
+MODULES_OPTIONAL_IUSE=+modules
+inherit desktop flag-o-matic linux-mod-r1 multilib readme.gentoo-r1
+inherit systemd toolchain-funcs unpacker user-info
 
-NV_KERNEL_MAX="6.1"
+MODULES_KERNEL_MAX=6.1
 NV_URI="https://download.nvidia.com/XFree86/";
 
 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
@@ -23,7 +23,7 @@ S="${WORKDIR}"
 LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT"
 SLOT="0/${PV%%.*}"
 KEYWORDS="-* amd64 x86"
-IUSE="+X abi_x86_32 abi_x86_64 +driver persistenced +static-libs +tools"
+IUSE="+X abi_x86_32 abi_x86_64 persistenced +static-libs +tools"
 
 COMMON_DEPEND="
        acct-group/video
@@ -81,7 +81,7 @@ PATCHES=(
 )
 
 pkg_setup() {
-       use driver || return
+       use modules && [[ ${MERGE_TYPE} != binary ]] || return
 
        local CONFIG_CHECK="
                PROC_FS
@@ -102,15 +102,7 @@ pkg_setup() {
 
        kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
 
-       MODULE_NAMES="
-               nvidia(video:kernel)
-               nvidia-drm(video:kernel)
-               nvidia-modeset(video:kernel)
-               $(usev !x86 "nvidia-uvm(video:kernel)")"
-
-       linux-mod_pkg_setup
-
-       [[ ${MERGE_TYPE} == binary ]] && return
+       linux-mod-r1_pkg_setup
 
        # do some extra checks manually as it gets messy to handle builtin-only
        # and some other conditional checks through CONFIG_CHECK
@@ -174,77 +166,6 @@ pkg_setup() {
 
        (( ${#warn[@]} )) &&
                ewarn "Detected potential configuration issues with used 
kernel:${warn[*]/#/$'\n'}"
-
-       BUILD_PARAMS='NV_VERBOSE=1 IGNORE_CC_MISMATCH=yes SYSSRC="${KV_DIR}" 
SYSOUT="${KV_OUT_DIR}"'
-       use x86 && BUILD_PARAMS+=' ARCH=i386'
-       BUILD_TARGETS="modules"
-
-       # Try to match toolchain with kernel only for modules
-       # (experimental, ideally this should be handled in linux-mod.eclass)
-       nvidia-tc-set() {
-               local -n var=KERNEL_${1}
-               if [[ ! -v var ]]; then
-                       read -r var < <(type -P "${@:2}") ||
-                               die "failed to find in PATH at least one of: 
${*:2}"
-                       einfo "Forcing '${var}' for modules (set ${!var} to 
override)"
-               fi
-       }
-
-       local tool switch
-       if linux_chkconfig_present CC_IS_GCC; then
-               if ! tc-is-gcc; then
-                       switch=
-                       nvidia-tc-set CC {${CHOST}-,}gcc
-               fi
-       elif linux_chkconfig_present CC_IS_CLANG; then
-               ewarn "Warning: using ${PN} with a clang-built kernel is 
largely untested"
-               if ! tc-is-clang; then
-                       switch=llvm-
-                       nvidia-tc-set CC {${CHOST}-,}clang
-               fi
-       fi
-
-       if linux_chkconfig_present LD_IS_BFD; then
-               # tc-ld-is-bfd needs https://github.com/gentoo/gentoo/pull/28355
-               [[ $(LC_ALL=C $(tc-getLD) --version 2>/dev/null) == "GNU ld"* 
]] ||
-                       nvidia-tc-set LD {${CHOST}-,}{ld.bfd,ld}
-       elif linux_chkconfig_present LD_IS_LLD; then
-               tc-ld-is-lld || nvidia-tc-set LD {${CHOST}-,}{ld.lld,lld}
-       fi
-
-       if [[ -v switch ]]; then
-               # only need llvm-nm for lto, but use complete set to be safe
-               for tool in AR NM OBJCOPY OBJDUMP READELF STRIP; do
-                       case $(LC_ALL=C $(tc-get${tool}) --version 2>/dev/null) 
in
-                               LLVM*|llvm*) [[ ! ${switch} ]];;
-                               *) [[ ${switch} ]];;
-                       esac && nvidia-tc-set ${tool} 
{${CHOST}-,}${switch}${tool,,}
-               done
-       fi
-
-       # pass unconditionally given exports are semi-ignored except CC/LD
-       for tool in CC LD AR NM OBJCOPY OBJDUMP READELF STRIP; do
-               BUILD_PARAMS+=" 
${tool}=\"\${KERNEL_${tool}:-\$(tc-get${tool})}\""
-       done
-
-       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
-
-       if kernel_is -gt ${NV_KERNEL_MAX/./ }; then
-               ewarn "Kernel ${KV_MAJOR}.${KV_MINOR} is known to break this 
version ${PN}"
-               ewarn "It is recommended to use one of:"
-               ewarn "  <=sys-kernel/gentoo-kernel-${NV_KERNEL_MAX}.x"
-               ewarn "  <=sys-kernel/gentoo-sources-${NV_KERNEL_MAX}.x"
-               ewarn "You are free to try or use /etc/portage/patches, but 
support will"
-               ewarn "not be given (Gentoo will not accept patches for this). 
When no"
-               ewarn "supported kernel are usable anymore, end-of-life 390.xx 
will be"
-               ewarn "removed -- 6.1.x LTS will be supported until at least 
December 2026."
-               ewarn
-               ewarn "Do _not_ file a bug report if run into issues."
-               ewarn
-       fi
 }
 
 src_prepare() {
@@ -287,24 +208,14 @@ src_compile() {
                NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
        )
 
-       if use driver; then
-               if linux_chkconfig_present GCC_PLUGINS; then
-                       mkdir "${T}"/plugin-test || die
-                       echo "obj-m += test.o" > "${T}"/plugin-test/Kbuild || 
die
-                       :> "${T}"/plugin-test/test.c || die
-                       if [[ $(LC_ALL=C make -C "${KV_OUT_DIR}" 
ARCH="$(tc-arch-kernel)" \
-                               HOSTCC="$(tc-getBUILD_CC)" CC="${CC}" 
M="${T}"/plugin-test 2>&1) \
-                               =~ "error: incompatible gcc/plugin version" ]]
-                       then
-                               eerror "Detected kernel was built with a 
different gcc/plugin version,"
-                               eerror "Please 'make clean' and rebuild your 
kernel with the current"
-                               eerror "gcc (or re-emerge for distribution 
kernels, including kernel-bin)."
-                               die "kernel ${KV_FULL} needs to be rebuilt"
-                       fi
-               fi
+       local modlist=( nvidia{,-drm,-modeset}=video:kernel )
+       use x86 || modlist+=( nvidia-uvm=video:kernel )
+       local modargs=(
+               IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
+               SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
+       )
 
-               linux-mod_src_compile
-       fi
+       linux-mod-r1_src_compile
 
        if use persistenced; then
                # 390.xx persistenced does not auto-detect libtirpc
@@ -377,7 +288,7 @@ src_install() {
        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\
-$(usev driver "
+$(usev modules "
 
 Like all out-of-tree kernel modules, it is necessary to rebuild
 ${PN} after upgrading or rebuilding the Linux kernel
@@ -419,8 +330,8 @@ For general information on using ${PN}, please see:
 https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
        readme.gentoo_create_doc
 
-       if use driver; then
-               linux-mod_src_install
+       if use modules; then
+               linux-mod-r1_src_install
 
                insinto /etc/modprobe.d
                newins "${FILESDIR}"/nvidia-390.conf nvidia.conf
@@ -528,8 +439,7 @@ https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
 }
 
 pkg_preinst() {
-       use driver || return
-       linux-mod_pkg_preinst
+       use modules || return
 
        # set video group id based on live system (bug #491414)
        local g=$(egetent group video | cut -d: -f3)
@@ -538,7 +448,7 @@ pkg_preinst() {
 }
 
 pkg_postinst() {
-       linux-mod_pkg_postinst
+       linux-mod-r1_pkg_postinst
 
        readme.gentoo_print_elog
 
@@ -546,7 +456,7 @@ pkg_postinst() {
                $(</proc/driver/nvidia/version) != *"  ${PV}  "* ]]; then
                ewarn "Currently loaded NVIDIA modules do not match the newly 
installed"
                ewarn "libraries and may prevent launching GPU-accelerated 
applications."
-               use driver && ewarn "The easiest way to fix this is usually to 
reboot."
+               use modules && ewarn "The easiest way to fix this is usually to 
reboot."
        fi
 
        ewarn

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-470.182.03-r1.ebuild 
b/x11-drivers/nvidia-drivers/nvidia-drivers-470.182.03-r1.ebuild
index e9d5a5757f02..133a3e8f047f 100644
--- a/x11-drivers/nvidia-drivers/nvidia-drivers-470.182.03-r1.ebuild
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-470.182.03-r1.ebuild
@@ -3,11 +3,11 @@
 
 EAPI=8
 
-MODULES_OPTIONAL_USE="driver"
-inherit desktop flag-o-matic linux-mod multilib readme.gentoo-r1 \
-       systemd toolchain-funcs unpacker user-info
+MODULES_OPTIONAL_IUSE=+modules
+inherit desktop flag-o-matic linux-mod-r1 multilib readme.gentoo-r1
+inherit systemd toolchain-funcs unpacker user-info
 
-NV_KERNEL_MAX="6.2"
+MODULES_KERNEL_MAX=6.2
 NV_URI="https://download.nvidia.com/XFree86/";
 
 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
@@ -22,7 +22,7 @@ S="${WORKDIR}"
 LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
 SLOT="0/${PV%%.*}"
 KEYWORDS="-* amd64"
-IUSE="+X abi_x86_32 abi_x86_64 +driver persistenced +static-libs +tools 
wayland"
+IUSE="+X abi_x86_32 abi_x86_64 persistenced +static-libs +tools wayland"
 
 COMMON_DEPEND="
        acct-group/video
@@ -84,7 +84,7 @@ PATCHES=(
 )
 
 pkg_setup() {
-       use driver || return
+       use modules && [[ ${MERGE_TYPE} != binary ]] || return
 
        local CONFIG_CHECK="
                PROC_FS
@@ -106,16 +106,7 @@ pkg_setup() {
 
        use amd64 && 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
+       linux-mod-r1_pkg_setup
 
        # do some extra checks manually as it gets messy to handle builtin-only
        # and some other conditional checks through CONFIG_CHECK
@@ -179,75 +170,6 @@ pkg_setup() {
 
        (( ${#warn[@]} )) &&
                ewarn "Detected potential configuration issues with used 
kernel:${warn[*]/#/$'\n'}"
-
-       BUILD_PARAMS='NV_VERBOSE=1 IGNORE_CC_MISMATCH=yes SYSSRC="${KV_DIR}" 
SYSOUT="${KV_OUT_DIR}"'
-       BUILD_TARGETS="modules"
-
-       # Try to match toolchain with kernel only for modules
-       # (experimental, ideally this should be handled in linux-mod.eclass)
-       nvidia-tc-set() {
-               local -n var=KERNEL_${1}
-               if [[ ! -v var ]]; then
-                       read -r var < <(type -P "${@:2}") ||
-                               die "failed to find in PATH at least one of: 
${*:2}"
-                       einfo "Forcing '${var}' for modules (set ${!var} to 
override)"
-               fi
-       }
-
-       local tool switch
-       if linux_chkconfig_present CC_IS_GCC; then
-               if ! tc-is-gcc; then
-                       switch=
-                       nvidia-tc-set CC {${CHOST}-,}gcc
-               fi
-       elif linux_chkconfig_present CC_IS_CLANG; then
-               ewarn "Warning: using ${PN} with a clang-built kernel is 
largely untested"
-               if ! tc-is-clang; then
-                       switch=llvm-
-                       nvidia-tc-set CC {${CHOST}-,}clang
-               fi
-       fi
-
-       if linux_chkconfig_present LD_IS_BFD; then
-               # tc-ld-is-bfd needs https://github.com/gentoo/gentoo/pull/28355
-               [[ $(LC_ALL=C $(tc-getLD) --version 2>/dev/null) == "GNU ld"* 
]] ||
-                       nvidia-tc-set LD {${CHOST}-,}{ld.bfd,ld}
-       elif linux_chkconfig_present LD_IS_LLD; then
-               tc-ld-is-lld || nvidia-tc-set LD {${CHOST}-,}{ld.lld,lld}
-       fi
-
-       if [[ -v switch ]]; then
-               # only need llvm-nm for lto, but use complete set to be safe
-               for tool in AR NM OBJCOPY OBJDUMP READELF STRIP; do
-                       case $(LC_ALL=C $(tc-get${tool}) --version 2>/dev/null) 
in
-                               LLVM*|llvm*) [[ ! ${switch} ]];;
-                               *) [[ ${switch} ]];;
-                       esac && nvidia-tc-set ${tool} 
{${CHOST}-,}${switch}${tool,,}
-               done
-       fi
-
-       # pass unconditionally given exports are semi-ignored except CC/LD
-       for tool in CC LD AR NM OBJCOPY OBJDUMP READELF STRIP; do
-               BUILD_PARAMS+=" 
${tool}=\"\${KERNEL_${tool}:-\$(tc-get${tool})}\""
-       done
-
-       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
-
-       if kernel_is -gt ${NV_KERNEL_MAX/./ }; then
-               ewarn "Kernel ${KV_MAJOR}.${KV_MINOR} is either known to break 
this version of ${PN}"
-               ewarn "or was not tested with it. It is recommended to use one 
of:"
-               ewarn "  <=sys-kernel/gentoo-kernel-${NV_KERNEL_MAX}.x"
-               ewarn "  <=sys-kernel/gentoo-sources-${NV_KERNEL_MAX}.x"
-               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 "(Gentoo will not accept patches for this)."
-               ewarn
-               ewarn "Do _not_ file a bug report if run into issues."
-               ewarn
-       fi
 }
 
 src_prepare() {
@@ -289,25 +211,13 @@ src_compile() {
                XNVCTRL_CFLAGS="${xnvflags}"
        )
 
-       if use driver; then
-               if linux_chkconfig_present GCC_PLUGINS; then
-                       mkdir "${T}"/plugin-test || die
-                       echo "obj-m += test.o" > "${T}"/plugin-test/Kbuild || 
die
-                       :> "${T}"/plugin-test/test.c || die
-                       if [[ $(LC_ALL=C make -C "${KV_OUT_DIR}" 
ARCH="$(tc-arch-kernel)" \
-                               HOSTCC="$(tc-getBUILD_CC)" CC="${CC}" 
M="${T}"/plugin-test 2>&1) \
-                               =~ "error: incompatible gcc/plugin version" ]]
-                       then
-                               eerror "Detected kernel was built with a 
different gcc/plugin version,"
-                               eerror "Please 'make clean' and rebuild your 
kernel with the current"
-                               eerror "gcc (or re-emerge for distribution 
kernels, including kernel-bin)."
-                               die "kernel ${KV_FULL} needs to be rebuilt"
-                       fi
-               fi
-
-               linux-mod_src_compile
-       fi
+       local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=video:kernel )
+       local modargs=(
+               IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
+               SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
+       )
 
+       linux-mod-r1_src_compile
        emake "${NV_ARGS[@]}" -C nvidia-modprobe
        use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
        use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
@@ -354,7 +264,7 @@ src_install() {
        )
        local skip_modules=(
                $(usev !X "nvfbc vdpau xdriver")
-               $(usev !driver gsp)
+               $(usev !modules gsp)
                installer nvpd # handled separately / built from source
        )
        local skip_types=(
@@ -374,7 +284,7 @@ src_install() {
        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\
-$(usev driver "
+$(usev modules "
 
 Like all out-of-tree kernel modules, it is necessary to rebuild
 ${PN} after upgrading or rebuilding the Linux kernel
@@ -398,8 +308,8 @@ For general information on using ${PN}, please see:
 https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
        readme.gentoo_create_doc
 
-       if use driver; then
-               linux-mod_src_install
+       if use modules; then
+               linux-mod-r1_src_install
 
                insinto /etc/modprobe.d
                doins "${T}"/nvidia.conf
@@ -512,8 +422,7 @@ https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
 pkg_preinst() {
        has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
 
-       use driver || return
-       linux-mod_pkg_preinst
+       use modules || return
 
        # set video group id based on live system (bug #491414)
        local g=$(egetent group video | cut -d: -f3)
@@ -536,7 +445,7 @@ pkg_preinst() {
 }
 
 pkg_postinst() {
-       linux-mod_pkg_postinst
+       linux-mod-r1_pkg_postinst
 
        readme.gentoo_print_elog
 
@@ -544,7 +453,7 @@ pkg_postinst() {
                $(</proc/driver/nvidia/version) != *"  ${PV}  "* ]]; then
                ewarn "Currently loaded NVIDIA modules do not match the newly 
installed"
                ewarn "libraries and may prevent launching GPU-accelerated 
applications."
-               use driver && ewarn "The easiest way to fix this is usually to 
reboot."
+               use modules && ewarn "The easiest way to fix this is usually to 
reboot."
        fi
 
        if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
@@ -570,7 +479,7 @@ pkg_postinst() {
                ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau";
        fi
 
-       if use wayland && use driver && [[ ! -v NV_HAD_WAYLAND ]]; then
+       if use wayland && use modules && [[ ! -v 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"

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-515.105.01-r1.ebuild 
b/x11-drivers/nvidia-drivers/nvidia-drivers-515.105.01-r1.ebuild
index 50175f4e17e3..2a3914adf383 100644
--- a/x11-drivers/nvidia-drivers/nvidia-drivers-515.105.01-r1.ebuild
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-515.105.01-r1.ebuild
@@ -3,11 +3,11 @@
 
 EAPI=8
 
-MODULES_OPTIONAL_USE="driver"
-inherit desktop flag-o-matic linux-mod multilib readme.gentoo-r1 \
-       systemd toolchain-funcs unpacker user-info
+MODULES_OPTIONAL_IUSE=+modules
+inherit desktop flag-o-matic linux-mod-r1 multilib readme.gentoo-r1
+inherit systemd toolchain-funcs unpacker user-info
 
-NV_KERNEL_MAX="6.2"
+MODULES_KERNEL_MAX=6.2
 NV_URI="https://download.nvidia.com/XFree86/";
 
 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
@@ -24,8 +24,8 @@ S="${WORKDIR}"
 LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
 SLOT="0/${PV%%.*}"
 KEYWORDS="-* amd64 ~arm64"
-IUSE="+X abi_x86_32 abi_x86_64 +driver kernel-open persistenced +static-libs 
+tools wayland"
-REQUIRED_USE="kernel-open? ( driver )"
+IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced +static-libs +tools 
wayland"
+REQUIRED_USE="kernel-open? ( modules )"
 
 COMMON_DEPEND="
        acct-group/video
@@ -90,7 +90,7 @@ PATCHES=(
 )
 
 pkg_setup() {
-       use driver || return
+       use modules && [[ ${MERGE_TYPE} != binary ]] || return
 
        local CONFIG_CHECK="
                PROC_FS
@@ -116,18 +116,7 @@ pkg_setup() {
        Cannot be directly selected in the kernel's menuconfig, and may need
        selection of another option that requires it such as CONFIG_KVM."
 
-       MODULE_NAMES="
-               nvidia(video:kernel)
-               nvidia-drm(video:kernel)
-               nvidia-modeset(video:kernel)
-               nvidia-peermem(video:kernel)
-               nvidia-uvm(video:kernel)"
-       use kernel-open &&
-               
MODULE_NAMES=${MODULE_NAMES//:kernel/:kernel-module-source:kernel-module-source/kernel-open}
-
-       linux-mod_pkg_setup
-
-       [[ ${MERGE_TYPE} == binary ]] && return
+       linux-mod-r1_pkg_setup
 
        # do some extra checks manually as it gets messy to handle builtin-only
        # and some other conditional checks through CONFIG_CHECK
@@ -191,77 +180,6 @@ pkg_setup() {
 
        (( ${#warn[@]} )) &&
                ewarn "Detected potential configuration issues with used 
kernel:${warn[*]/#/$'\n'}"
-
-       BUILD_PARAMS='NV_VERBOSE=1 IGNORE_CC_MISMATCH=yes SYSSRC="${KV_DIR}" 
SYSOUT="${KV_OUT_DIR}"'
-       BUILD_TARGETS="modules"
-
-       # Try to match toolchain with kernel only for modules
-       # (experimental, ideally this should be handled in linux-mod.eclass)
-       nvidia-tc-set() {
-               local -n var=KERNEL_${1}
-               if [[ ! -v var ]]; then
-                       read -r var < <(type -P "${@:2}") ||
-                               die "failed to find in PATH at least one of: 
${*:2}"
-                       einfo "Forcing '${var}' for modules (set ${!var} to 
override)"
-               fi
-       }
-
-       local tool switch
-       if linux_chkconfig_present CC_IS_GCC; then
-               if ! tc-is-gcc; then
-                       switch=
-                       nvidia-tc-set CC {${CHOST}-,}gcc
-                       nvidia-tc-set CXX {${CHOST}-,}g++ # needed by 
kernel-open
-               fi
-       elif linux_chkconfig_present CC_IS_CLANG; then
-               ewarn "Warning: using ${PN} with a clang-built kernel is 
largely untested"
-               if ! tc-is-clang; then
-                       switch=llvm-
-                       nvidia-tc-set CC {${CHOST}-,}clang
-                       nvidia-tc-set CXX {${CHOST}-,}clang++
-               fi
-       fi
-
-       if linux_chkconfig_present LD_IS_BFD; then
-               # tc-ld-is-bfd needs https://github.com/gentoo/gentoo/pull/28355
-               [[ $(LC_ALL=C $(tc-getLD) --version 2>/dev/null) == "GNU ld"* 
]] ||
-                       nvidia-tc-set LD {${CHOST}-,}{ld.bfd,ld}
-       elif linux_chkconfig_present LD_IS_LLD; then
-               tc-ld-is-lld || nvidia-tc-set LD {${CHOST}-,}{ld.lld,lld}
-       fi
-
-       if [[ -v switch ]]; then
-               # only need llvm-nm for lto, but use complete set to be safe
-               for tool in AR NM OBJCOPY OBJDUMP READELF STRIP; do
-                       case $(LC_ALL=C $(tc-get${tool}) --version 2>/dev/null) 
in
-                               LLVM*|llvm*) [[ ! ${switch} ]];;
-                               *) [[ ${switch} ]];;
-                       esac && nvidia-tc-set ${tool} 
{${CHOST}-,}${switch}${tool,,}
-               done
-       fi
-
-       # pass unconditionally given exports are semi-ignored except CC/LD
-       for tool in CC CXX LD AR NM OBJCOPY OBJDUMP READELF STRIP; do
-               BUILD_PARAMS+=" 
${tool}=\"\${KERNEL_${tool}:-\$(tc-get${tool})}\""
-       done
-
-       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
-
-       if kernel_is -gt ${NV_KERNEL_MAX/./ }; then
-               ewarn "Kernel ${KV_MAJOR}.${KV_MINOR} is either known to break 
this version of ${PN}"
-               ewarn "or was not tested with it. It is recommended to use one 
of:"
-               ewarn "  <=sys-kernel/gentoo-kernel-${NV_KERNEL_MAX}.x"
-               ewarn "  <=sys-kernel/gentoo-sources-${NV_KERNEL_MAX}.x"
-               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 "(Gentoo will not accept patches for this)."
-               ewarn
-               ewarn "Do _not_ file a bug report if run into issues."
-               ewarn
-       fi
 }
 
 src_prepare() {
@@ -321,30 +239,26 @@ src_compile() {
                XNVCTRL_CFLAGS="${xnvflags}"
        )
 
-       if use driver; then
-               if linux_chkconfig_present GCC_PLUGINS; then
-                       mkdir "${T}"/plugin-test || die
-                       echo "obj-m += test.o" > "${T}"/plugin-test/Kbuild || 
die
-                       :> "${T}"/plugin-test/test.c || die
-                       if [[ $(LC_ALL=C make -C "${KV_OUT_DIR}" 
ARCH="$(tc-arch-kernel)" \
-                               HOSTCC="$(tc-getBUILD_CC)" CC="${CC}" 
M="${T}"/plugin-test 2>&1) \
-                               =~ "error: incompatible gcc/plugin version" ]]
-                       then
-                               eerror "Detected kernel was built with a 
different gcc/plugin version,"
-                               eerror "Please 'make clean' and rebuild your 
kernel with the current"
-                               eerror "gcc (or re-emerge for distribution 
kernels, including kernel-bin)."
-                               die "kernel ${KV_FULL} needs to be rebuilt"
-                       fi
-               fi
-
+       if use modules; then
                local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} 
o_ldflags=${LDFLAGS}
+
+               local modlistargs=video:kernel
                if use kernel-open; then
-                       # building the nvidia "blob" fails with lto, and also 
need
-                       # to strip in case of a different toolchain for the 
kernel
+                       
modlistargs+=-module-source:kernel-module-source/kernel-open
+
+                       # environment flags are normally unused for modules, 
but nvidia
+                       # uses it for building the "blob" and it is a bit 
fragile
                        filter-lto
-                       strip-unsupported-flags
+                       CC=${KERNEL_CC} CXX=${KERNEL_CXX} 
strip-unsupported-flags
                fi
-               linux-mod_src_compile
+
+               local modlist=( 
nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
+               local modargs=(
+                       IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
+                       SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
+               )
+
+               linux-mod-r1_src_compile
                CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
        fi
 
@@ -395,7 +309,7 @@ src_install() {
        )
        local skip_modules=(
                $(usev !X "nvfbc vdpau xdriver")
-               $(usev !driver gsp)
+               $(usev !modules gsp)
                installer nvpd # handled separately / built from source
        )
        local skip_types=(
@@ -415,7 +329,7 @@ src_install() {
        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\
-$(usev driver "
+$(usev modules "
 
 Like all out-of-tree kernel modules, it is necessary to rebuild
 ${PN} after upgrading or rebuilding the Linux kernel
@@ -439,8 +353,8 @@ For general information on using ${PN}, please see:
 https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
        readme.gentoo_create_doc
 
-       if use driver; then
-               linux-mod_src_install
+       if use modules; then
+               linux-mod-r1_src_install
 
                insinto /etc/modprobe.d
                doins "${T}"/nvidia.conf
@@ -562,8 +476,7 @@ https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
 pkg_preinst() {
        has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
 
-       use driver || return
-       linux-mod_pkg_preinst
+       use modules || return
 
        # set video group id based on live system (bug #491414)
        local g=$(egetent group video | cut -d: -f3)
@@ -586,7 +499,7 @@ pkg_preinst() {
 }
 
 pkg_postinst() {
-       linux-mod_pkg_postinst
+       linux-mod-r1_pkg_postinst
 
        readme.gentoo_print_elog
 
@@ -594,7 +507,7 @@ pkg_postinst() {
                $(</proc/driver/nvidia/version) != *"  ${PV}  "* ]]; then
                ewarn "Currently loaded NVIDIA modules do not match the newly 
installed"
                ewarn "libraries and may prevent launching GPU-accelerated 
applications."
-               use driver && ewarn "The easiest way to fix this is usually to 
reboot."
+               use modules && ewarn "The easiest way to fix this is usually to 
reboot."
        fi
 
        if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
@@ -631,7 +544,7 @@ pkg_postinst() {
                ewarn "Switch back to USE=-kernel-open to restore functionality 
if needed for now."
        fi
 
-       if use wayland && use driver && [[ ! -v NV_HAD_WAYLAND ]]; then
+       if use wayland && use modules && [[ ! -v 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"

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-525.116.04-r1.ebuild 
b/x11-drivers/nvidia-drivers/nvidia-drivers-525.116.04-r1.ebuild
index ce05c7a71043..d27670a866f3 100644
--- a/x11-drivers/nvidia-drivers/nvidia-drivers-525.116.04-r1.ebuild
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-525.116.04-r1.ebuild
@@ -3,11 +3,11 @@
 
 EAPI=8
 
-MODULES_OPTIONAL_USE="driver"
-inherit desktop flag-o-matic linux-mod multilib readme.gentoo-r1 \
-       systemd toolchain-funcs unpacker user-info
+MODULES_OPTIONAL_IUSE=+modules
+inherit desktop flag-o-matic linux-mod-r1 multilib readme.gentoo-r1
+inherit systemd toolchain-funcs unpacker user-info
 
-NV_KERNEL_MAX="6.3"
+MODULES_KERNEL_MAX=6.3
 NV_URI="https://download.nvidia.com/XFree86/";
 
 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
@@ -24,8 +24,8 @@ S="${WORKDIR}"
 LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
 SLOT="0/${PV%%.*}"
 KEYWORDS="-* amd64 ~arm64"
-IUSE="+X abi_x86_32 abi_x86_64 +driver kernel-open persistenced +static-libs 
+tools wayland"
-REQUIRED_USE="kernel-open? ( driver )"
+IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced +static-libs +tools 
wayland"
+REQUIRED_USE="kernel-open? ( modules )"
 
 COMMON_DEPEND="
        acct-group/video
@@ -88,7 +88,7 @@ PATCHES=(
 )
 
 pkg_setup() {
-       use driver || return
+       use modules && [[ ${MERGE_TYPE} != binary ]] || return
 
        local CONFIG_CHECK="
                PROC_FS
@@ -114,18 +114,7 @@ pkg_setup() {
        Cannot be directly selected in the kernel's menuconfig, and may need
        selection of another option that requires it such as CONFIG_KVM."
 
-       MODULE_NAMES="
-               nvidia(video:kernel)
-               nvidia-drm(video:kernel)
-               nvidia-modeset(video:kernel)
-               nvidia-peermem(video:kernel)
-               nvidia-uvm(video:kernel)"
-       use kernel-open &&
-               
MODULE_NAMES=${MODULE_NAMES//:kernel/:kernel-module-source:kernel-module-source/kernel-open}
-
-       linux-mod_pkg_setup
-
-       [[ ${MERGE_TYPE} == binary ]] && return
+       linux-mod-r1_pkg_setup
 
        # do some extra checks manually as it gets messy to handle builtin-only
        # and some other conditional checks through CONFIG_CHECK
@@ -189,77 +178,6 @@ pkg_setup() {
 
        (( ${#warn[@]} )) &&
                ewarn "Detected potential configuration issues with used 
kernel:${warn[*]/#/$'\n'}"
-
-       BUILD_PARAMS='NV_VERBOSE=1 IGNORE_CC_MISMATCH=yes SYSSRC="${KV_DIR}" 
SYSOUT="${KV_OUT_DIR}"'
-       BUILD_TARGETS="modules"
-
-       # Try to match toolchain with kernel only for modules
-       # (experimental, ideally this should be handled in linux-mod.eclass)
-       nvidia-tc-set() {
-               local -n var=KERNEL_${1}
-               if [[ ! -v var ]]; then
-                       read -r var < <(type -P "${@:2}") ||
-                               die "failed to find in PATH at least one of: 
${*:2}"
-                       einfo "Forcing '${var}' for modules (set ${!var} to 
override)"
-               fi
-       }
-
-       local tool switch
-       if linux_chkconfig_present CC_IS_GCC; then
-               if ! tc-is-gcc; then
-                       switch=
-                       nvidia-tc-set CC {${CHOST}-,}gcc
-                       nvidia-tc-set CXX {${CHOST}-,}g++ # needed by 
kernel-open
-               fi
-       elif linux_chkconfig_present CC_IS_CLANG; then
-               ewarn "Warning: using ${PN} with a clang-built kernel is 
largely untested"
-               if ! tc-is-clang; then
-                       switch=llvm-
-                       nvidia-tc-set CC {${CHOST}-,}clang
-                       nvidia-tc-set CXX {${CHOST}-,}clang++
-               fi
-       fi
-
-       if linux_chkconfig_present LD_IS_BFD; then
-               # tc-ld-is-bfd needs https://github.com/gentoo/gentoo/pull/28355
-               [[ $(LC_ALL=C $(tc-getLD) --version 2>/dev/null) == "GNU ld"* 
]] ||
-                       nvidia-tc-set LD {${CHOST}-,}{ld.bfd,ld}
-       elif linux_chkconfig_present LD_IS_LLD; then
-               tc-ld-is-lld || nvidia-tc-set LD {${CHOST}-,}{ld.lld,lld}
-       fi
-
-       if [[ -v switch ]]; then
-               # only need llvm-nm for lto, but use complete set to be safe
-               for tool in AR NM OBJCOPY OBJDUMP READELF STRIP; do
-                       case $(LC_ALL=C $(tc-get${tool}) --version 2>/dev/null) 
in
-                               LLVM*|llvm*) [[ ! ${switch} ]];;
-                               *) [[ ${switch} ]];;
-                       esac && nvidia-tc-set ${tool} 
{${CHOST}-,}${switch}${tool,,}
-               done
-       fi
-
-       # pass unconditionally given exports are semi-ignored except CC/LD
-       for tool in CC CXX LD AR NM OBJCOPY OBJDUMP READELF STRIP; do
-               BUILD_PARAMS+=" 
${tool}=\"\${KERNEL_${tool}:-\$(tc-get${tool})}\""
-       done
-
-       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
-
-       if kernel_is -gt ${NV_KERNEL_MAX/./ }; then
-               ewarn "Kernel ${KV_MAJOR}.${KV_MINOR} is either known to break 
this version of ${PN}"
-               ewarn "or was not tested with it. It is recommended to use one 
of:"
-               ewarn "  <=sys-kernel/gentoo-kernel-${NV_KERNEL_MAX}.x"
-               ewarn "  <=sys-kernel/gentoo-sources-${NV_KERNEL_MAX}.x"
-               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 "(Gentoo will not accept patches for this)."
-               ewarn
-               ewarn "Do _not_ file a bug report if run into issues."
-               ewarn
-       fi
 }
 
 src_prepare() {
@@ -317,30 +235,26 @@ src_compile() {
                XNVCTRL_CFLAGS="${xnvflags}"
        )
 
-       if use driver; then
-               if linux_chkconfig_present GCC_PLUGINS; then
-                       mkdir "${T}"/plugin-test || die
-                       echo "obj-m += test.o" > "${T}"/plugin-test/Kbuild || 
die
-                       :> "${T}"/plugin-test/test.c || die
-                       if [[ $(LC_ALL=C make -C "${KV_OUT_DIR}" 
ARCH="$(tc-arch-kernel)" \
-                               HOSTCC="$(tc-getBUILD_CC)" CC="${CC}" 
M="${T}"/plugin-test 2>&1) \
-                               =~ "error: incompatible gcc/plugin version" ]]
-                       then
-                               eerror "Detected kernel was built with a 
different gcc/plugin version,"
-                               eerror "Please 'make clean' and rebuild your 
kernel with the current"
-                               eerror "gcc (or re-emerge for distribution 
kernels, including kernel-bin)."
-                               die "kernel ${KV_FULL} needs to be rebuilt"
-                       fi
-               fi
-
+       if use modules; then
                local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} 
o_ldflags=${LDFLAGS}
+
+               local modlistargs=video:kernel
                if use kernel-open; then
-                       # building the nvidia "blob" fails with lto, and also 
need
-                       # to strip in case of a different toolchain for the 
kernel
+                       
modlistargs+=-module-source:kernel-module-source/kernel-open
+
+                       # environment flags are normally unused for modules, 
but nvidia
+                       # uses it for building the "blob" and it is a bit 
fragile
                        filter-lto
-                       strip-unsupported-flags
+                       CC=${KERNEL_CC} CXX=${KERNEL_CXX} 
strip-unsupported-flags
                fi
-               linux-mod_src_compile
+
+               local modlist=( 
nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
+               local modargs=(
+                       IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
+                       SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
+               )
+
+               linux-mod-r1_src_compile
                CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
        fi
 
@@ -393,7 +307,7 @@ src_install() {
        )
        local skip_modules=(
                $(usev !X "nvfbc vdpau xdriver")
-               $(usev !driver gsp)
+               $(usev !modules gsp)
                installer nvpd # handled separately / built from source
        )
        local skip_types=(
@@ -413,7 +327,7 @@ src_install() {
        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\
-$(usev driver "
+$(usev modules "
 
 Like all out-of-tree kernel modules, it is necessary to rebuild
 ${PN} after upgrading or rebuilding the Linux kernel
@@ -437,8 +351,8 @@ For general information on using ${PN}, please see:
 https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
        readme.gentoo_create_doc
 
-       if use driver; then
-               linux-mod_src_install
+       if use modules; then
+               linux-mod-r1_src_install
 
                insinto /etc/modprobe.d
                doins "${T}"/nvidia.conf
@@ -560,8 +474,7 @@ https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
 pkg_preinst() {
        has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
 
-       use driver || return
-       linux-mod_pkg_preinst
+       use modules || return
 
        # set video group id based on live system (bug #491414)
        local g=$(egetent group video | cut -d: -f3)
@@ -584,7 +497,7 @@ pkg_preinst() {
 }
 
 pkg_postinst() {
-       linux-mod_pkg_postinst
+       linux-mod-r1_pkg_postinst
 
        readme.gentoo_print_elog
 
@@ -592,7 +505,7 @@ pkg_postinst() {
                $(</proc/driver/nvidia/version) != *"  ${PV}  "* ]]; then
                ewarn "Currently loaded NVIDIA modules do not match the newly 
installed"
                ewarn "libraries and may prevent launching GPU-accelerated 
applications."
-               use driver && ewarn "The easiest way to fix this is usually to 
reboot."
+               use modules && ewarn "The easiest way to fix this is usually to 
reboot."
        fi
 
        if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
@@ -629,7 +542,7 @@ pkg_postinst() {
                ewarn "Switch back to USE=-kernel-open to restore functionality 
if needed for now."
        fi
 
-       if use wayland && use driver && [[ ! -v NV_HAD_WAYLAND ]]; then
+       if use wayland && use modules && [[ ! -v 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"

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-525.47.26-r1.ebuild 
b/x11-drivers/nvidia-drivers/nvidia-drivers-525.47.26-r1.ebuild
index dd901326817b..3cfb46f5d84e 100644
--- a/x11-drivers/nvidia-drivers/nvidia-drivers-525.47.26-r1.ebuild
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-525.47.26-r1.ebuild
@@ -3,12 +3,12 @@
 
 EAPI=8
 
-MODULES_OPTIONAL_USE="driver"
-inherit desktop flag-o-matic linux-mod multilib readme.gentoo-r1 \
-       systemd toolchain-funcs unpacker user-info
+MODULES_OPTIONAL_IUSE=+modules
+inherit desktop flag-o-matic linux-mod-r1 multilib readme.gentoo-r1
+inherit systemd toolchain-funcs unpacker user-info
 
-NV_KERNEL_MAX="6.3"
-NV_PIN="525.116.04"
+MODULES_KERNEL_MAX=6.3
+NV_PIN=525.116.04
 
 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
 HOMEPAGE="https://developer.nvidia.com/vulkan-driver";
@@ -25,8 +25,8 @@ S="${WORKDIR}"
 LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
 SLOT="0/vulkan"
 KEYWORDS="-* ~amd64"
-IUSE="+X abi_x86_32 abi_x86_64 +driver kernel-open persistenced +static-libs 
+tools wayland"
-REQUIRED_USE="kernel-open? ( driver )"
+IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced +static-libs +tools 
wayland"
+REQUIRED_USE="kernel-open? ( modules )"
 
 COMMON_DEPEND="
        acct-group/video
@@ -89,7 +89,7 @@ PATCHES=(
 )
 
 pkg_setup() {
-       use driver || return
+       use modules && [[ ${MERGE_TYPE} != binary ]] || return
 
        local CONFIG_CHECK="
                PROC_FS
@@ -115,18 +115,7 @@ pkg_setup() {
        Cannot be directly selected in the kernel's menuconfig, and may need
        selection of another option that requires it such as CONFIG_KVM."
 
-       MODULE_NAMES="
-               nvidia(video:kernel)
-               nvidia-drm(video:kernel)
-               nvidia-modeset(video:kernel)
-               nvidia-peermem(video:kernel)
-               nvidia-uvm(video:kernel)"
-       use kernel-open &&
-               
MODULE_NAMES=${MODULE_NAMES//:kernel/:kernel-module-source:kernel-module-source/kernel-open}
-
-       linux-mod_pkg_setup
-
-       [[ ${MERGE_TYPE} == binary ]] && return
+       linux-mod-r1_pkg_setup
 
        # do some extra checks manually as it gets messy to handle builtin-only
        # and some other conditional checks through CONFIG_CHECK
@@ -190,77 +179,6 @@ pkg_setup() {
 
        (( ${#warn[@]} )) &&
                ewarn "Detected potential configuration issues with used 
kernel:${warn[*]/#/$'\n'}"
-
-       BUILD_PARAMS='NV_VERBOSE=1 IGNORE_CC_MISMATCH=yes SYSSRC="${KV_DIR}" 
SYSOUT="${KV_OUT_DIR}"'
-       BUILD_TARGETS="modules"
-
-       # Try to match toolchain with kernel only for modules
-       # (experimental, ideally this should be handled in linux-mod.eclass)
-       nvidia-tc-set() {
-               local -n var=KERNEL_${1}
-               if [[ ! -v var ]]; then
-                       read -r var < <(type -P "${@:2}") ||
-                               die "failed to find in PATH at least one of: 
${*:2}"
-                       einfo "Forcing '${var}' for modules (set ${!var} to 
override)"
-               fi
-       }
-
-       local tool switch
-       if linux_chkconfig_present CC_IS_GCC; then
-               if ! tc-is-gcc; then
-                       switch=
-                       nvidia-tc-set CC {${CHOST}-,}gcc
-                       nvidia-tc-set CXX {${CHOST}-,}g++ # needed by 
kernel-open
-               fi
-       elif linux_chkconfig_present CC_IS_CLANG; then
-               ewarn "Warning: using ${PN} with a clang-built kernel is 
largely untested"
-               if ! tc-is-clang; then
-                       switch=llvm-
-                       nvidia-tc-set CC {${CHOST}-,}clang
-                       nvidia-tc-set CXX {${CHOST}-,}clang++
-               fi
-       fi
-
-       if linux_chkconfig_present LD_IS_BFD; then
-               # tc-ld-is-bfd needs https://github.com/gentoo/gentoo/pull/28355
-               [[ $(LC_ALL=C $(tc-getLD) --version 2>/dev/null) == "GNU ld"* 
]] ||
-                       nvidia-tc-set LD {${CHOST}-,}{ld.bfd,ld}
-       elif linux_chkconfig_present LD_IS_LLD; then
-               tc-ld-is-lld || nvidia-tc-set LD {${CHOST}-,}{ld.lld,lld}
-       fi
-
-       if [[ -v switch ]]; then
-               # only need llvm-nm for lto, but use complete set to be safe
-               for tool in AR NM OBJCOPY OBJDUMP READELF STRIP; do
-                       case $(LC_ALL=C $(tc-get${tool}) --version 2>/dev/null) 
in
-                               LLVM*|llvm*) [[ ! ${switch} ]];;
-                               *) [[ ${switch} ]];;
-                       esac && nvidia-tc-set ${tool} 
{${CHOST}-,}${switch}${tool,,}
-               done
-       fi
-
-       # pass unconditionally given exports are semi-ignored except CC/LD
-       for tool in CC CXX LD AR NM OBJCOPY OBJDUMP READELF STRIP; do
-               BUILD_PARAMS+=" 
${tool}=\"\${KERNEL_${tool}:-\$(tc-get${tool})}\""
-       done
-
-       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
-
-       if kernel_is -gt ${NV_KERNEL_MAX/./ }; then
-               ewarn "Kernel ${KV_MAJOR}.${KV_MINOR} is either known to break 
this version of ${PN}"
-               ewarn "or was not tested with it. It is recommended to use one 
of:"
-               ewarn "  <=sys-kernel/gentoo-kernel-${NV_KERNEL_MAX}.x"
-               ewarn "  <=sys-kernel/gentoo-sources-${NV_KERNEL_MAX}.x"
-               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 "(Gentoo will not accept patches for this)."
-               ewarn
-               ewarn "Do _not_ file a bug report if run into issues."
-               ewarn
-       fi
 }
 
 src_prepare() {
@@ -318,30 +236,26 @@ src_compile() {
                XNVCTRL_CFLAGS="${xnvflags}"
        )
 
-       if use driver; then
-               if linux_chkconfig_present GCC_PLUGINS; then
-                       mkdir "${T}"/plugin-test || die
-                       echo "obj-m += test.o" > "${T}"/plugin-test/Kbuild || 
die
-                       :> "${T}"/plugin-test/test.c || die
-                       if [[ $(LC_ALL=C make -C "${KV_OUT_DIR}" 
ARCH="$(tc-arch-kernel)" \
-                               HOSTCC="$(tc-getBUILD_CC)" CC="${CC}" 
M="${T}"/plugin-test 2>&1) \
-                               =~ "error: incompatible gcc/plugin version" ]]
-                       then
-                               eerror "Detected kernel was built with a 
different gcc/plugin version,"
-                               eerror "Please 'make clean' and rebuild your 
kernel with the current"
-                               eerror "gcc (or re-emerge for distribution 
kernels, including kernel-bin)."
-                               die "kernel ${KV_FULL} needs to be rebuilt"
-                       fi
-               fi
-
+       if use modules; then
                local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} 
o_ldflags=${LDFLAGS}
+
+               local modlistargs=video:kernel
                if use kernel-open; then
-                       # building the nvidia "blob" fails with lto, and also 
need
-                       # to strip in case of a different toolchain for the 
kernel
+                       
modlistargs+=-module-source:kernel-module-source/kernel-open
+
+                       # environment flags are normally unused for modules, 
but nvidia
+                       # uses it for building the "blob" and it is a bit 
fragile
                        filter-lto
-                       strip-unsupported-flags
+                       CC=${KERNEL_CC} CXX=${KERNEL_CXX} 
strip-unsupported-flags
                fi
-               linux-mod_src_compile
+
+               local modlist=( 
nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
+               local modargs=(
+                       IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
+                       SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
+               )
+
+               linux-mod-r1_src_compile
                CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
        fi
 
@@ -394,7 +308,7 @@ src_install() {
        )
        local skip_modules=(
                $(usev !X "nvfbc vdpau xdriver")
-               $(usev !driver gsp)
+               $(usev !modules gsp)
                installer nvpd # handled separately / built from source
        )
        local skip_types=(
@@ -414,7 +328,7 @@ src_install() {
        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\
-$(usev driver "
+$(usev modules "
 
 Like all out-of-tree kernel modules, it is necessary to rebuild
 ${PN} after upgrading or rebuilding the Linux kernel
@@ -438,8 +352,8 @@ For general information on using ${PN}, please see:
 https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
        readme.gentoo_create_doc
 
-       if use driver; then
-               linux-mod_src_install
+       if use modules; then
+               linux-mod-r1_src_install
 
                insinto /etc/modprobe.d
                doins "${T}"/nvidia.conf
@@ -561,8 +475,7 @@ https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers";
 pkg_preinst() {
        has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
 
-       use driver || return
-       linux-mod_pkg_preinst
+       use modules || return
 
        # set video group id based on live system (bug #491414)
        local g=$(egetent group video | cut -d: -f3)
@@ -585,7 +498,7 @@ pkg_preinst() {
 }
 
 pkg_postinst() {
-       linux-mod_pkg_postinst
+       linux-mod-r1_pkg_postinst
 
        readme.gentoo_print_elog
 
@@ -593,7 +506,7 @@ pkg_postinst() {
                $(</proc/driver/nvidia/version) != *"  ${PV}  "* ]]; then
                ewarn "Currently loaded NVIDIA modules do not match the newly 
installed"
                ewarn "libraries and may prevent launching GPU-accelerated 
applications."
-               use driver && ewarn "The easiest way to fix this is usually to 
reboot."
+               use modules && ewarn "The easiest way to fix this is usually to 
reboot."
        fi
 
        if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
@@ -630,7 +543,7 @@ pkg_postinst() {
                ewarn "Switch back to USE=-kernel-open to restore functionality 
if needed for now."
        fi
 
-       if use wayland && use driver && [[ ! -v NV_HAD_WAYLAND ]]; then
+       if use wayland && use modules && [[ ! -v 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"

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-530.41.03-r1.ebuild 
b/x11-drivers/nvidia-drivers/nvidia-drivers-530.41.03-r1.ebuild
index c1a57acccc87..ecf91c791425 100644
--- a/x11-drivers/nvidia-drivers/nvidia-drivers-530.41.03-r1.ebuild
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-530.41.03-r1.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=8
 
-MODULES_OPTIONAL_IUSE="+modules"
+MODULES_OPTIONAL_IUSE=+modules
 inherit desktop flag-o-matic linux-mod-r1 multilib readme.gentoo-r1
 inherit systemd toolchain-funcs unpacker user-info
 

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-535.43.02-r1.ebuild 
b/x11-drivers/nvidia-drivers/nvidia-drivers-535.43.02-r1.ebuild
index f17a5d471821..5d5db42e432b 100644
--- a/x11-drivers/nvidia-drivers/nvidia-drivers-535.43.02-r1.ebuild
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-535.43.02-r1.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=8
 
-MODULES_OPTIONAL_IUSE="+modules"
+MODULES_OPTIONAL_IUSE=+modules
 inherit desktop flag-o-matic linux-mod-r1 multilib readme.gentoo-r1
 inherit systemd toolchain-funcs unpacker user-info
 


Reply via email to