nix-config-v2/modules/graphics/default.nix

108 lines
2.4 KiB
Nix
Raw Permalink Normal View History

2024-12-12 19:41:58 -06:00
{
config,
2024-12-23 14:35:36 -06:00
lib,
pkgs,
2024-12-12 19:41:58 -06:00
...
2024-12-23 14:35:36 -06:00
}:
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;
2024-12-12 19:41:58 -06:00
[
2024-12-23 14:35:36 -06:00
vulkan-loader
vulkan-validation-layers
2024-12-12 19:41:58 -06:00
]
++ (
2024-12-23 14:35:36 -06:00
if cfg.vulkan.debug
2024-12-12 19:41:58 -06:00
then [
2024-12-23 14:35:36 -06:00
vulkan-tools
2024-12-12 19:41:58 -06:00
]
else []
2024-12-23 14:35:36 -06:00
);
})
]);
2024-12-12 19:41:58 -06:00
}