modules/graphics.nix (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# graphics.nix - NVIDIA RTX 4060 Max-Q + AMD Radeon 780M hybrid graphics configuration
# Import this in your configuration.nix with: imports = [ ./graphics.nix ];
{ config, lib, pkgs, ... }:
{
# Enable OpenGL/graphics support
hardware.graphics = {
enable = true;
enable32Bit = true; # For 32-bit applications and games
};
# NVIDIA driver configuration
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
# Use the latest production driver (or specify version if needed)
# package = config.boot.kernelPackages.nvidiaPackages.stable;
# For your current version (590.48.01), you can use:
package = config.boot.kernelPackages.nvidiaPackages.beta;
# Modesetting is required for Wayland compositors
modesetting.enable = true;
# Power management (important for laptops)
# Enable this if you want the GPU to power down when not in use
powerManagement.enable = true;
# Fine-grained power management (experimental)
# This can help with battery life but may cause issues
# Disable if you experience problems
powerManagement.finegrained = false;
# Enable the NVIDIA settings menu accessible via `nvidia-settings`
nvidiaSettings = true;
# NVIDIA Prime configuration for hybrid graphics
prime = {
# Choose your sync mode - pick ONE of the following options:
# Option 1: offload mode (RECOMMENDED for laptops)
# AMD GPU is used by default, NVIDIA only when explicitly requested
# Best for battery life
offload = {
enable = true;
enableOffloadCmd = true; # Enables `nvidia-offload` command
};
# Option 2: sync mode (uncomment if you want both GPUs active)
# Both GPUs are always active, displays can use either
# Better performance but worse battery life
#sync.enable = true;
# Option 3: reverse-sync mode (uncomment if needed)
# NVIDIA is primary, can render to AMD outputs
# reversesync.enable = true;
# Bus IDs - find yours with: lspci | grep -E 'VGA|3D'
# Format is "PCI:X:Y:Z" where X:Y.Z is from lspci output
# Example: "01:00.0" becomes "PCI:1:0:0"
# NVIDIA GPU Bus ID (01:00.0)
nvidiaBusId = "PCI:1:0:0";
};
# Open source kernel module (experimental, not recommended for gaming)
# Set to false to use proprietary drivers (recommended)
open = false;
};
# Wayland-specific NVIDIA environment variables for Hyprland
environment.sessionVariables = {
# Enable Wayland support
NIXOS_OZONE_WL = "1";
# NVIDIA-specific Wayland variables
WLR_NO_HARDWARE_CURSORS = "1"; # Fixes cursor issues on NVIDIA
# Force GBM backend (recommended for NVIDIA on Wayland)
#GBM_BACKEND = "nvidia-drm";
#__GLX_VENDOR_LIBRARY_NAME = "nvidia";
# NVIDIA direct rendering
#LIBVA_DRIVER_NAME = "nvidia";
# Disable hardware cursor for NVIDIA
#WLR_RENDERER_ALLOW_SOFTWARE = "1";
WLR_DRM_DEVICES = "/dev/dri/card1";
ELECTRON_OZONE_PLATFORM_HINT = "auto";
};
# Kernel parameters for NVIDIA
boot.kernelParams = [
"nvidia-drm.modeset=1" # Enable modesetting
"nvidia-drm.fbdev=0" # Enable fbdev
#"module_blacklist=amdgpu"
];
# Early loading of NVIDIA modules
boot.initrd.kernelModules = [
"nvidia"
"nvidia_modeset"
"nvidia_uvm"
"nvidia_drm"
];
# Additional packages for graphics tools
environment.systemPackages = with pkgs; [
# NVIDIA tools
nvtopPackages.nvidia # GPU monitoring
# Vulkan tools
vulkan-tools
vulkan-loader
vulkan-validation-layers
# AMD GPU tools (for your integrated GPU)
radeontop
];
# Optional: Create nvidia-offload command for launching apps on NVIDIA GPU
# Usage: nvidia-offload <application>
# This is only needed if using offload mode
environment.shellAliases = {
nvidia-offload = "env __NV_PRIME_RENDER_OFFLOAD=1 __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 __GLX_VENDOR_LIBRARY_NAME=nvidia __VK_LAYER_NV_optimus=NVIDIA_only";
};
# Optional: Blacklist nouveau (open-source NVIDIA driver)
# Uncomment if you have issues with nouveau conflicting
# boot.blacklistedKernelModules = [ "nouveau" ];
}
|