diff --git a/devices/pc/default.nix b/devices/pc/default.nix index 844a47e4..2ec8e027 100644 --- a/devices/pc/default.nix +++ b/devices/pc/default.nix @@ -62,11 +62,6 @@ inputs: { cpus = [ "amd" ]; gpu = { type = "amd+nvidia"; prime.busId = { amd = "8:0:0"; nvidia = "1:0:0"; }; dynamicBoost = true; }; - bluetooth.enable = true; - joystick.enable = true; - printer.enable = true; - sound.enable = true; - legion.enable = true; }; packages.packageSet = "workstation"; virtualization = diff --git a/devices/surface/default.nix b/devices/surface/default.nix index 2cca452c..24e0b815 100644 --- a/devices/surface/default.nix +++ b/devices/surface/default.nix @@ -34,15 +34,7 @@ inputs: kernel.patches = [ "cjktty" "lantian" "surface" ]; networking.hostname = "surface"; }; - hardware = - { - cpus = [ "intel" ]; - gpu.type = "intel"; - bluetooth.enable = true; - joystick.enable = true; - printer.enable = true; - sound.enable = true; - }; + hardware = { cpus = [ "intel" ]; gpu.type = "intel"; }; packages.packageSet = "desktop-fat"; virtualization = { docker.enable = true; waydroid.enable = true; }; services = diff --git a/devices/xmupc1/default.nix b/devices/xmupc1/default.nix index bb743356..345a8ccb 100644 --- a/devices/xmupc1/default.nix +++ b/devices/xmupc1/default.nix @@ -52,15 +52,7 @@ inputs: networking.hostname = "xmupc1"; nix.remote.slave.enable = true; }; - hardware = - { - cpus = [ "amd" ]; - gpu.type = "nvidia"; - bluetooth.enable = true; - joystick.enable = true; - printer.enable = true; - sound.enable = true; - }; + hardware = { cpus = [ "amd" ]; gpu.type = "nvidia"; }; packages.packageSet = "workstation"; virtualization = { waydroid.enable = true; docker.enable = true; kvmHost = { enable = true; gui = true; }; }; services = diff --git a/devices/xmupc2/default.nix b/devices/xmupc2/default.nix index baf705e3..e7d6573a 100644 --- a/devices/xmupc2/default.nix +++ b/devices/xmupc2/default.nix @@ -46,15 +46,7 @@ inputs: networking.hostname = "xmupc2"; nix.remote.slave.enable = true; }; - hardware = - { - cpus = [ "intel" ]; - gpu.type = "nvidia"; - bluetooth.enable = true; - joystick.enable = true; - printer.enable = true; - sound.enable = true; - }; + hardware = { cpus = [ "intel" ]; gpu.type = "nvidia"; }; packages.packageSet = "workstation"; virtualization = { waydroid.enable = true; docker.enable = true; kvmHost = { enable = true; gui = true; }; }; services = diff --git a/modules/hardware/default.nix b/modules/hardware/default.nix index c7bd7ef0..6a77fbdc 100644 --- a/modules/hardware/default.nix +++ b/modules/hardware/default.nix @@ -3,75 +3,69 @@ inputs: imports = inputs.localLib.findModules ./.; options.nixos.hardware = let inherit (inputs.lib) mkOption types; in { - bluetooth.enable = mkOption { type = types.bool; default = false; }; - joystick.enable = mkOption { type = types.bool; default = false; }; - printer.enable = mkOption { type = types.bool; default = false; }; - sound.enable = mkOption { type = types.bool; default = false; }; + bluetooth = mkOption { type = types.nullOr (types.submodule {}); default = {}; }; + joystick = mkOption { type = types.nullOr (types.submodule {}); default = {}; }; + printer = mkOption { type = types.nullOr (types.submodule {}); default = {}; }; + sound = mkOption { type = types.nullOr (types.submodule {}); default = {}; }; cpus = mkOption { type = types.listOf (types.enum [ "intel" "amd" ]); default = []; }; }; - config = - let - inherit (inputs.lib) mkMerge mkIf; - inherit (inputs.config.nixos) hardware; - inherit (builtins) listToAttrs map concatLists; - inherit (inputs.localLib) attrsToList; - 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 + config = let inherit (inputs.config.nixos) hardware; in inputs.lib.mkMerge + [ + # bluetooth + (inputs.lib.mkIf (hardware.bluetooth != null) { hardware.bluetooth.enable = true; }) + # joystick + (inputs.lib.mkIf (hardware.joystick != null) { hardware = { xone.enable = true; xpadneo.enable = true; }; }) + # printer + ( + inputs.lib.mkIf (hardware.printer != null) + { + services = { - services = - { - printing = { enable = true; drivers = [ inputs.pkgs.cnijfilter2 ]; }; - avahi = { enable = true; nssmdns = true; openFirewall = true; }; - }; - } - ) - # 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 - (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; - config = ''["session.suspend-timeout-seconds"] = 0''; - in - builtins.replaceStrings [(spaces + comment)] [(spaces + config)] content; - } - ) - # cpus - ( - mkIf (hardware.cpus != []) - { - hardware.cpu = listToAttrs - (map (name: { inherit name; value = { updateMicrocode = true; }; }) hardware.cpus); - boot.initrd.availableKernelModules = - let - modules = - { - intel = - [ - "intel_cstate" "aesni_intel" "intel_cstate" "intel_uncore" "intel_uncore_frequency" "intel_powerclamp" - ]; - amd = []; - }; - in - concatLists (map (cpu: modules.${cpu}) hardware.cpus); - } - ) - ]; + printing = { enable = true; drivers = [ inputs.pkgs.cnijfilter2 ]; }; + avahi = { enable = true; nssmdns = true; openFirewall = true; }; + }; + } + ) + # sound + ( + inputs.lib.mkIf (hardware.sound != null) + { + 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; + config = ''["session.suspend-timeout-seconds"] = 0''; + in + builtins.replaceStrings [(spaces + comment)] [(spaces + config)] content; + } + ) + # cpus + ( + inputs.lib.mkIf (hardware.cpus != []) + { + hardware.cpu = builtins.listToAttrs + (map (name: { inherit name; value = { updateMicrocode = true; }; }) hardware.cpus); + boot.initrd.availableKernelModules = + let + modules = + { + intel = + [ + "intel_cstate" "aesni_intel" "intel_cstate" "intel_uncore" "intel_uncore_frequency" "intel_powerclamp" + ]; + amd = []; + }; + in + builtins.concatLists (map (cpu: modules.${cpu}) hardware.cpus); + } + ) + ]; }