# 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 # 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" ]; }