Warning for readers: my main language is Russian, the translation may be incorrect in some places. Have fun reading.
This guide walks through the process of configuring NVIDIA proprietary drivers on a NixOS laptop with a hybrid graphics setup (a dedicated NVIDIA GPU and an integrated Intel GPU). Our specific hardware was a laptop with an NVIDIA GeForce GTX 1650 Ti and an Intel Core i5-10300H.
The journey involved several common errors and a final switch to a more stable configuration mode.
Step 1: Find Your GPU Bus IDs
For laptops with hybrid graphics, you must tell NixOS the PCI Bus IDs of both your integrated and dedicated GPUs.
-
Open a terminal.
-
The
lspcicommand is not installed by default. Run it within a temporary shell:nix-shell -p pciutils -
Once inside the
nix-shell, run the command to find your graphics devices:lspci | grep -E 'VGA|3D' -
You will get an output similar to this. Note the values at the beginning of each line (e.g.,
00:02.0and01:00.0).00:02.0 VGA compatible controller: Intel Corporation CometLake-H GT2 [UHD Graphics] 01:00.0 VGA compatible controller: NVIDIA Corporation TU117M [GeForce GTX 1650 Ti Mobile] -
Convert these IDs to the format
PCI:BUS:SLOT:FUNCTION. For our example, this becomes:- Intel:
PCI:0:2:0 - NVIDIA:
PCI:1:0:0
- Intel:
-
Type
exitto leave thenix-shell.
Step 2: Initial Configuration Attempt (PRIME Offload)
Our first goal was to use PRIME Offload, a mode that saves battery by keeping the NVIDIA GPU powered down until itâs explicitly needed.
Here is the initial configuration block we added to configuration.nix:
# Enable OpenGL
hardware.graphics = {
enable = true;
enable32Bit = true;
};
# Configure the NVIDIA driver
hardware.nvidia = {
modesetting.enable = true;
open = true; # Use the open-source kernel module
nvidiaSettings = true;
package = config.boot.kernelPackages.nvidiaPackages.stable;
prime = {
offload = {
enable = true;
enableOffloadCmd = true;
};
# Use the Bus IDs you found earlier
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
};
# Load the nvidia driver for Xorg and Wayland
services.xserver.videoDrivers = [ "modesetting" "nvidia" ];
Troubleshooting: The Errors We Encountered
Applying the initial configuration was not smooth. Here are the errors we faced and how we fixed them.
Error 1: `hardware.opengl.videoDriversâ does not exist
- Problem: This option has been renamed.
- Solution: We changed
hardware.opengl.videoDriverstoservices.xserver.videoDrivers.
Error 2: `hardware.opengl.driSupportâ no longer has any effect
- Problem: This option is now enabled automatically when
hardware.opengl.enableis set totrue. - Solution: We simply removed the
driSupport = true;line from our configuration.
Error 3: Syntax Error, unexpected =
- Problem: A simple typo where we wrote
package = package = .... - Solution: We corrected the line to
package = config.boot.kernelPackages.nvidiaPackages.stable;.
Error 4: attribute âproduction_openâ missing
- Problem: We tried to use a package name (
production_open) that doesnât exist in this NixOS version. - Solution: We used the standard
stablepackage and relied on theopen = true;flag to select the correct variant.
Problem 5: The X11 Login Loop
- Problem: After rebuilding, we could log in to the Wayland session, but trying to log into the âPlasma (X11)â session would show a black screen and return us to the login prompt. This is a classic âlogin loopâ.
- Root Cause: PRIME Offload can be complex to configure and sometimes conflicts with the X server startup.
Step 3: The Final Solution - Switching to PRIME Sync
To solve the login loop, we switched from Offload mode to PRIME Sync. This mode is less power-efficient but significantly more stable and easier to configure. It uses the NVIDIA GPU for all rendering and simply displays the final image on the screen.
-
We modified the
hardware.nvidia.primeblock in ourconfiguration.nix:# Replace the entire 'prime' block with this: prime = { sync.enable = true; intelBusId = "PCI:0:2:0"; nvidiaBusId = "PCI:1:0:0"; }; -
We also removed
"modesetting"from thevideoDriverslist for maximum compatibility with X11:services.xserver.videoDrivers = [ "nvidia" ]; -
We ran
sudo nixos-rebuild switchand rebooted.
The Final Working Configuration
This is the final, working hardware.nvidia block that successfully configured our system:
# === NVIDIA CONFIGURATION FOR LAPTOP ===
hardware.graphics = {
enable = true;
enable32Bit = true;
};
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
modesetting.enable = true;
open = true;
nvidiaSettings = true;
package = config.boot.kernelPackages.nvidiaPackages.stable;
prime = {
sync.enable = true; # The stable solution
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
};
# === END OF NVIDIA CONFIGURATION ===
Verification
After rebooting and logging into the âPlasma (X11)â session, we verified the installation by opening a terminal and running:
nvidia-smi
This command displayed a detailed table with our GTX 1650 Tiâs information, confirming that the driver was active and correctly configured. Games and applications now use the NVIDIA GPU by default.