{ config, lib, pkgs, ... }: let inherit (lib.modules) mkDefault mkIf; inherit (lib.options) mkEnableOption; cfg = config.modules.system.hardware; in { options.modules.system.hardware = { nvidia = { enable = mkEnableOption "Nvidia graphics drivers"; }; amd.enable = mkEnableOption "AMD graphics drivers"; }; config = { hardware = { graphics = { enable = true; extraPackages = [ pkgs.nvidia-vaapi-driver ]; }; nvidia = mkIf cfg.nvidia.enable { open = mkDefault true; # Whether to enable kernel modesetting when using the NVIDIA proprietary driver. # Enabling this causes the proprietary NVIDIA driver to provide its own # framebuffer device, which can cause Wayland compositors to work when # they otherwise wouldn’t. . modesetting.enable = true; # nvidia-settings is useless on NixOS. nvidiaSettings = false; # fixes sleep on nvidia devices powerManagement = { enable = true; finegrained = false; }; package = config.boot.kernelPackages.nvidiaPackages.beta; }; }; services.xserver.videoDrivers = [ "nvidia" ]; environment.systemPackages = builtins.attrValues { inherit (pkgs) mesa vulkan-tools vulkan-loader libva libva-utils ; inherit (pkgs.nvtopPackages) nvidia; }; # Nouveau is a set of free and open-source drivers for NVIDIA GPUs # that provide 2D/3D acceleration for all NVIDIA GPUs. # Its use is in general not recommended due to its considerably worse # performance compared to NVIDIA's kernel modules, as it does not # support reclocking (changing the GPU clock frequency on-demand) # for many NVIDIA GPUs. # I therefore disable it to save myself from headaches. boot.blacklistedKernelModules = mkIf cfg.nvidia.enable [ "nouveau" ]; }; }