- Notifications
You must be signed in to change notification settings - Fork 0
NVIDIA
Complete guide to NVIDIA GPU configuration in NullOS, including PRIME setup for hybrid graphics laptops.
NullOS supports NVIDIA GPUs with:
- NVIDIA PRIME - Hybrid graphics (Intel + NVIDIA)
- Dedicated GPU - Desktop with NVIDIA only
- Power Management - Laptop power optimization
- Specialisations - Boot-time graphics switching
Configuration File:modules/system/nvidia.nix
For laptops with both Intel integrated and NVIDIA dedicated GPUs.
NVIDIA PRIME allows:
- Default: Use Intel GPU (better battery life)
- On-Demand: Launch apps on NVIDIA GPU when needed
- Performance: Full NVIDIA power when required
In machines/{hostname}/default.nix:
useNvidiaPrime=true;intelBusId="PCI:0:2:0";nvidiaBusId="PCI:1:0:0";Method 1: Using lspci
nix-shell -p pciutils --run "lspci | grep -i vga"Output example:
00:02.0 VGA compatible controller: Intel Corporation ...
01:00.0 VGA compatible controller: NVIDIA Corporation ...
Convert to NixOS format:
00:02.0→PCI:0:2:0(Intel)01:00.0→PCI:1:0:0(NVIDIA)
Method 2: Check Hardware Scan
sudo nixos-generate-config --show-hardware-config | grep -i busThe NVIDIA PRIME setup in NullOS:
# modules/system/nvidia.nixhardware.nvidia={modesetting.enable=true;# Required for WaylandpowerManagement.enable=true;# Enable PM featurespowerManagement.finegrained=false;# Coarse-grained PMopen=false;# Use proprietary drivernvidiaSettings=true;# Include nvidia-settingspackage=config.boot.kernelPackages.nvidiaPackages.stable;prime={intelBusId=vars.intelBusId;nvidiaBusId=vars.nvidiaBusId;};};Use environment variables:
nvidia-offload firefox
nvidia-offload steamOr manually:
__NV_PRIME_RENDER_OFFLOAD=1 \
__GLX_VENDOR_LIBRARY_NAME=nvidia \
firefoxAdd to your shell config:
# In home/zsh/zshrc-personal.nixalias nvidia-run='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia'Usage:
nvidia-run steamnvidia-smiIf NVIDIA is in use, you'll see active processes.
For desktops or laptops with only NVIDIA GPU.
In machines/{hostname}/default.nix:
useNvidiaPrime=false;This uses NVIDIA as the primary GPU without PRIME offloading.
# modules/system/nvidia.nix (when PRIME disabled)services.xserver.videoDrivers=["nvidia"];hardware.nvidia={modesetting.enable=true;powerManagement.enable=false;# Not needed for desktopopen=false;nvidiaSettings=true;package=config.boot.kernelPackages.nvidiaPackages.stable;};package=config.boot.kernelPackages.nvidiaPackages.stable;Recommended for most users.
package=config.boot.kernelPackages.nvidiaPackages.beta;Latest features, potentially unstable.
For older GPUs:
package=config.boot.kernelPackages.nvidiaPackages.legacy_470;# orpackage=config.boot.kernelPackages.nvidiaPackages.legacy_390;Long-term support branch:
package=config.boot.kernelPackages.nvidiaPackages.production;hardware.nvidia.open=false;Pros:
- Better performance
- Full feature support
- More stable
Cons:
- Closed source
- Larger driver
hardware.nvidia.open=true;Pros:
- Open source
- Community maintained
- Smaller
Cons:
- Limited GPU support (RTX 20 series and newer)
- Fewer features
- Potentially less stable
Note: Only works with Turing (RTX 20 series) and newer GPUs.
hardware.nvidia.powerManagement={enable=true;# Enable power managementfinegrained=false;# Use coarse-grained (recommended)};Coarse-grained (finegrained = false):
- GPU fully powered off when not in use
- Longer wake-up time
- Better battery life
- Recommended for laptops
Fine-grained (finegrained = true):
- GPU in low-power state
- Faster wake-up
- Slightly worse battery
- Experimental
hardware.nvidia.powerManagement={enable=false;# Not needed};Boot into different graphics configurations.
Boot menu entries with different configurations:
- Default: Hybrid graphics (PRIME offload)
- NVIDIA Only: Dedicated GPU mode
- Intel Only: Integrated graphics only
Edit your hardware configuration (e.g., modules/system/hardware_nslapt.nix):
{config,pkgs,lib, ... }:
{# Default configuration uses PRIMEspecialisation={# NVIDIA-only mode (better performance, worse battery)nvidia-performance.configuration={system.nixos.tags=["nvidia-performance"];hardware.nvidia.prime.offload.enable=lib.mkForcefalse;hardware.nvidia.powerManagement.enable=lib.mkForcefalse;# Force NVIDIA as primaryservices.xserver.displayManager.sessionCommands='' export __NV_PRIME_RENDER_OFFLOAD=0 '';};# Intel-only mode (best battery, no NVIDIA)intel-only.configuration={system.nixos.tags=["intel-only"];# Disable NVIDIA entirelyboot.blacklistedKernelModules=["nvidia""nvidia_drm""nvidia_modeset"];hardware.nvidia.prime.offload.enable=lib.mkForcefalse;services.xserver.videoDrivers=lib.mkForce["intel"];};};}- Rebuild:
sudo nixos-rebuild switch --flake .#hostnameReboot
Select from GRUB:
- Default entry (Hybrid PRIME)
- NixOS - nvidia-performance
- NixOS - intel-only
Boot into chosen configuration
Check which specialisation is active:
cat /run/current-system/specialisationhardware.nvidia.modesetting.enable=true;This enables DRM kernel mode setting, required for Wayland.
Set in home/hyprland/env.nix:
env=["LIBVA_DRIVER_NAME,nvidia""XDG_SESSION_TYPE,wayland""GBM_BACKEND,nvidia-drm""__GLX_VENDOR_LIBRARY_NAME,nvidia""WLR_NO_HARDWARE_CURSORS,1"];Why these variables?
LIBVA_DRIVER_NAME- Hardware video accelerationGBM_BACKEND- Buffer management__GLX_VENDOR_LIBRARY_NAME- OpenGL vendorWLR_NO_HARDWARE_CURSORS- Fixes cursor on NVIDIA
nvidia-settingsAvailable when:
hardware.nvidia.nvidiaSettings=true;- GPU monitoring
- Fan control
- Overclocking
- Display configuration
- Performance settings
Note: Settings made here are not persistent. Configure in NixOS for persistence.
NullOS includes supergfxd for advanced GPU switching:
services.supergfxd.enable=true;Graphics switching daemon for laptops with hybrid graphics.
Features:
- Dynamic GPU switching
- Power management
- Integration with system76-power
Usage:
# Check status
supergfxctl -S
# Switch to integrated
supergfxctl -m integrated
# Switch to NVIDIA
supergfxctl -m nvidia
# Hybrid mode
supergfxctl -m hybridReal-time GPU monitoring:
nvidia-smiWatch mode (update every 2 seconds):
watch -n 2 nvidia-sminvidia-smi --query-gpu=driver_version --format=csv,noheadernvidia-smi --query-gpu=utilization.gpu --format=csv,noheadernvidia-smi --query-gpu=temperature.gpu --format=csv,noheaderSteam is already configured in NullOS for NVIDIA.
File:modules/software/steam.nix
programs.steam={enable=true;remotePlay.openFirewall=true;gamescopeSession.enable=true;};nvidia-offload steamOr set per-game launch options in Steam:
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia %command%
NullOS includes GameMode for performance optimization:
gamemoderun ./gameFor Steam, add to launch options:
gamemoderun %command%
environment.systemPackages=withpkgs;[cudatoolkitcudaPackages.cudnn];Ollama is configured to use CUDA:
# modules/services/ollama.nixservices.ollama={enable=true;acceleration="cuda";};home.packages=withpkgs;[python3Packages.pytorch-bin# CUDA-enabled];Or in a dev shell:
# shell.nix{pkgs ? import<nixpkgs>{}}:
pkgs.mkShell{buildInputs=withpkgs;[python3python3Packages.pytorch-bincudatoolkit];}Enable NVIDIA composition pipeline:
services.xserver.screenSection='' Option "metamodes" "nvidia-auto-select +0+0 {ForceFullCompositionPipeline=On}"'';For Wayland/Hyprland, add:
# In hyprland configenv=WLR_DRM_NO_ATOMIC,1Try different modesetting:
hardware.nvidia.modesetting.enable=false;Or boot parameters in modules/system/boot.nix:
boot.kernelParams=["nvidia-drm.modeset=1""nvidia.NVreg_PreserveVideoMemoryAllocations=1"];Check if blacklisted:
lsmod | grep nvidiaLoad manually:
sudo modprobe nvidiaCheck for conflicts in hardware config.
Enable preserve video memory:
hardware.nvidia.powerManagement.enable=true;boot.kernelParams=["nvidia.NVreg_PreserveVideoMemoryAllocations=1"];# Required servicessystemd.services.nvidia-hibernate={ ... };systemd.services.nvidia-suspend={ ... };systemd.services.nvidia-resume={ ... };- Check GPU is being used:
nvidia-smi- Verify offload variables:
echo$__NV_PRIME_RENDER_OFFLOADUse correct driver version
Disable power management temporarily:
hardware.nvidia.powerManagement.enable=false;Settings made in nvidia-settings GUI don't persist.
Solution: Configure in NixOS:
services.xserver.deviceSection='' Option "Coolbits" "4" # Fan control'';nvidia-smi -pm 1 # Enable persistence mode
nvidia-smi -pl 150 # Set power limit (watts)Enable in configuration:
services.xserver.deviceSection='' Option "Coolbits" "28"'';Then use nvidia-settings or:
nvidia-settings -a "[gpu:0]/GPUGraphicsClockOffset[3]=100"
nvidia-settings -a "[gpu:0]/GPUMemoryTransferRateOffset[3]=200"Warning: Overclocking can cause instability. Test carefully.
NixOS detects automatically. To configure specific GPUs:
hardware.nvidia.prime={# GPU 0nvidiaBusId="PCI:1:0:0";# GPU 1 would be configured separately};Not officially supported by NVIDIA PRIME. Use:
- Manual GPU selection
- DRI_PRIME for AMD rendering
- NVIDIA offload for NVIDIA rendering
- Start with PRIME - On laptops, use hybrid mode
- Test Specialisations - Create boot options for flexibility
- Monitor Power Usage - Use
powertopto check battery impact - Keep Drivers Updated - Update flake for latest drivers
- Use Offload Wisely - Only run heavy apps on NVIDIA
- Check Logs - Review
journalctlfor NVIDIA errors - Backup Working Config - Commit to git when stable
# GPU information
nvidia-smi
# Driver version
nvidia-smi --query-gpu=driver_version --format=csv
# Check PRIME status
glxinfo | grep "OpenGL renderer"# Test NVIDIA offload
__NV_PRIME_RENDER_OFFLOAD=1 glxinfo | grep "OpenGL renderer"# Monitor GPU continuously
watch -n 1 nvidia-smi
# supergfxd status
supergfxctl -S
# Check which GPU Wayland is usingecho$WLR_RENDERER_ALLOW_SOFTWARE- Specialisations - Advanced boot configurations
- Power Management - Optimize battery life
- Gaming - Gaming-specific configuration
- Troubleshooting - Solve common issues