nixos-config/modules/common/hardware.nix

59 lines
1.4 KiB
Nix

{
lib,
config,
pkgs,
machineProps,
...
}:
let
gpu = config.my.hardware.gpu;
hwAccelerationOptionPath = if (machineProps.nixpkgs == "unstable") then "graphics" else "opengl";
enable32BitOptionName =
if (machineProps.nixpkgs == "unstable") then "enable32Bit" else "driSupport32Bit";
anyWineUser =
if machineProps.enableHomeManager then
(builtins.any (user: user.my.games.wine.enable) (builtins.attrValues config.home-manager.users))
else
false;
in
with lib;
{
options.my.hardware.gpu = mkOption {
type = types.nullOr (
types.enum [
"nvidia"
"intel"
"amd"
]
);
default = null;
example = "nvidia";
description = ''
The GPU type.
'';
};
config = {
boot.kernelParams = mkIf (gpu == "intel") [ "i915.enable_guc=2" ];
services.xserver.videoDrivers = mkIf (gpu == "nvidia") [ "nvidia" ];
# Small hack as this option path changes between 24.05 and unstable
hardware.${hwAccelerationOptionPath} = {
enable = gpu != null;
"${enable32BitOptionName}" = anyWineUser;
extraPackages = with pkgs; [
(mkIf (gpu == "intel") intel-media-driver)
(mkIf (gpu == "intel") intel-compute-runtime)
];
};
hardware.nvidia = mkIf (gpu == "nvidia") {
open = true;
package = config.boot.kernelPackages.nvidiaPackages.beta;
};
};
}