feat: nvidia drivers for oreo

This commit is contained in:
2026-06-08 11:27:28 -04:00
parent 118300d92f
commit 141a785cc5
4 changed files with 121 additions and 3 deletions
+104
View File
@@ -0,0 +1,104 @@
{ config, lib, ... }:
{
options.modules.nvidia = {
enable = lib.mkEnableOption "NVIDIA proprietary drivers";
open = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Use the open-source NVIDIA kernel module.
Set to true for Turing (RTX 20-series) and newer.
Set to false for older architectures.
'';
};
package = lib.mkOption {
type = lib.types.package;
default = config.boot.kernelPackages.nvidiaPackages.stable;
defaultText = lib.literalExpression
"config.boot.kernelPackages.nvidiaPackages.stable";
description = "The NVIDIA driver package to use.";
};
prime = {
enable = lib.mkEnableOption "NVIDIA Optimus PRIME (hybrid graphics)";
mode = lib.mkOption {
type = lib.types.enum [ "offload" "sync" "reverse-sync" ];
default = "offload";
description = ''
Which PRIME mode to use.
offload — iGPU handles everything; dGPU used on demand (best battery)
sync — dGPU always active; best performance, less tearing
reverse-sync — experimental; dGPU primary, iGPU for outputs
'';
};
intelBusId = lib.mkOption {
type = lib.types.str;
default = "";
example = "PCI:0:2:0";
description = "PCI bus ID of the Intel iGPU (from lshw -c display).";
};
amdBusId = lib.mkOption {
type = lib.types.str;
default = "";
example = "PCI:54:0:0";
description = "PCI bus ID of the AMD iGPU (from lshw -c display). Leave empty if Intel.";
};
nvidiaBusId = lib.mkOption {
type = lib.types.str;
default = "";
example = "PCI:14:0:0";
description = "PCI bus ID of the NVIDIA dGPU (from lshw -c display).";
};
};
};
config = lib.mkIf config.modules.nvidia.enable {
hardware.graphics.enable = true;
services.xserver.videoDrivers =
if config.modules.nvidia.prime.enable
&& config.modules.nvidia.prime.mode == "offload"
then [
(if config.modules.nvidia.prime.amdBusId != "" then "amdgpu" else "modesetting")
"nvidia"
]
else [ "nvidia" ];
hardware.nvidia = {
modesetting.enable = true;
open = config.modules.nvidia.open;
nvidiaSettings = true;
package = config.modules.nvidia.package;
powerManagement.enable = false;
powerManagement.finegrained = false;
prime = lib.mkIf config.modules.nvidia.prime.enable (
let
busIds = lib.filterAttrs (_: v: v != "") {
intelBusId = config.modules.nvidia.prime.intelBusId;
amdgpuBusId = config.modules.nvidia.prime.amdBusId;
nvidiaBusId = config.modules.nvidia.prime.nvidiaBusId;
};
modeConfig =
if config.modules.nvidia.prime.mode == "offload" then {
offload.enable = true;
offload.enableOffloadCmd = true;
} else if config.modules.nvidia.prime.mode == "sync" then {
sync.enable = true;
} else {
reverseSync.enable = true;
allowExternalGpu = false;
};
in busIds // modeConfig
);
};
};
}