I have been trying to get my Nvidia card working, using offloading (as it seemed the simplest option).
I have the 4070 (laptop version).
I have pulled and put together all the configs from the Nvidia modules in the hardware repo and the items from the wiki. At the moment, I am not consuming the code from the hardware repo (my laptop model is not supported yet), and wanted all my Nvidia config in a single spot until I get this working.
Essentially, nvidia-smi nor nvidia-settings see the card. I searched this site, and the other fixes do not seem to apply.
Config:
{ lib, pkgs, config, ... }:
{
# NVIDIA drivers are unfree.
nixpkgs.config.allowUnfree = pkgs.lib.mkForce true;
# Sets the default video driver for the X server and Wayland to "nvidia"
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
hardware = {
opengl = {
# Enables the graphics driver for OpenGL
enable = true;
# Enables Direct Rendering Infrastructure (DRI), which allows the graphics driver to directly render graphics, improving performance in OpenGL
driSupport = true;
# Enables 32-bit Direct Rendering Infrastructure (DRI) support, which allows the graphics driver to directly render graphics in 32-bit applications using OpenGL
driSupport32Bit = true;
# Adds the 'vaapiVdpau' package to the extra packages for OpenGL
extraPackages = with pkgs; [ vaapiVdpau ];
};
nvidia = {
# Modesetting is required.
# Since NVIDIA does not support automatic KMS late loading, enabling DRM (Direct Rendering Manager) kernel mode setting is required to make Wayland compositors function properly, or to allow for Xorg#Rootless_Xorg.
modesetting.enable = true;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials.
powerManagement.enable = false;
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
powerManagement.finegrained = false;
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
## Confirmed my card is in there.
open = true;
# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
package = config.boot.kernelPackages.nvidiaPackages.stable;
prime = {
offload = {
enable = true;
enableOffloadCmd = true; # Provides `nvidia-offload` command.
};
# Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
intelBusId = "PCI:0:2:0";
# Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
nvidiaBusId = "PCI:1:0:0";
};
};
};
}
#### NOTES
# Get BusID:
# lspci | rg "VGA|3D controller"
# it will be in hexadecimal format, convert it to decimal
# https://www.binaryhexconverter.com/hex-to-decimal-converter
Errors:
β― nvidia-smi
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
OK, I was going down the road of the article, then I noticed it is for the βsuperβ. Which I do not believe this 4070 is. (Since it is a laptop GPU).
I also noticed this time around that the wiki highlights:
Note: As of early March 2024 the production driver has been updated from 535 to 550. This is a breaking change for some people, especially those on Wayland. To resolve this follow the steps under Running the new RTX SUPER on nixos stable.
So I moved over to package = config.boot.kernelPackages.nvidiaPackages.production; but unfortunately it did not help.
So, after the change, I checked journalctl again:
Mar 06 17:38:22 evo kernel: Command line: initrd=\EFI\nixos\ycyfh7ddcajd7gav8rz8gnl7mdwzgf84-initrd-linux-6.6.19-initrd.efi init=/nix/store/payip885f0jd2lmzfavpq419ihcs17y9-nixos-system-evo-24.05.20240303.b8697e5/init loglevel=4 nvidia-drm.modeset=1
Mar 06 17:38:22 evo kernel: Kernel command line: initrd=\EFI\nixos\ycyfh7ddcajd7gav8rz8gnl7mdwzgf84-initrd-linux-6.6.19-initrd.efi init=/nix/store/payip885f0jd2lmzfavpq419ihcs17y9-nixos-system-evo-24.05.20240303.b8697e5/init loglevel=4 nvidia-drm.modeset=1
{ pkgs, config, libs, inputs, ... }:
let
username = if builtins.getEnv "SUDO_USER" != "" then
builtins.getEnv "SUDO_USER"
else
builtins.getEnv "USER";
in {
# Enable OpenGL
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
# https://github.com/NixOS/nixos-hardware/blob/5d48925b815fd202781bfae8fb6f45c07112fdb2/common/gpu/nvidia/default.nix
extraPackages = with pkgs; [ vaapiVdpau ];
};
# Load nvidia driver for Xorg and Wayland
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
# Modesetting is required.
modesetting.enable = true;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
powerManagement.enable = false;
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
powerManagement.finegrained = false;
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from diver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommened setting.
open = false;
# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
# package = config.boot.kernelPackages.nvidiaPackages.production;
# Can select driver here:
# https://github.com/NixOS/nixpkgs/blob/979a311fbd179b86200e412a3ed266b64808df4e/pkgs/os-specific/linux/nvidia-x11/default.nix#L36
package = let
rcu_patch = pkgs.fetchpatch {
url =
"https://github.com/gentoo/gentoo/raw/c64caf53/x11-drivers/nvidia-drivers/files/nvidia-drivers-470.223.02-gpl-pfn_valid.patch";
hash = "sha256-eZiQQp2S/asE7MfGvfe6dA/kdCvek9SYa/FFGp24dVg=";
};
in config.boot.kernelPackages.nvidiaPackages.mkDriver {
# version = "535.154.05";
# sha256_64bit = "sha256-fpUGXKprgt6SYRDxSCemGXLrEsIA6GOinp+0eGbqqJg=";
# sha256_aarch64 = "sha256-G0/GiObf/BZMkzzET8HQjdIcvCSqB1uhsinro2HLK9k=";
# openSha256 = "sha256-wvRdHguGLxS0mR06P5Qi++pDJBCF8pJ8hr4T8O6TJIo=";
# settingsSha256 = "sha256-9wqoDEWY4I7weWW05F4igj1Gj9wjHsREFMztfEmqm10=";
# persistencedSha256 =
# "sha256-d0Q3Lk80JqkS1B54Mahu2yY/WocOqFFbZVBh+ToGhaE=";
version = "550.40.07";
sha256_64bit = "sha256-KYk2xye37v7ZW7h+uNJM/u8fNf7KyGTZjiaU03dJpK0=";
sha256_aarch64 = "sha256-AV7KgRXYaQGBFl7zuRcfnTGr8rS5n13nGUIe3mJTXb4=";
openSha256 = "sha256-mRUTEWVsbjq+psVe+kAT6MjyZuLkG2yRDxCMvDJRL1I=";
settingsSha256 = "sha256-c30AQa4g4a1EHmaEu1yc05oqY01y+IusbBuq+P6rMCs=";
persistencedSha256 =
"sha256-11tLSY8uUIl4X/roNnxf5yS2PQvHvoNjnd2CB67e870=";
patches = [ rcu_patch ];
};
prime = {
# offload = {
# enable = true;
# enableOffloadCmd = true;
# };
# OR
sync.enable = true;
# Make sure to use the correct Bus ID values for your system!
# https://wiki.nixos.org/wiki/Nvidia#Configuring_Optimus_PRIME:_Bus_ID_Values_(Mandatory)
# Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA. ANd can match with: sudo lshw -c display
# Note the two values under "bus info" above, which may differ from laptop to laptop. Our Nvidia Bus ID is 0e:00.0 and our Intel Bus ID is 00:02.0. Watch out for the formatting; convert them from hexadecimal to decimal, remove the padding (leading zeroes), replace the dot with a colon
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
};
home-manager.users."${username}" = {
home.packages = with pkgs; [
# Nvidia settings
gnomeExtensions.gpu-profile-selector
inputs.envycontrol.packages.x86_64-linux.default
];
dconf.settings = with inputs.home-manager.lib.hm.gvariant; {
# Gnome Extention - GPU Profile Selector
"org/gnome/shell/extensions/GPU_profile_selector" = {
rtd3 = true;
force-composition-pipeline = true;
coolbits = true;
force-topbar-view = false;
};
};
};
}
β― nvidia-smi
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
β― lsmod | grep nvidia
β― sudo modprobe nvidia
modprobe: ERROR: could not find module by name='off'
modprobe: ERROR: could not insert 'off': Unknown symbol in module, or unknown parameter (see dmesg)
so that then lead me to:
β― bat /etc/modprobe.d/blacklist-nvidia.conf
ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β File: /etc/modprobe.d/blacklist-nvidia.conf
ββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ
1 β # Automatically generated by EnvyControl
2 β
3 β blacklist nouveau
4 β blacklist nvidia
5 β blacklist nvidia_drm
6 β blacklist nvidia_uvm
7 β blacklist nvidia_modeset
8 β blacklist nvidia_current
9 β blacklist nvidia_current_drm
10 β blacklist nvidia_current_uvm
11 β blacklist nvidia_current_modeset
12 β alias nouveau off
13 β alias nvidia off
14 β alias nvidia_drm off
15 β alias nvidia_uvm off
16 β alias nvidia_modeset off
17 β alias nvidia_current off
18 β alias nvidia_current_drm off
19 β alias nvidia_current_uvm off
20 β alias nvidia_current_modeset off
My current nvidia config looks like:
{ pkgs, config, lib, inputs, ... }: {
imports = [
inputs.nixos-hardware.nixosModules.common-gpu-nvidia
# TODO: why do I get the below error?
# error: The option `hardware.intelgpu.loadInInitrd' in `/nix/store/4mgg9mrh8g0qj4g3z9zvqhrniig10bsn-source/systems/evo/hardware/gpus.nix' is already declared in `/nix/store/75hvhrfigcnckibdlg877157bpwjmy85-source/common/gpu/intel'.
# Where is the other coming from?g
# inputs.nixos-hardware.nixosModules.common-gpu-intel
];
boot = {
blacklistedKernelModules = lib.mkDefault [ "nouveau" ];
kernelModules = [ "kvm-intel" "nvidia" ];
};
hardware = {
opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
extraPackages = [ pkgs.intel-media-driver ];
};
nvidia = {
# Modesetting is required.
modesetting.enable = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
package = config.boot.kernelPackages.nvidiaPackages.production;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials.
powerManagement.enable = false;
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
powerManagement.finegrained = false;
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
open = false;
prime = {
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
# Make the Intel iGP default. The NVIDIA Quadro is for CUDA/NVENC
reverseSync.enable = true;
# sync.enable = true;
};
nvidiaSettings = true;
};
};
services.xserver.videoDrivers = [ "nvidia" ];
}
Did I do something wrong in there that would cause my issues?
Hey, I also have a similar issue on a System76 Gaze18 (core i9 + RTX 3050) with plasma6.
I have access to nvidia-offload and nvidia-settings and nvidia-smi, but but the settings and smi complain that thereβs no driver even when run with nvidia-offload.
Here is my nvidia.nix
{ config, lib, pkgs, ... }:
{
#boot.initrd.kernelModules = [ "nvidia" ];
#boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ];
boot.kernelParams = [
"ibt=off"
];
# Enable OpenGL
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
};
# Load nvidia driver for Xorg and Wayland
services.xserver.videoDrivers = ["nvidia"];
hardware.nvidia = {
# Modesetting is required.
modesetting.enable = true;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials.
#powerManagement.enable = false;
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
#powerManagement.finegrained = false;
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
#open = false;
# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
package = config.boot.kernelPackages.nvidiaPackages.stable;
prime = {
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
offload = {
enable = true;
enableOffloadCmd = true;
};
};
};
}
βΞ» nvidia-offload nvidia-smi
Thu Jun 13 11:41:21 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.78 Driver Version: 550.78 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 3050 ... Off | 00000000:01:00.0 Off | N/A |
| N/A 46C P0 12W / 70W | 1MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
βΞ» cat nvidia.nix
{ config, lib, pkgs, ... }:
{
boot.initrd.kernelModules = [ "nvidia" ];
boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ];
boot.kernelParams = [
"ibt=off"
];
# Enable OpenGL
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
};
# Load nvidia driver for Xorg and Wayland
services.xserver.videoDrivers = ["nvidia"];
hardware.nvidia = {
# Modesetting is required.
modesetting.enable = true;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials.
#powerManagement.enable = false;
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
#powerManagement.finegrained = false;
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
#open = false;
# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
package = config.boot.kernelPackages.nvidiaPackages.stable;
prime = {
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
offload = {
enable = true;
enableOffloadCmd = true;
};
};
};
}
The key thing here that fixed it all was initrd.kernelModules = [ "nvidia" "i915" "nvidia_modeset" "nvidia_uvm" "nvidia_drm" ];
I do not know if I should be happy it is fixed, or sad it took, this long.
Working (for me) Config
{ pkgs, config, lib, inputs, ... }: {
imports = [
inputs.nixos-hardware.nixosModules.common-gpu-nvidia
# TODO: why do I get the below error?
# error: The option `hardware.intelgpu.loadInInitrd' in `/nix/store/4mgg9mrh8g0qj4g3z9zvqhrniig10bsn-source/systems/evo/hardware/gpus.nix' is already declared in `/nix/store/75hvhrfigcnckibdlg877157bpwjmy85-source/common/gpu/intel'.
# Where is the other coming from?g
# inputs.nixos-hardware.nixosModules.common-gpu-intel
];
boot = {
# TODO: confirm this works
# https://forums.developer.nvidia.com/t/550-54-14-cannot-create-sg-table-for-nvkmskapimemory-spammed-when-launching-chrome-on-wayland/284775/26
initrd.kernelModules = [ "nvidia" "i915" "nvidia_modeset" "nvidia_uvm" "nvidia_drm" ];
# extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ];
kernelParams = [ "nvidia-drm.fbdev=1" ];
};
hardware = {
# deprecated for graphics.enable
# opengl = {
# enable = true;
# # extraPackages = [ pkgs.intel-media-driver pkgs.vaapiVdpau ];
# };
graphics = {
# For 32 bit applications
# enable32Bit = true;
enable = true;
};
nvidia = {
# Modesetting is required.
modesetting.enable = true;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials.
powerManagement.enable = true;
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
powerManagement.finegrained = false;
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
open = false;
forceFullCompositionPipeline = true;
prime = {
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
offload = {
enable = true;
enableOffloadCmd = true;
};
# Make the Intel iGP default. The NVIDIA Quadro is for CUDA/NVENC
# reverseSync.enable = true;
# sync.enable = true;
};
nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
package = config.boot.kernelPackages.nvidiaPackages.beta;
};
};
services.xserver.videoDrivers = [ "nvidia" ];
}