{ config, lib, pkgs, ... }: with lib; let cfg = config.graphics; in { options.graphics = { gpuVendor = mkOption { type = types.enum ["nvidia" "amd" "intel" "none"]; default = "none"; description = "GPU vendor to configure graphics drivers for"; }; enable = mkEnableOption "graphics configuration"; wayland = { enable = mkEnableOption "Wayland support"; variableRefreshRate = mkOption { type = types.bool; default = false; description = "Enable variable refresh rate (FreeSync/G-Sync) support"; }; }; vulkan = { enable = mkEnableOption "Vulkan support"; debug = mkOption { type = types.bool; default = false; description = "Enable Vulkan validation layers"; }; }; }; config = mkIf cfg.enable (mkMerge [ { environment.systemPackages = with pkgs; [ glxinfo vulkan-tools mesa-demos ]; } (mkIf (cfg.gpuVendor == "nvidia") { services.xserver.videoDrivers = ["nvidia"]; hardware.nvidia = { package = config.boot.kernelPackages.nvidiaPackages.stable; open = true; modesetting.enable = true; powerManagement.enable = true; }; environment.systemPackages = with pkgs; [ nvidia-vaapi-driver nvtopPackages.full ]; }) (mkIf (cfg.gpuVendor == "amd") { services.xserver.videoDrivers = ["amdgpu"]; hardware.opengl.extraPackages = with pkgs; [ rocm-opencl-icd rocm-opencl-runtime amdvlk ]; environment.systemPackages = with pkgs; [ radeontop ]; }) (mkIf (cfg.gpuVendor == "intel") { services.xserver.videoDrivers = ["modesetting"]; hardware.opengl.extraPackages = with pkgs; [ intel-media-driver intel-compute-runtime ]; }) (mkIf cfg.wayland.enable { programs.xwayland.enable = true; environment.sessionVariables = { MOZ_ENABLE_WAYLAND = "1"; QT_QPA_PLATFORM = "wayland"; SDL_VIDEODRIVER = "wayland"; }; }) (mkIf cfg.vulkan.enable { environment.systemPackages = with pkgs; [ vulkan-loader vulkan-validation-layers ] ++ ( if cfg.vulkan.debug then [ vulkan-tools ] else [] ); }) ]); }