nixos/modules/hardware/default.nix

57 lines
2.0 KiB
Nix
Raw Normal View History

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-22 00:45:24 +08:00
cpu = mkOption { type = types.listOf (types.enum [ "intel" "amd" ]); default = []; };
2023-07-18 18:19:00 +08:00
};
2023-07-19 11:49:09 +08:00
config = let inherit (inputs.lib) mkMerge mkIf; in mkMerge
[
2023-07-22 00:45:24 +08:00
# bluetooth
2023-07-19 11:49:09 +08:00
(mkIf inputs.config.nixos.hardware.bluetooth.enable { hardware.bluetooth.enable = true; })
2023-07-22 00:45:24 +08:00
# joystick
2023-07-19 11:49:09 +08:00
(mkIf inputs.config.nixos.hardware.joystick.enable { hardware = { xone.enable = true; xpadneo.enable = true; }; })
2023-07-22 00:45:24 +08:00
# printer
2023-07-19 11:49:09 +08:00
(
mkIf inputs.config.nixos.hardware.printer.enable
{
services =
2023-07-18 18:19:00 +08:00
{
printing = { enable = true; drivers = [ inputs.pkgs.cnijfilter2 ]; };
avahi = { enable = true; nssmdns = true; openFirewall = true; };
2023-07-19 11:49:09 +08:00
};
}
)
2023-07-22 00:45:24 +08:00
# sound
2023-07-19 11:49:09 +08:00
(
mkIf inputs.config.nixos.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
("/." + inputs.pkgs.wireplumber + "/share/wireplumber/main.lua.d/50-alsa-config.lua");
matched = builtins.match
".*\n([[:space:]]*)(--\\[\"session\\.suspend-timeout-seconds\"][^\n]*)[\n].*" content;
spaces = builtins.elemAt matched 0;
comment = builtins.elemAt matched 1;
2023-07-22 00:45:24 +08:00
config = ''["session.suspend-timeout-seconds"] = 0'';
2023-07-19 11:49:09 +08:00
in
builtins.replaceStrings [(spaces + comment)] [(spaces + config)] content;
}
)
2023-07-22 00:45:24 +08:00
# cpu
{
hardware.cpu = builtins.listToAttrs (builtins.map
(name: { inherit name; value = { updateMicrocode = true; }; })
2023-07-22 00:48:24 +08:00
inputs.config.nixos.hardware.cpu);
2023-07-22 00:45:24 +08:00
}
2023-07-19 11:49:09 +08:00
];
2023-07-15 22:45:35 +08:00
}