1{
2 pkgs,
3 config,
4 ...
5}:
6let
7 nvidiaDriverChannel = config.boot.kernelPackages.nvidiaPackages.production;
8in
9{
10 services.xserver.videoDrivers = [
11 "nvidia"
12 "amdgpu"
13 ];
14
15 nixpkgs.config = {
16 nvidia.acceptLicense = true;
17 allowUnfree = true;
18 cudaSupport = true;
19 };
20 # Kernel parameters for better Wayland and Hyprland integration
21 boot.kernelParams = [
22 "nvidia-drm.modeset=1" # Enable mode setting for Wayland
23 "nvidia.NVreg_PreserveVideoMemoryAllocations=1" # Improves resume after sleep
24 ];
25
26 # Blacklist nouveau to avoid conflicts
27 boot.blacklistedKernelModules = [ "nouveau" ];
28 environment.variables = {
29 LIBVA_DRIVER_NAME = "nvidia"; # Hardware video acceleration
30 XDG_SESSION_TYPE = "wayland"; # Force Wayland
31 GBM_BACKEND = "nvidia-drm"; # Graphics backend for Wayland
32 __GLX_VENDOR_LIBRARY_NAME = "nvidia"; # Use Nvidia driver for GLX
33 WLR_NO_HARDWARE_CURSORS = "1"; # Fix for cursors on Wayland
34 NIXOS_OZONE_WL = "1"; # Wayland support for Electron apps
35 __GL_GSYNC_ALLOWED = "1"; # Enable G-Sync if available
36 __GL_VRR_ALLOWED = "1"; # Enable VRR (Variable Refresh Rate)
37 WLR_DRM_NO_ATOMIC = "1"; # Fix for some issues with Hyprland
38 NVD_BACKEND = "direct"; # Configuration for new driver
39 MOZ_ENABLE_WAYLAND = "1"; # Wayland support for Firefox
40 };
41
42 hardware = {
43 nvidia = {
44 forceFullCompositionPipeline = true; # Prevents screen tearing
45 # Modesetting is required.
46 modesetting.enable = true;
47
48 powerManagement = {
49 enable = true; # Power management
50 finegrained = true; # More precise power consumption control
51 };
52
53 prime = {
54 offload = {
55 enable = true;
56 enableOffloadCmd = true;
57 };
58
59 nvidiaBusId = "PCI:1:0:0";
60 amdgpuBusId = "PCI:15:0:0";
61
62 };
63
64 # Use the NVidia open source kernel module (not to be confused with the
65 # independent third-party "nouveau" open source driver).
66 # Currently alpha-quality/buggy, so false is currently the recommended setting.
67 open = true;
68
69 # Environment variables for better compatibility
70
71 # Enable the Nvidia settings menu,
72 # accessible via `nvidia-settings`.
73 nvidiaSettings = true;
74
75 package = nvidiaDriverChannel;
76
77 # #Fixes a glitch
78 # nvidiaPersistenced = true;
79 };
80 nvidia-container-toolkit.enable = true;
81
82 graphics = {
83 enable = true;
84 package = nvidiaDriverChannel;
85 enable32Bit = true;
86 extraPackages = with pkgs; [
87 nvidia-vaapi-driver
88 libva-vdpau-driver
89 libvdpau-va-gl
90 mesa
91 egl-wayland
92 vulkan-loader
93 vulkan-validation-layers
94 libva
95 ];
96 };
97 };
98
99 nix.settings = {
100 substituters = [
101 "https://cache.nixos-cuda.org"
102
103 ];
104 trusted-public-keys = [
105 "cache.nixos-cuda.org:74DUi4Ye579gUqzH4ziL9IyiJBlDpMRn9MBN8oNan9M="
106 ];
107 };
108
109 environment.systemPackages = with pkgs; [
110 vulkan-tools
111 mesa-demos
112 libva-utils # VA-API debugging tools
113 ];
114}