2024-06-24 11:38:28 -04:00
|
|
|
# Enables Nvidia GPU support.
|
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.aux.system.gpu.nvidia;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
aux.system.gpu.nvidia = {
|
2024-09-08 11:58:56 -04:00
|
|
|
enable = lib.mkEnableOption "Enables Nvidia GPU support.";
|
2024-06-24 11:38:28 -04:00
|
|
|
hybrid = {
|
2024-09-08 11:58:56 -04:00
|
|
|
enable = lib.mkEnableOption "Enables hybrid GPU support.";
|
|
|
|
sync = lib.mkEnableOption "Enables sync mode for faster performance at the cost of higher battery usage.";
|
2024-06-24 11:38:28 -04:00
|
|
|
busIDs = {
|
|
|
|
nvidia = lib.mkOption {
|
|
|
|
description = "The bus ID for your Nvidia GPU.";
|
|
|
|
type = lib.types.str;
|
|
|
|
example = "PCI:0:2:0";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
intel = lib.mkOption {
|
|
|
|
description = "The bus ID for your integrated Intel GPU. If you don't have an Intel GPU, you can leave this blank.";
|
|
|
|
type = lib.types.str;
|
|
|
|
example = "PCI:14:0:0";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
amd = lib.mkOption {
|
|
|
|
description = "The bus ID for your integrated AMD GPU. If you don't have an AMD GPU, you can leave this blank.";
|
|
|
|
type = lib.types.str;
|
|
|
|
example = "PCI:54:0:0";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
2024-07-01 15:51:13 -04:00
|
|
|
assertion = (cfg.hybrid.busIDs.nvidia != "");
|
2024-07-13 13:34:59 -04:00
|
|
|
message = "You need to define a bus ID for your Nvidia GPU. To learn how to find the bus ID, see https://wiki.nixos.org/wiki/Nvidia#Configuring_Optimus_PRIME:_Bus_ID_Values_.28Mandatory.29.";
|
2024-06-24 11:38:28 -04:00
|
|
|
}
|
|
|
|
{
|
2024-07-01 15:51:13 -04:00
|
|
|
assertion = (cfg.hybrid.busIDs.intel != "" || cfg.hybrid.busIDs.amd != "");
|
2024-07-13 13:34:59 -04:00
|
|
|
message = "You need to define a bus ID for your non-Nvidia GPU. To learn how to find your bus ID, see https://wiki.nixos.org/wiki/Nvidia#Configuring_Optimus_PRIME:_Bus_ID_Values_.28Mandatory.29.";
|
2024-06-24 11:38:28 -04:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
aux.system.allowUnfree = true;
|
|
|
|
|
|
|
|
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
|
2024-09-08 11:58:56 -04:00
|
|
|
hardware = {
|
|
|
|
opengl.extraPackages = with pkgs; [ vaapiVdpau ];
|
|
|
|
nvidia = {
|
|
|
|
modesetting.enable = true;
|
|
|
|
nvidiaSettings = config.aux.system.ui.desktops.enable;
|
|
|
|
package = config.boot.kernelPackages.nvidiaPackages.stable;
|
|
|
|
prime = lib.mkIf cfg.hybrid.enable {
|
2024-06-24 11:38:28 -04:00
|
|
|
|
2024-09-08 11:58:56 -04:00
|
|
|
offload = lib.mkIf (!cfg.hybrid.sync) {
|
|
|
|
enable = true;
|
|
|
|
enableOffloadCmd = true; # Provides `nvidia-offload` command.
|
|
|
|
};
|
2024-06-24 11:38:28 -04:00
|
|
|
|
2024-09-08 11:58:56 -04:00
|
|
|
sync.enable = cfg.hybrid.sync;
|
2024-06-24 11:38:28 -04:00
|
|
|
|
2024-09-08 11:58:56 -04:00
|
|
|
nvidiaBusId = cfg.hybrid.busIDs.nvidia;
|
|
|
|
intelBusId = cfg.hybrid.busIDs.intel;
|
|
|
|
amdgpuBusId = cfg.hybrid.busIDs.amd;
|
|
|
|
};
|
2024-06-24 11:38:28 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|