From 1ac90d79857b9f125c7102607e43830cb37c9762 Mon Sep 17 00:00:00 2001 From: ooks-io Date: Mon, 10 Jun 2024 13:23:53 +1200 Subject: [PATCH] refactor(nixos:host): move module options -> nixos/options/host.nix --- nixos/modules/base/host/admin.nix | 35 +---- nixos/modules/base/host/hardware/cpu/amd.nix | 4 +- .../base/host/hardware/cpu/default.nix | 12 -- .../base/host/hardware/features/battery.nix | 29 +--- .../base/host/hardware/features/default.nix | 12 -- .../base/host/hardware/gpu/default.nix | 12 -- nixos/modules/base/host/hardware/monitors.nix | 62 -------- nixos/modules/base/host/name.nix | 11 +- nixos/modules/base/host/role.nix | 13 -- nixos/modules/base/host/type.nix | 13 -- nixos/options/host.nix | 133 ++++++++++++++++++ 11 files changed, 137 insertions(+), 199 deletions(-) delete mode 100644 nixos/modules/base/host/hardware/monitors.nix delete mode 100644 nixos/modules/base/host/role.nix delete mode 100644 nixos/modules/base/host/type.nix create mode 100644 nixos/options/host.nix diff --git a/nixos/modules/base/host/admin.nix b/nixos/modules/base/host/admin.nix index ff696f8..415deab 100644 --- a/nixos/modules/base/host/admin.nix +++ b/nixos/modules/base/host/admin.nix @@ -3,43 +3,10 @@ let cfg = config.ooknet.host.admin; ifTheyExist = groups: builtins.filter (group: builtins.hasAttr group config.users.groups) groups; - inherit (lib) mkIf types mkOption; + inherit (lib) mkIf; in { - options.ooknet.host.admin = { - name = mkOption { - type = types.str; - default = "ooks"; - description = "Name of the primary user"; - }; - shell = mkOption { - type = types.enum ["fish" "bash" "zsh"]; - default = "zsh"; - description = "The login shell of the primary user"; - }; - gitName = mkOption { - type = types.str; - default = "ooks-io"; - description = "Github username of admin"; - }; - gitEmail = mkOption { - type = types.str; - default = "ooks@protonmail.com"; - description = "Github email of admin"; - }; - sshKey = mkOption { - type = types.str; - default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBn3ff3HaZHIyH4K13k8Mwqu/o7jIABJ8rANK+r2PfJk"; - description = "The ssh key for the admin user"; - }; - homeManager = mkOption { - type = types.bool; - default = false; - description = "Enables home manager module for the admin user"; - }; - }; - config = { users.users.${cfg.name} = { isNormalUser = true; diff --git a/nixos/modules/base/host/hardware/cpu/amd.nix b/nixos/modules/base/host/hardware/cpu/amd.nix index 0929a25..e09301f 100644 --- a/nixos/modules/base/host/hardware/cpu/amd.nix +++ b/nixos/modules/base/host/hardware/cpu/amd.nix @@ -1,7 +1,7 @@ { lib, config, pkgs, ... }: let - inherit (lib) mkMerge mkEnableOption mkIf versionAtLeast versionOlder; + inherit (lib) mkMerge mkIf versionAtLeast versionOlder; inherit (builtins) elem; cpu = config.ooknet.host.hardware.cpu; cfg = cpu.amd; @@ -11,8 +11,6 @@ let in { - options.ooknet.host.hardware.cpu.amd.pstate.enable = mkEnableOption "Enable amd pstate module"; - config = mkIf (elem cpu.type ["amd"]) { environment.systemPackages = [pkgs.amdctl]; hardware.cpu.amd.updateMicrocode = true; diff --git a/nixos/modules/base/host/hardware/cpu/default.nix b/nixos/modules/base/host/hardware/cpu/default.nix index 1fd7074..b0acb52 100644 --- a/nixos/modules/base/host/hardware/cpu/default.nix +++ b/nixos/modules/base/host/hardware/cpu/default.nix @@ -1,18 +1,6 @@ -{ lib, ... }: - -let - inherit (lib) types mkOption; -in - { imports = [ ./amd.nix ./intel.nix ]; - - options.ooknet.host.hardware.cpu.type = mkOption { - type = with types; nullOr (enum ["intel" "amd"]); - default = null; - description = "Type of cpu system module to use"; - }; } diff --git a/nixos/modules/base/host/hardware/features/battery.nix b/nixos/modules/base/host/hardware/features/battery.nix index a0bdbe6..12829b1 100644 --- a/nixos/modules/base/host/hardware/features/battery.nix +++ b/nixos/modules/base/host/hardware/features/battery.nix @@ -4,39 +4,12 @@ let features = config.ooknet.host.hardware.features; cfg = config.ooknet.host.hardware.battery; - inherit (lib) mkIf mkDefault mkOption types; + inherit (lib) mkIf mkDefault; inherit (builtins) elem; MHz = x: x * 1000; in { - options.ooknet.host.hardware.battery = { - powersave = { - minFreq = mkOption { - type = types.int; - default = 800; - description = "Minimum frequency for powersave mode in MHz"; - }; - maxFreq = mkOption { - type = types.int; - default = 1100; - description = "Maximum frequency for powersave mode in MHz"; - }; - }; - performance = { - minFreq = mkOption { - type = types.int; - default = 1500; - description = "Minimum frequency for performance mode in MHz"; - }; - maxFreq = mkOption { - type = types.int; - default = 2600; - description = "Maximum frequency for performance mode in MHz"; - }; - }; - }; - config = mkIf (elem "battery" features) { boot = { kernelModules = ["acpi_call"]; diff --git a/nixos/modules/base/host/hardware/features/default.nix b/nixos/modules/base/host/hardware/features/default.nix index ffb1959..c88a6c6 100644 --- a/nixos/modules/base/host/hardware/features/default.nix +++ b/nixos/modules/base/host/hardware/features/default.nix @@ -1,9 +1,3 @@ -{ lib, config, ... }: - -let - inherit (lib) types mkOption; -in - { imports = [ ./bluetooth.nix @@ -13,10 +7,4 @@ in ./audio.nix ./video.nix ]; - - options.ooknet.host.hardware.features = mkOption { - type = with types; listOf (enum ["audio" "video" "bluetooth" "backlight" "battery" "ssd"]); - default = []; - description = "What extra hardware feature system modules to use"; - }; } diff --git a/nixos/modules/base/host/hardware/gpu/default.nix b/nixos/modules/base/host/hardware/gpu/default.nix index 71e16d3..83df5d0 100644 --- a/nixos/modules/base/host/hardware/gpu/default.nix +++ b/nixos/modules/base/host/hardware/gpu/default.nix @@ -1,19 +1,7 @@ -{ lib, ... }: - -let - inherit (lib) types mkOption; -in - { imports = [ ./amd.nix ./intel.nix ./nvidia.nix ]; - - options.ooknet.host.hardware.gpu.type = mkOption { - type = with types; nullOr (enum ["intel" "amd" "nvidia"]); - default = null; - description = "Type of gpu system module to use"; - }; } diff --git a/nixos/modules/base/host/hardware/monitors.nix b/nixos/modules/base/host/hardware/monitors.nix deleted file mode 100644 index 6baca77..0000000 --- a/nixos/modules/base/host/hardware/monitors.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ lib, config, ... }: - -let - inherit (lib) mkOption types; - cfg = config.ooknet.host.hardware.monitors; -in -{ - options.ooknet.host.hardware.monitors = mkOption { - type = types.listOf (types.submodule { - options = { - name = mkOption { - type = types.str; - example = "DP-1"; - }; - primary = mkOption { - type = types.bool; - default = false; - }; - width = mkOption { - type = types.int; - example = 1920; - }; - height = mkOption { - type = types.int; - example = 1080; - }; - refreshRate = mkOption { - type = types.int; - default = 60; - }; - x = mkOption { - type = types.int; - default = 0; - }; - y = mkOption { - type = types.int; - default = 0; - }; - transform = mkOption { - type = types.int; - default = 0; - }; - enabled = mkOption { - type = types.bool; - default = true; - }; - workspace = mkOption { - type = types.nullOr types.str; - default = null; - }; - }; - }); - default = [ ]; - }; - config = { - assertions = [{ - assertion = ((lib.length cfg) != 0) -> - ((lib.length (lib.filter (m: m.primary) cfg)) == 1); - message = "Exactly one monitor must be set to primary."; - }]; - }; -} diff --git a/nixos/modules/base/host/name.nix b/nixos/modules/base/host/name.nix index 036fdae..29a682c 100644 --- a/nixos/modules/base/host/name.nix +++ b/nixos/modules/base/host/name.nix @@ -1,19 +1,10 @@ -{ lib, config, ... }: +{ config, ... }: let - inherit (lib) types mkOption; cfg = config.ooknet.host; in { - options.ooknet.host = { - name = mkOption { - type = types.str; - default = "ooksgeneric"; - description = "Name of host machine"; - }; - }; - config = { networking.hostName = cfg.name; environment.sessionVariables.HN = cfg.name; diff --git a/nixos/modules/base/host/role.nix b/nixos/modules/base/host/role.nix deleted file mode 100644 index b612fd8..0000000 --- a/nixos/modules/base/host/role.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ lib, ... }: - -let - inherit (lib) types mkOption; -in - -{ - options.ooknet.host.function = mkOption { - type = with types; listOf (enum ["gaming" "workstation" "media-server"]); - default = []; - description = "Host's primary function/s"; - }; -} diff --git a/nixos/modules/base/host/type.nix b/nixos/modules/base/host/type.nix deleted file mode 100644 index 1abb275..0000000 --- a/nixos/modules/base/host/type.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ lib, ... }: - -let - inherit (lib) mkOption types; -in - -{ - options.ooknet.host.type = mkOption { - type = types.enum ["desktop" "laptop" "mixed" "server" "phone" "laptop" "micro" "vm"]; - default = ""; - description = "Declare what type of device the host is"; - }; -} diff --git a/nixos/options/host.nix b/nixos/options/host.nix new file mode 100644 index 0000000..01ff896 --- /dev/null +++ b/nixos/options/host.nix @@ -0,0 +1,133 @@ +{ lib, config, ... }: + +let + inherit (lib) mkOption mkEnableOption; + inherit (lib.types) bool enum listOf int submodule nullOr str; + hardware = config.ooknet.host.hardware; +in + +{ + options.ooknet.host = { + name = mkOption { + type = str; + default = "ooksgeneric"; + }; + + type = mkOption { + type = enum ["desktop" "laptop" "phone" "micro" "vm"]; + default = "desktop"; + }; + + role = mkOption { + type = enum ["workstation" "server"]; + default = "workstation"; + }; + + profiles = mkOption { + type = listOf (enum ["gaming" "creativity" "media-server"]); + default = []; + }; + + admin = { + name = mkOption { + type = str; + default = "ooks"; + }; + shell = mkOption { + type = enum ["bash" "zsh" "fish"]; + default = "bash"; + }; + gitName = mkOption { + type = str; + default = "ooks-io"; + }; + gitEmail = mkOption { + type = str; + default = "ooks@protonmail.com"; + }; + sshKey = mkOption { + type = str; + default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBn3ff3HaZHIyH4K13k8Mwqu/o7jIABJ8rANK+r2PfJk"; + }; + homeManager = mkEnableOption ""; + }; + + hardware = { + gpu = { + type = mkOption { + type = nullOr (enum ["intel" "amd" "nvidia"]); + default = null; + }; + }; + + cpu = { + type = mkOption { + type = nullOr (enum ["intel" "amd"]); + default = null; + }; + amd.pstate.enable = mkEnableOption ""; + }; + + features = mkOption { + type = listOf (enum ["audio" "video" "bluetooth" "backlight" "battery" "ssd"]); + default = [ "ssd" ]; + }; + + monitors = mkOption { + type = listOf (submodule { + options = { + name = mkOption { + type = str; + example = "DP-1"; + }; + primary = mkOption { + type = bool; + default = false; + }; + width = mkOption { + type = int; + example = 1920; + }; + height = mkOption { + type = int; + example = 1080; + }; + refreshRate = mkOption { + type = int; + default = 60; + }; + x = mkOption { + type = int; + default = 0; + }; + y = mkOption { + type = int; + default = 0; + }; + transform = mkOption { + type = int; + default = 0; + }; + enabled = mkOption { + type = bool; + default = true; + }; + workspace = mkOption { + type = nullOr str; + default = null; + }; + }; + }); + default = [ ]; + }; + }; + }; + + config = { + assertions = [{ + assertion = ((lib.length hardware.monitors) != 0) -> + ((lib.length (lib.filter (m: m.primary) hardware.monitors)) == 1); + message = "Exactly one monitor must be set to primary."; + }]; + }; +}