Skip to content
NullString1 edited this page Jan 13, 2026 · 2 revisions

NVIDIA Configuration

Complete guide to NVIDIA GPU configuration in NullOS, including PRIME setup for hybrid graphics laptops.

Overview

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


NVIDIA PRIME (Hybrid Graphics)

For laptops with both Intel integrated and NVIDIA dedicated GPUs.

What is NVIDIA PRIME?

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

Enabling PRIME

In variables.nix:

useNvidiaPrime = true;
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";

Finding Your Bus IDs

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.0PCI:0:2:0 (Intel)
  • 01:00.0PCI:1:0:0 (NVIDIA)

Method 2: Check Hardware Scan

sudo nixos-generate-config --show-hardware-config | grep -i bus

Configuration Details

The NVIDIA PRIME setup in NullOS:

# modules/system/nvidia.nix
hardware.nvidia = {
  modesetting.enable = true;           # Required for Wayland
  powerManagement.enable = true;       # Enable PM features
  powerManagement.finegrained = false; # Coarse-grained PM
  open = false;                        # Use proprietary driver
  nvidiaSettings = true;               # Include nvidia-settings
  package = config.boot.kernelPackages.nvidiaPackages.stable;
  
  prime = {
    intelBusId = vars.intelBusId;
    nvidiaBusId = vars.nvidiaBusId;
  };
};

Using PRIME Offload

Launch App on NVIDIA GPU

Use environment variables:

nvidia-offload firefox
nvidia-offload steam

Or manually:

__NV_PRIME_RENDER_OFFLOAD=1 \
__GLX_VENDOR_LIBRARY_NAME=nvidia \
firefox

Create Shortcuts

Add to your shell config:

# In home/zsh/zshrc-personal.nix
alias nvidia-run='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia'

Usage:

nvidia-run steam

Check Which GPU is Active

nvidia-smi

If NVIDIA is in use, you'll see active processes.


Dedicated NVIDIA GPU

For desktops or laptops with only NVIDIA GPU.

Configuration

In variables.nix:

useNvidiaPrime = false;

This uses NVIDIA as the primary GPU without PRIME offloading.

Full Configuration

# modules/system/nvidia.nix (when PRIME disabled)
services.xserver.videoDrivers = [ "nvidia" ];

hardware.nvidia = {
  modesetting.enable = true;
  powerManagement.enable = false;  # Not needed for desktop
  open = false;
  nvidiaSettings = true;
  package = config.boot.kernelPackages.nvidiaPackages.stable;
};

NVIDIA Driver Versions

Stable (Default)

package = config.boot.kernelPackages.nvidiaPackages.stable;

Recommended for most users.

Beta

package = config.boot.kernelPackages.nvidiaPackages.beta;

Latest features, potentially unstable.

Legacy

For older GPUs:

package = config.boot.kernelPackages.nvidiaPackages.legacy_470;
# or
package = config.boot.kernelPackages.nvidiaPackages.legacy_390;

Production

Long-term support branch:

package = config.boot.kernelPackages.nvidiaPackages.production;

Open Source vs Proprietary Driver

Proprietary (Default)

hardware.nvidia.open = false;

Pros:

  • Better performance
  • Full feature support
  • More stable

Cons:

  • Closed source
  • Larger driver

Open Source

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.


Power Management

Laptop Power Management

hardware.nvidia.powerManagement = {
  enable = true;              # Enable power management
  finegrained = 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

Desktop Power Management

hardware.nvidia.powerManagement = {
  enable = false;  # Not needed
};

Specialisations

Boot into different graphics configurations.

What are Specialisations?

Boot menu entries with different configurations:

  • Default: Hybrid graphics (PRIME offload)
  • NVIDIA Only: Dedicated GPU mode
  • Intel Only: Integrated graphics only

Creating Specialisations

Edit your hardware configuration (e.g., modules/system/hardware_nslapt.nix):

{ config, pkgs, lib, ... }:

{
  # Default configuration uses PRIME
  
  specialisation = {
    # NVIDIA-only mode (better performance, worse battery)
    nvidia-performance.configuration = {
      system.nixos.tags = [ "nvidia-performance" ];
      
      hardware.nvidia.prime.offload.enable = lib.mkForce false;
      hardware.nvidia.powerManagement.enable = lib.mkForce false;
      
      # Force NVIDIA as primary
      services.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 entirely
      boot.blacklistedKernelModules = [ "nvidia" "nvidia_drm" "nvidia_modeset" ];
      hardware.nvidia.prime.offload.enable = lib.mkForce false;
      services.xserver.videoDrivers = lib.mkForce [ "intel" ];
    };
  };
}

Using Specialisations

  1. Rebuild:
sudo nixos-rebuild switch --flake .#hostname
  1. Reboot

  2. Select from GRUB:

    • Default entry (Hybrid PRIME)
    • NixOS - nvidia-performance
    • NixOS - intel-only
  3. Boot into chosen configuration

Current Specialisation

Check which specialisation is active:

cat /run/current-system/specialisation

Wayland Configuration

Required for Hyprland

hardware.nvidia.modesetting.enable = true;

This enables DRM kernel mode setting, required for Wayland.

Hyprland Environment Variables

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 acceleration
  • GBM_BACKEND - Buffer management
  • __GLX_VENDOR_LIBRARY_NAME - OpenGL vendor
  • WLR_NO_HARDWARE_CURSORS - Fixes cursor on NVIDIA

NVIDIA Settings GUI

Launching nvidia-settings

nvidia-settings

Available when:

hardware.nvidia.nvidiaSettings = true;

Features

  • GPU monitoring
  • Fan control
  • Overclocking
  • Display configuration
  • Performance settings

Note: Settings made here are not persistent. Configure in NixOS for persistence.


Supergfxd

NullOS includes supergfxd for advanced GPU switching:

services.supergfxd.enable = true;

What is supergfxd?

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 hybrid

Monitoring NVIDIA GPU

nvidia-smi

Real-time GPU monitoring:

nvidia-smi

Watch mode (update every 2 seconds):

watch -n 2 nvidia-smi

Check Driver Version

nvidia-smi --query-gpu=driver_version --format=csv,noheader

GPU Utilization

nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader

Temperature

nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader

Gaming with NVIDIA

Steam Configuration

Steam is already configured in NullOS for NVIDIA.

File: modules/software/steam.nix

programs.steam = {
  enable = true;
  remotePlay.openFirewall = true;
  gamescopeSession.enable = true;
};

Launch Steam Game on NVIDIA

nvidia-offload steam

Or set per-game launch options in Steam:

__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia %command%

GameMode

NullOS includes GameMode for performance optimization:

gamemoderun ./game

For Steam, add to launch options:

gamemoderun %command%

CUDA and Machine Learning

Installing CUDA

environment.systemPackages = with pkgs; [
  cudatoolkit
  cudaPackages.cudnn
];

Ollama with NVIDIA

Ollama is configured to use CUDA:

# modules/services/ollama.nix
services.ollama = {
  enable = true;
  acceleration = "cuda";
};

PyTorch with CUDA

home.packages = with pkgs; [
  python3Packages.pytorch-bin  # CUDA-enabled
];

Or in a dev shell:

# shell.nix
{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = with pkgs; [
    python3
    python3Packages.pytorch-bin
    cudatoolkit
  ];
}

Troubleshooting

Screen Tearing

Enable NVIDIA composition pipeline:

services.xserver.screenSection = ''
  Option "metamodes" "nvidia-auto-select +0+0 {ForceFullCompositionPipeline=On}"
'';

For Wayland/Hyprland, add:

# In hyprland config
env = WLR_DRM_NO_ATOMIC,1

Black Screen on Boot

Try 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"
];

NVIDIA Module Not Loading

Check if blacklisted:

lsmod | grep nvidia

Load manually:

sudo modprobe nvidia

Check for conflicts in hardware config.

Suspend/Resume Issues

Enable preserve video memory:

hardware.nvidia.powerManagement.enable = true;

boot.kernelParams = [
  "nvidia.NVreg_PreserveVideoMemoryAllocations=1"
];

# Required services
systemd.services.nvidia-hibernate = { ... };
systemd.services.nvidia-suspend = { ... };
systemd.services.nvidia-resume = { ... };

Poor Performance

  1. Check GPU is being used:
nvidia-smi
  1. Verify offload variables:
echo $__NV_PRIME_RENDER_OFFLOAD
  1. Use correct driver version

  2. Disable power management temporarily:

hardware.nvidia.powerManagement.enable = false;

NVIDIA Settings Not Saving

Settings made in nvidia-settings GUI don't persist.

Solution: Configure in NixOS:

services.xserver.deviceSection = ''
  Option "Coolbits" "4"  # Fan control
'';

Performance Tuning

Force Maximum Performance

nvidia-smi -pm 1  # Enable persistence mode
nvidia-smi -pl 150  # Set power limit (watts)

Overclocking

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.


Multi-GPU Setup

Multiple NVIDIA GPUs

NixOS detects automatically. To configure specific GPUs:

hardware.nvidia.prime = {
  # GPU 0
  nvidiaBusId = "PCI:1:0:0";
  
  # GPU 1 would be configured separately
};

NVIDIA + AMD

Not officially supported by NVIDIA PRIME. Use:

  • Manual GPU selection
  • DRI_PRIME for AMD rendering
  • NVIDIA offload for NVIDIA rendering

Best Practices

  1. Start with PRIME - On laptops, use hybrid mode
  2. Test Specialisations - Create boot options for flexibility
  3. Monitor Power Usage - Use powertop to check battery impact
  4. Keep Drivers Updated - Update flake for latest drivers
  5. Use Offload Wisely - Only run heavy apps on NVIDIA
  6. Check Logs - Review journalctl for NVIDIA errors
  7. Backup Working Config - Commit to git when stable

Useful Commands

# 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 using
echo $WLR_RENDERER_ALLOW_SOFTWARE

Next Steps

Clone this wiki locally