2023-07-15 22:45:35 +08:00
|
|
|
inputs:
|
|
|
|
{
|
|
|
|
options.nixos.hardware = let inherit (inputs.lib) mkOption types; in
|
|
|
|
{
|
|
|
|
bluetooth.enable = mkOption { type = types.bool; default = false; };
|
2023-07-15 22:48:24 +08:00
|
|
|
joystick.enable = mkOption { type = types.bool; default = false; };
|
2023-07-18 18:19:00 +08:00
|
|
|
printer.enable = mkOption { type = types.bool; default = false; };
|
2023-07-19 00:10:36 +08:00
|
|
|
sound.enable = mkOption { type = types.bool; default = false; };
|
2023-07-27 11:05:14 +08:00
|
|
|
cpus = mkOption { type = types.listOf (types.enum [ "intel" "amd" ]); default = []; };
|
|
|
|
gpus = mkOption { type = types.listOf (types.enum [ "intel" "nvidia" ]); default = []; };
|
|
|
|
prime =
|
|
|
|
{
|
|
|
|
enable = mkOption { type = types.bool; default = false; };
|
|
|
|
mode = mkOption { type = types.enum [ "offload" "sync" ]; default = "offload"; };
|
|
|
|
busId = mkOption { type = types.attrsOf types.str; default = {}; };
|
|
|
|
};
|
2023-08-21 01:38:14 +08:00
|
|
|
gamemode.drmDevice = mkOption { type = types.int; default = 0; };
|
2023-07-18 18:19:00 +08:00
|
|
|
};
|
2023-07-26 23:36:12 +08:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
inherit (inputs.lib) mkMerge mkIf;
|
|
|
|
inherit (inputs.config.nixos) hardware;
|
|
|
|
inherit (builtins) listToAttrs map concatLists;
|
2023-07-27 11:05:14 +08:00
|
|
|
inherit (inputs.localLib) attrsToList;
|
2023-07-26 23:36:12 +08:00
|
|
|
in mkMerge
|
|
|
|
[
|
|
|
|
# bluetooth
|
|
|
|
(mkIf hardware.bluetooth.enable { hardware.bluetooth.enable = true; })
|
|
|
|
# joystick
|
|
|
|
(mkIf hardware.joystick.enable { hardware = { xone.enable = true; xpadneo.enable = true; }; })
|
|
|
|
# printer
|
|
|
|
(
|
|
|
|
mkIf hardware.printer.enable
|
2023-07-18 18:19:00 +08:00
|
|
|
{
|
2023-07-26 23:36:12 +08:00
|
|
|
services =
|
2023-07-22 14:16:01 +08:00
|
|
|
{
|
2023-07-26 23:36:12 +08:00
|
|
|
printing = { enable = true; drivers = [ inputs.pkgs.cnijfilter2 ]; };
|
|
|
|
avahi = { enable = true; nssmdns = true; openFirewall = true; };
|
2023-07-22 14:16:01 +08:00
|
|
|
};
|
2023-07-26 23:36:12 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
# sound
|
|
|
|
(
|
|
|
|
mkIf hardware.sound.enable
|
|
|
|
{
|
|
|
|
hardware.pulseaudio.enable = false;
|
|
|
|
services.pipewire = { enable = true; alsa = { enable = true; support32Bit = true; }; pulse.enable = true; };
|
|
|
|
sound.enable = true;
|
|
|
|
security.rtkit.enable = true;
|
|
|
|
environment.etc."wireplumber/main.lua.d/50-alsa-config.lua".text =
|
|
|
|
let
|
|
|
|
content = builtins.readFile
|
2023-08-22 16:53:33 +08:00
|
|
|
(inputs.pkgs.wireplumber + "/share/wireplumber/main.lua.d/50-alsa-config.lua");
|
2023-07-26 23:36:12 +08:00
|
|
|
matched = builtins.match
|
|
|
|
".*\n([[:space:]]*)(--\\[\"session\\.suspend-timeout-seconds\"][^\n]*)[\n].*" content;
|
|
|
|
spaces = builtins.elemAt matched 0;
|
|
|
|
comment = builtins.elemAt matched 1;
|
|
|
|
config = ''["session.suspend-timeout-seconds"] = 0'';
|
|
|
|
in
|
|
|
|
builtins.replaceStrings [(spaces + comment)] [(spaces + config)] content;
|
|
|
|
}
|
|
|
|
)
|
2023-07-27 11:05:14 +08:00
|
|
|
# cpus
|
2023-07-26 23:36:12 +08:00
|
|
|
(
|
2023-07-27 11:05:14 +08:00
|
|
|
mkIf (hardware.cpus != [])
|
2023-07-26 23:36:12 +08:00
|
|
|
{
|
2023-07-27 11:05:14 +08:00
|
|
|
hardware.cpu = listToAttrs
|
|
|
|
(map (name: { inherit name; value = { updateMicrocode = true; }; }) hardware.cpus);
|
2023-07-26 23:36:12 +08:00
|
|
|
boot.initrd.availableKernelModules =
|
|
|
|
let
|
|
|
|
modules =
|
|
|
|
{
|
|
|
|
intel = [ "intel_cstate" "aesni_intel" ];
|
|
|
|
amd = [];
|
|
|
|
};
|
|
|
|
in
|
2023-07-27 11:05:14 +08:00
|
|
|
concatLists (map (cpu: modules.${cpu}) hardware.cpus);
|
2023-07-26 23:36:12 +08:00
|
|
|
}
|
|
|
|
)
|
2023-07-27 11:05:14 +08:00
|
|
|
# gpus
|
2023-07-26 23:36:12 +08:00
|
|
|
(
|
2023-07-27 11:05:14 +08:00
|
|
|
mkIf (hardware.gpus != [])
|
2023-07-26 23:36:12 +08:00
|
|
|
{
|
|
|
|
boot.initrd.availableKernelModules =
|
|
|
|
let
|
|
|
|
modules =
|
|
|
|
{
|
|
|
|
intel = [ "i915" ];
|
|
|
|
nvidia = [ "nvidia" "nvidia_drm" "nvidia_modeset" "nvidia_uvm" ];
|
|
|
|
};
|
|
|
|
in
|
2023-07-27 11:05:14 +08:00
|
|
|
concatLists (map (gpu: modules.${gpu}) hardware.gpus);
|
|
|
|
hardware =
|
2023-07-22 14:16:01 +08:00
|
|
|
{
|
2023-07-27 11:05:14 +08:00
|
|
|
opengl =
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
driSupport = true;
|
|
|
|
extraPackages =
|
|
|
|
with inputs.pkgs;
|
|
|
|
let
|
|
|
|
packages =
|
|
|
|
{
|
|
|
|
intel = [ intel-compute-runtime intel-media-driver intel-vaapi-driver libvdpau-va-gl ];
|
|
|
|
nvidia = [ vaapiVdpau ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
concatLists (map (gpu: packages.${gpu}) hardware.gpus);
|
|
|
|
driSupport32Bit = true;
|
|
|
|
};
|
|
|
|
nvidia.nvidiaSettings = builtins.elem "nvidia" hardware.gpus;
|
2023-07-22 14:16:01 +08:00
|
|
|
};
|
2023-07-26 23:36:12 +08:00
|
|
|
}
|
|
|
|
)
|
2023-07-27 11:05:14 +08:00
|
|
|
(mkIf (builtins.elem "intel" hardware.gpus) { services.xserver.deviceSection = ''Driver "modesetting"''; })
|
|
|
|
# prime
|
|
|
|
(
|
|
|
|
mkIf hardware.prime.enable
|
|
|
|
{
|
|
|
|
hardware.nvidia = mkMerge
|
|
|
|
[
|
|
|
|
(
|
|
|
|
mkIf (hardware.prime.mode == "offload")
|
|
|
|
{
|
|
|
|
prime.offload = { enable = true; enableOffloadCmd = true; };
|
|
|
|
powerManagement = { finegrained = true; enable = true; };
|
|
|
|
}
|
|
|
|
)
|
|
|
|
(
|
|
|
|
mkIf (hardware.prime.mode == "sync")
|
|
|
|
{
|
|
|
|
prime = { sync.enable = true; };
|
|
|
|
# prime.forceFullCompositionPipeline = true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
{
|
|
|
|
prime = listToAttrs
|
|
|
|
(map (gpu: { inherit (gpu) value; name = "${gpu.name}BusId"; }) (attrsToList hardware.prime.busId));
|
|
|
|
}
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
)
|
2023-08-21 01:38:14 +08:00
|
|
|
{ programs.gamemode.settings.gpu.gpu_device = "${toString hardware.gamemode.drmDevice}"; }
|
2023-07-26 23:36:12 +08:00
|
|
|
];
|
2023-07-15 22:45:35 +08:00
|
|
|
}
|