diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/Manifest b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/Manifest
new file mode 100644
index 0000000000..179f528247
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/Manifest
@@ -0,0 +1,8 @@
+DIST NVIDIA-Linux-aarch64-550.163.01.run 236409124 BLAKE2B 21c79346f6b739f44d7ed2d4955129613f51e1329ff15948ef50a9a06b82975ad890d6142e5dfb163e7b0da19bf5c26029cf507d120037f8a76abc177a286403 SHA512 0ef4ab4aae308ec0cfb5458cef34a1503ac1a85f0e1d0c9f061d8e28f939b15784e3862d96d83e93123d9eb56807a6804318ce230ee68917fb75e363011f8304
+DIST NVIDIA-Linux-x86_64-550.163.01.run 307143336 BLAKE2B 256106bcd3bace402289e60aca4cd3b447d0fd8ec3dabd50e2bb303c5e866f8da5c28f9b578d95775bf69158f100d68a91d20d9a91426285a8e799817f21db6b SHA512 676b1de35d21e80091528a49080c114e0870ea90b3f3721265ae8071abbc2183c851e6f11ba96a332c743fedfaf4ec9a014ad6ceed586fdbb03d94d33405e356
+DIST NVIDIA-kernel-module-source-550.163.01.tar.xz 13552400 BLAKE2B e1fd753127d10097c5f1d3c90d95c7eb0934c0d5e1df0a371aed2a0d7669960b67c46eed20eec3c42ca41c0f34bf6d7d3d2a77a94308c9f86d4f5d831da19363 SHA512 c9f4ce2890db3fdc66dd080da4d6802a8bc3b18feba96be5d33641b02cca637b1bcd2a3748f36f93a32f26ba57eb352156314f139688b0d3a102efdfde6c32ba
+DIST nvidia-installer-550.163.01.tar.bz2 155861 BLAKE2B 662064b3ceb4aadebde419057d85c6b4e28b91944bd5bab241bcba9b3c9a105e507afc7651b17fff01e1cccb78d66fdc6789597ce059f882a6f322b08f28e832 SHA512 f8df7a0eccdecb7d4d4f47d96050cdbefff91289b29550b061358614845648451d4b161d9bdbfbf5a9a87ce650d272cb3b795e6d2ed4d0274844a56db097bd15
+DIST nvidia-modprobe-550.163.01.tar.bz2 41448 BLAKE2B 23e567d612e669ec6ae9f389651c9e1cebe7ba59ee95bb5961e5071952697860df77f02026040e29135338eb7cf96bba0015b3d94548297235fb5214f35bec48 SHA512 0f5b59468a6e5e95dcdef1d938ea78f4ce09a0c9784e3c70d83f1c3b1bd52e8055b6b332147316445c3be714abab3629320d6117878d50aa7a2d7d2d9b9b6485
+DIST nvidia-persistenced-550.163.01.tar.bz2 61450 BLAKE2B 1a11cb89981b88f8d14558227d9493f1f8a81ccb5502002c436e9311a38c9c8fe0402c65eac1517a2893985eec07699b2e7bc7a81aa14dc0d52198ac85a2cd1b SHA512 f17dbcafa917b5b450f7665f98fd24f06ad99e6bcd1fcf42ef95aa9337b55561b7b16eaad8fa408110d08ee7e6d812444792cccbb9c92865099891832da779ce
+DIST nvidia-settings-550.163.01.tar.bz2 1099317 BLAKE2B 25419c1796deeea238b3e44fd8d648a8627272565be40cb0745132cef1c16e0c422242a1e6369745d577e674a68bf9dfc3c009e281a84ba58db5429d97ac9cff SHA512 5306ab05f284ba06852d7c96ff62ded7b8b615d3a002009cd5d781fdad716db37f53d1c8a43337ada60d524b4f7d183d98ad2673f40a5ca1ca4c5112bb913e74
+DIST nvidia-xconfig-550.163.01.tar.bz2 111149 BLAKE2B d19ef0427e3432798e674dc66447090e8fb8fcb549ebe27aaee19aa38294cf178e175a067b2da5313342c93ea2aebef35861d05cc4cc0ee2c3eae955b3ddbbb3 SHA512 35f95d85928c82bc5de8e462ca5e90a6d8fe03e5b5367b9cdaadddc1e956f0d26b6dc42e716ae7c88512afdfb98cc841fe9b22846f6d6acc578c5dba4d0a16e1
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/95-nvidia-settings-r1 b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/95-nvidia-settings-r1
new file mode 100644
index 0000000000..48c41d8aad
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/95-nvidia-settings-r1
@@ -0,0 +1,2 @@
+#!/bin/sh
+/usr/bin/nvidia-settings --load-config-only
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-545.conf b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-545.conf
new file mode 100644
index 0000000000..5f7f384c27
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-545.conf
@@ -0,0 +1,39 @@
+# NVIDIA drivers options
+# See /usr/share/doc/nvidia-drivers-*/README.txt* for more information.
+
+# nvidia-drivers and nouveau / nova cannot be used at same time.
+# Comment out the following lines if you wish to allow either.
+blacklist nouveau
+blacklist nova_core
+
+# Kernel Mode Setting (notably needed for fbdev and wayland).
+# Enabling may possibly cause issues with SLI and Reverse PRIME.
+#options nvidia-drm modeset=1
+
+# Enable experimental framebuffer console support (requires modeset=1 above).
+# Replaces efifb, simpledrm, or similar once loaded (emphasis on being
+# experimental, "may" cause issues X mode switching, sleep, or more).
+#options nvidia-drm fbdev=1
+
+# Suspend options. Note that Allocations=1 requires suspend hooks currently
+# only used when either systemd or elogind is used to suspend. If using
+# neither or have issues, try Allocations=0 (revert if it does not help
+# as =0 is not recommended).
+options nvidia \
+ NVreg_PreserveVideoMemoryAllocations=1 \
+ NVreg_TemporaryFilePath=/var/tmp
+
+# !!! Security Warning !!!
+# Do not change the DeviceFile options unless you know what you are doing.
+# Only add trusted users to the 'video' group, these users may be able to
+# crash, compromise, or irreparably damage the machine.
+options nvidia \
+ NVreg_DeviceFileGID=@VIDEOGID@ \
+ NVreg_DeviceFileMode=432 \
+ NVreg_DeviceFileUID=0 \
+ NVreg_ModifyDeviceFiles=1
+
+# Should be no need to touch anything below.
+alias char-major-195 nvidia
+alias /dev/nvidiactl char-major-195
+remove nvidia modprobe -r --ignore-remove nvidia-drm nvidia-modeset nvidia-uvm nvidia
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-modprobe-390.141-uvm-perms.patch b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-modprobe-390.141-uvm-perms.patch
new file mode 100644
index 0000000000..6ffd42ff77
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-modprobe-390.141-uvm-perms.patch
@@ -0,0 +1,12 @@
+Create /dev/nvidia-uvm* by respecting nvidia.conf's permissions.
+--- a/nvidia-modprobe/modprobe-utils/nvidia-modprobe-utils.c
++++ b/nvidia-modprobe/modprobe-utils/nvidia-modprobe-utils.c
+@@ -742,6 +742,6 @@
+ }
+
+- return mknod_helper(major, base_minor, NV_UVM_DEVICE_NAME, NULL) &&
+- mknod_helper(major, base_minor + 1, NV_UVM_TOOLS_DEVICE_NAME, NULL);
++ return mknod_helper(major, base_minor, NV_UVM_DEVICE_NAME, NV_PROC_REGISTRY_PATH) &&
++ mknod_helper(major, base_minor + 1, NV_UVM_TOOLS_DEVICE_NAME, NV_PROC_REGISTRY_PATH);
+ }
+
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-persistenced.confd b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-persistenced.confd
new file mode 100644
index 0000000000..e06d53c0c9
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-persistenced.confd
@@ -0,0 +1,7 @@
+# configuration file for /etc/init.d/nvidia-persistenced
+
+# NVPD_USER: user to run as, needs access to /dev/nvidia* (video group)
+NVPD_USER="nvpd"
+
+# ARGS: additional arguments, see nvidia-persistenced(1)
+ARGS=""
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-persistenced.initd b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-persistenced.initd
new file mode 100644
index 0000000000..27d8bb37d9
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-persistenced.initd
@@ -0,0 +1,11 @@
+#!/sbin/openrc-run
+# SPDX-License-Identifier: MIT
+
+description="Maintain persistent software state in the NVIDIA driver"
+command="nvidia-persistenced"
+command_args="${NVPD_USER:+--user ${NVPD_USER}} ${ARGS}"
+pidfile="/var/run/nvidia-persistenced/nvidia-persistenced.pid"
+
+stop_post() {
+ rmdir "${pidfile%/*}" 2>/dev/null || true
+}
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-powerd.initd b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-powerd.initd
new file mode 100644
index 0000000000..5132a20c65
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-powerd.initd
@@ -0,0 +1,11 @@
+#!/sbin/openrc-run
+# SPDX-License-Identifier: MIT
+
+description="Support for NVIDIA Dynamic Boost (only for use with specific laptops)"
+command="nvidia-powerd"
+command_background=true
+pidfile="/var/run/nvidia-powerd.pid"
+
+depend() {
+ need dbus
+}
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-settings-530.30.02-desktop.patch b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-settings-530.30.02-desktop.patch
new file mode 100644
index 0000000000..d1cdbcec44
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/nvidia-settings-530.30.02-desktop.patch
@@ -0,0 +1,11 @@
+These __PLACEHOLDER__ are replaced by nvidia-installer which we don't use.
+--- a/nvidia-settings/doc/nvidia-settings.desktop
++++ b/nvidia-settings/doc/nvidia-settings.desktop
+@@ -5,5 +5,5 @@
+ Comment=Configure NVIDIA X Server Settings
+-Exec=__UTILS_PATH__/nvidia-settings
++Exec=nvidia-settings
+ Icon=nvidia-settings
+-Categories=__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__
++Categories=System;HardwareSettings;
+
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/system-sleep.elogind b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/system-sleep.elogind
new file mode 100644
index 0000000000..d36e2697b8
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/files/system-sleep.elogind
@@ -0,0 +1,7 @@
+#!/bin/sh
+case ${1-} in
+ pre) nvidia-sleep.sh suspend;;
+ # run in background given resume is flaky if elogind did not finish
+ post) nvidia-sleep.sh resume &;;
+ *) exit 1;;
+esac
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/metadata.xml b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/metadata.xml
new file mode 100644
index 0000000000..b3bb900152
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/metadata.xml
@@ -0,0 +1,37 @@
+
+
+
+
+ maintainers@flatcar-linux.org
+ The Flatcar Container Linux Maintainers
+
+
+
+ cpe:/a:nvidia:gpu_driver
+ NVIDIA/nvidia-installer
+ NVIDIA/nvidia-modprobe
+ NVIDIA/nvidia-persistenced
+ NVIDIA/nvidia-settings
+ NVIDIA/nvidia-xconfig
+ NVIDIA/open-gpu-kernel-modules
+
+
+
+ Subslot is primarily used to identify branches, at most
+ rebuilding reverse dependencies on bumps would only be
+ for the static library (not essential to) given other
+ headers are provided by nvidia-cuda-toolkit instead.
+
+
+
diff --git a/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/old-nvidia-drivers-550.163.01-r1.ebuild b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/old-nvidia-drivers-550.163.01-r1.ebuild
new file mode 100644
index 0000000000..6e3b131d18
--- /dev/null
+++ b/sdk_container/src/third_party/coreos-overlay/x11-drivers/old-nvidia-drivers/old-nvidia-drivers-550.163.01-r1.ebuild
@@ -0,0 +1,569 @@
+# Copyright 1999-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+MODULES_OPTIONAL_IUSE=+modules
+inherit desktop dot-a eapi9-pipestatus flag-o-matic linux-mod-r1
+inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
+
+MODULES_KERNEL_MAX=6.14
+NV_URI="https://download.nvidia.com/XFree86/"
+
+DESCRIPTION="NVIDIA Accelerated Graphics Driver"
+HOMEPAGE="https://www.nvidia.com/"
+SRC_URI="
+ amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
+ arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
+ $(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
+ nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
+ ${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
+"
+# nvidia-installer is unused but here for GPL-2's "distribute sources"
+S=${WORKDIR}
+
+LICENSE="NVIDIA-2023 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
+SLOT="0/${PV%%.*}"
+KEYWORDS="-* amd64 ~arm64"
+IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
+REQUIRED_USE="kernel-open? ( modules )"
+
+COMMON_DEPEND="
+ acct-group/video
+ X? ( x11-libs/libpciaccess )
+ persistenced? (
+ acct-user/nvpd
+ net-libs/libtirpc:=
+ )
+ tools? (
+ >=app-accessibility/at-spi2-core-2.46:2
+ dev-libs/glib:2
+ dev-libs/jansson:=
+ media-libs/harfbuzz:=
+ x11-libs/cairo
+ x11-libs/gdk-pixbuf:2
+ x11-libs/gtk+:3[X]
+ x11-libs/libX11
+ x11-libs/libXext
+ x11-libs/libXxf86vm
+ x11-libs/pango
+ )
+"
+RDEPEND="
+ ${COMMON_DEPEND}
+ dev-libs/openssl:0/3
+ sys-libs/glibc
+ X? (
+ media-libs/libglvnd[X,abi_x86_32(-)?]
+ x11-libs/libX11[abi_x86_32(-)?]
+ x11-libs/libXext[abi_x86_32(-)?]
+ )
+ powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
+ wayland? (
+ gui-libs/egl-gbm
+ >=gui-libs/egl-wayland-1.1.10
+ )
+"
+DEPEND="
+ ${COMMON_DEPEND}
+ static-libs? (
+ x11-base/xorg-proto
+ 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="
+ sys-devel/m4
+ virtual/pkgconfig
+"
+
+# there is some non-prebuilt exceptions but rather not maintain a list
+QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
+
+PATCHES=(
+ "${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
+ "${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
+)
+
+pkg_setup() {
+ use modules && [[ ${MERGE_TYPE} != binary ]] || return
+
+ # do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
+ get_version
+ require_configured_kernel
+
+ local CONFIG_CHECK="
+ PROC_FS
+ ~DRM_KMS_HELPER
+ ~SYSVIPC
+ ~!LOCKDEP
+ ~!PREEMPT_RT
+ ~!SLUB_DEBUG_ON
+ !DEBUG_MUTEXES
+ $(usev powerd '~CPU_FREQ')
+ "
+
+ kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
+ CONFIG_CHECK+=" DRM_TTM_HELPER"
+
+ use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
+
+ use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
+
+ local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
+ selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
+ DRM_AMDGPU=m (among others, consult the kernel config's help), can
+ also use DRM_NOUVEAU=m as long as built as module *not* built-in."
+ 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.
+ ${drm_helper_msg}"
+ local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
+ kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
+ ${drm_helper_msg}"
+ local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
+ Cannot be directly selected in the kernel's menuconfig, and may need
+ selection of another option that requires it such as CONFIG_KVM."
+ local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
+ will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
+ set. Please do not report issues if run into e.g. kernel panics while
+ ignoring this."
+
+ linux-mod-r1_pkg_setup
+}
+
+src_prepare() {
+ # make patches usable across versions
+ rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
+ rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
+ rm nvidia-settings && mv nvidia-settings{-${PV},} || die
+ rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
+ mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
+
+ default
+
+ # prevent detection of incomplete kernel DRM support (bug #603818)
+ sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
+ -i kernel{,-module-source/kernel-open}/conftest.sh || die
+
+ sed 's/__USER__/nvpd/' \
+ nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
+ > "${T}"/nvidia-persistenced.service || die
+
+ # use alternative vulkan icd option if USE=-X (bug #909181)
+ use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
+
+ # enable nvidia-drm.modeset=1 by default with USE=wayland
+ cp "${FILESDIR}"/nvidia-545.conf "${T}"/nvidia.conf || die
+ use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
+
+ # makefile attempts to install wayland library even if not built
+ use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
+ nvidia-settings/src/Makefile || die
+}
+
+src_compile() {
+ tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
+
+ # extra flags for the libXNVCtrl.a static library
+ local xnvflags=-fPIC #840389
+ tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
+
+ NV_ARGS=(
+ PREFIX="${EPREFIX}"/usr
+ HOST_CC="$(tc-getBUILD_CC)"
+ HOST_LD="$(tc-getBUILD_LD)"
+ BUILD_GTK2LIB=
+ NV_USE_BUNDLED_LIBJANSSON=0
+ NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
+ WAYLAND_AVAILABLE=$(usex wayland 1 0)
+ XNVCTRL_CFLAGS="${xnvflags}"
+ )
+
+ if use modules; then
+ local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
+
+ # conftest.sh is broken with c23 due to func() changing meaning,
+ # and then fails later due to ealier misdetections
+ # TODO: try without now and then + drop modargs' CC= (bug #944092)
+ KERNEL_CC+=" -std=gnu17"
+
+ local modlistargs=video:kernel
+ if use kernel-open; then
+ 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-flags -fno-plt #912949
+ filter-lto
+ CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
+ fi
+
+ local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
+ local modargs=(
+ CC="${KERNEL_CC}" # needed for above gnu17 workaround
+ IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
+ SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
+
+ # kernel takes "x86" and "x86_64" as meaning the same, but nvidia
+ # makes the distinction (since 550.135) and is not happy with "x86"
+ # TODO?: it should be ok/better for tc-arch-kernel to do x86_64
+ $(usev amd64 ARCH=x86_64)
+ )
+
+ # temporary workaround for bug #914468
+ addpredict "${KV_OUT_DIR}"
+
+ linux-mod-r1_src_compile
+ CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
+ fi
+
+ emake "${NV_ARGS[@]}" -C nvidia-modprobe
+ use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
+ use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
+
+ if use tools; then
+ # avoid noisy *very* noisy logs with deprecation warnings
+ CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
+ emake "${NV_ARGS[@]}" -C nvidia-settings
+ elif use static-libs; then
+ # pretend GTK+3 is available, not actually used (bug #880879)
+ emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
+ -C nvidia-settings/src out/libXNVCtrl.a
+ fi
+}
+
+src_install() {
+ local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
+
+ NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
+
+ local -A paths=(
+ [APPLICATION_PROFILE]=/usr/share/nvidia
+ [CUDA_ICD]=/etc/OpenCL/vendors
+ [EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
+ [FIRMWARE]=/lib/firmware/nvidia/${PV}
+ [GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
+ [GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
+ [OPENGL_DATA]=/usr/share/nvidia
+ [VULKAN_ICD_JSON]=/usr/share/vulkan
+ [WINE_LIB]=/usr/${libdir}/nvidia/wine
+ [XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
+
+ [GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
+ [GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
+ [XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
+ )
+
+ local skip_files=(
+ $(usev !X "libGLX_nvidia libglxserver_nvidia")
+ libGLX_indirect # non-glvnd unused fallback
+ libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
+ libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
+ libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
+ libnvidia-pkcs11.so # using the openssl3 version instead
+ )
+ local skip_modules=(
+ $(usev !X "nvfbc vdpau xdriver")
+ $(usev !modules gsp)
+ $(usev !powerd powerd)
+ installer nvpd # handled separately / built from source
+ )
+ local skip_types=(
+ GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
+ OPENCL_WRAPPER.\* # virtual/opencl
+ DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
+ )
+
+ local DOCS=(
+ README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
+ nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
+ )
+ local HTML_DOCS=( html/. )
+ einstalldocs
+
+ 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\
+$(usev modules "
+
+Like all out-of-tree kernel modules, it is necessary to rebuild
+${PN} after upgrading or rebuilding the Linux kernel
+by for example running \`emerge @module-rebuild\`. Alternatively,
+if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
+this can be automated by setting USE=dist-kernel globally.
+
+Loaded kernel modules also must not mismatch with the installed
+${PN} version (excluding -r revision), meaning should
+ensure \`eselect kernel list\` points to the kernel that will be
+booted before building and preferably reboot after upgrading
+${PN} (the ebuild will emit a warning if mismatching).
+
+See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
+$(use amd64 && usev !abi_x86_32 "
+
+Note that without USE=abi_x86_32 on ${PN}, 32bit applications
+(typically using wine / steam) will not be able to use GPU acceleration.")
+
+For additional information or for troubleshooting issues, please see
+https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
+documentation that is installed alongside this README."
+ readme.gentoo_create_doc
+
+ if use modules; then
+ linux-mod-r1_src_install
+
+ insinto /etc/modprobe.d
+ doins "${T}"/nvidia.conf
+
+ # used for gpu verification with binpkgs (not kept, see pkg_preinst)
+ insinto /usr/share/nvidia
+ doins supported-gpus/supported-gpus.json
+ fi
+
+ emake "${NV_ARGS[@]}" -C nvidia-modprobe install
+ fowners :video /usr/bin/nvidia-modprobe #505092
+ fperms 4710 /usr/bin/nvidia-modprobe
+
+ if use persistenced; then
+ emake "${NV_ARGS[@]}" -C nvidia-persistenced install
+ newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
+ newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
+ systemd_dounit "${T}"/nvidia-persistenced.service
+ fi
+
+ if use tools; then
+ emake "${NV_ARGS[@]}" -C nvidia-settings install
+
+ doicon nvidia-settings/doc/nvidia-settings.png
+ domenu nvidia-settings/doc/nvidia-settings.desktop
+
+ 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
+ strip-lto-bytecode
+
+ insinto /usr/include/NVCtrl
+ doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
+ fi
+
+ use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
+
+ # mimic nvidia-installer by reading .manifest to install files
+ # 0:file 1:perms 2:type 3+:subtype/arguments -:module
+ local m into
+ while IFS=' ' read -ra m; do
+ ! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
+ [[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
+ [[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
+ has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
+
+ case ${m[2]} in
+ MANPAGE)
+ gzip -dc ${m[0]} | newman - ${m[0]%.gz}
+ pipestatus || die
+ continue
+ ;;
+ GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
+ VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
+ esac
+
+ if [[ -v 'paths[${m[2]}]' ]]; then
+ into=${paths[${m[2]}]}
+ elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
+ into=${m[3]}
+ elif [[ ${m[2]} == *_BINARY ]]; then
+ into=/usr/bin
+ elif [[ ${m[3]} == COMPAT32 ]]; then
+ use abi_x86_32 || continue
+ into=/usr/${libdir32}
+ elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
+ into=/usr/${libdir}
+ else
+ die "No known installation path for ${m[0]}"
+ fi
+ [[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
+ [[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
+
+ if [[ ${m[2]} =~ _SYMLINK$ ]]; then
+ [[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
+ dosym ${m[4]} ${into}/${m[0]}
+ continue
+ fi
+ [[ ${m[0]} =~ ^libnvidia-ngx.so|^libnvidia-egl-gbm.so ]] &&
+ dosym ${m[0]} ${into}/${m[0]%.so*}.so.1 # soname not in .manifest
+
+ printf -v m[1] %o $((m[1] | 0200)) # 444->644
+ insopts -m${m[1]}
+ insinto ${into}
+ doins ${m[0]}
+ done < .manifest || die
+ insopts -m0644 # reset
+
+ # MODULE:installer non-skipped extras
+ : "$(systemd_get_sleepdir)"
+ exeinto "${_#"${EPREFIX}"}"
+ doexe systemd/system-sleep/nvidia
+ dobin systemd/nvidia-sleep.sh
+ systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend}.service
+
+ dobin nvidia-bug-report.sh
+
+ # MODULE:powerd extras
+ if use powerd; then
+ newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
+ systemd_dounit systemd/system/nvidia-powerd.service
+
+ insinto /usr/share/dbus-1/system.d
+ doins nvidia-dbus.conf
+ fi
+
+ # enabling is needed for sleep to work properly and little reason not to do
+ # it unconditionally for a better user experience
+ : "$(systemd_get_systemunitdir)"
+ local unitdir=${_#"${EPREFIX}"}
+ # not using relative symlinks to match systemd's own links
+ dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
+ dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
+ dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
+ dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
+ # also add a custom elogind hook to do the equivalent of the above
+ exeinto /usr/lib/elogind/system-sleep
+ newexe "${FILESDIR}"/system-sleep.elogind nvidia
+ # =systemd-256 or may fail to resume with some setups
+ # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
+ insinto "${unitdir}"/systemd-homed.service.d
+ newins - 10-nvidia.conf <<-EOF
+ [Service]
+ Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
+ EOF
+ insinto "${unitdir}"/systemd-suspend.service.d
+ newins - 10-nvidia.conf <<-EOF
+ [Service]
+ Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
+ EOF
+ dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
+ dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
+ dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
+
+ # symlink non-versioned so nvidia-settings can use it even if misdetected
+ dosym nvidia-application-profiles-${PV}-key-documentation \
+ ${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
+
+ # don't attempt to strip firmware files (silences errors)
+ dostrip -x ${paths[FIRMWARE]}
+
+ # sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
+ # are widespread and sometime affect revdeps of packages built with
+ # USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
+ # ebuilds should handle manually if need others or addwrite)
+ insinto /etc/sandbox.d
+ newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
+
+ # dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
+ # our settings are used for bug 932781#c8 and nouveau blacklist if either
+ # modules are included (however, just best-effort without initramfs regen)
+ if use modules; then
+ echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
+ "${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
+ fi
+}
+
+pkg_preinst() {
+ has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
+ has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
+
+ use modules || return
+
+ # set video group id based on live system (bug #491414)
+ local g=$(egetent group video | cut -d: -f3)
+ [[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
+ 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() {
+ linux-mod-r1_pkg_postinst
+
+ readme.gentoo_print_elog
+
+ if [[ -r /proc/driver/nvidia/version &&
+ $( ${EROOT}/etc/portage/package.mask/${PN}"
+ else
+ ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
+ fi
+ ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
+ ewarn "are available or fully functional, may need to consider nouveau[2])."
+ ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
+ ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
+ fi
+
+ if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
+ ewarn
+ ewarn "Open source variant of ${PN} was selected, be warned it is experimental"
+ ewarn "and only for modern GPUs (e.g. GTX 1650+). Try to disable if run into issues."
+ ewarn "Please also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
+ fi
+
+ 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"
+ elog "experimental but is required for wayland."
+ elog
+ elog "If you experience issues, either disable wayland or edit nvidia.conf."
+ elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
+ fi
+}