refactor(nixos:host): move module options -> nixos/options/host.nix

This commit is contained in:
ooks-io 2024-06-10 13:23:53 +12:00
parent 20466f95b2
commit 1ac90d7985
11 changed files with 137 additions and 199 deletions

View file

@ -3,43 +3,10 @@
let let
cfg = config.ooknet.host.admin; cfg = config.ooknet.host.admin;
ifTheyExist = groups: builtins.filter (group: builtins.hasAttr group config.users.groups) groups; ifTheyExist = groups: builtins.filter (group: builtins.hasAttr group config.users.groups) groups;
inherit (lib) mkIf types mkOption; inherit (lib) mkIf;
in 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 = { config = {
users.users.${cfg.name} = { users.users.${cfg.name} = {
isNormalUser = true; isNormalUser = true;

View file

@ -1,7 +1,7 @@
{ lib, config, pkgs, ... }: { lib, config, pkgs, ... }:
let let
inherit (lib) mkMerge mkEnableOption mkIf versionAtLeast versionOlder; inherit (lib) mkMerge mkIf versionAtLeast versionOlder;
inherit (builtins) elem; inherit (builtins) elem;
cpu = config.ooknet.host.hardware.cpu; cpu = config.ooknet.host.hardware.cpu;
cfg = cpu.amd; cfg = cpu.amd;
@ -11,8 +11,6 @@ let
in in
{ {
options.ooknet.host.hardware.cpu.amd.pstate.enable = mkEnableOption "Enable amd pstate module";
config = mkIf (elem cpu.type ["amd"]) { config = mkIf (elem cpu.type ["amd"]) {
environment.systemPackages = [pkgs.amdctl]; environment.systemPackages = [pkgs.amdctl];
hardware.cpu.amd.updateMicrocode = true; hardware.cpu.amd.updateMicrocode = true;

View file

@ -1,18 +1,6 @@
{ lib, ... }:
let
inherit (lib) types mkOption;
in
{ {
imports = [ imports = [
./amd.nix ./amd.nix
./intel.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";
};
} }

View file

@ -4,39 +4,12 @@
let let
features = config.ooknet.host.hardware.features; features = config.ooknet.host.hardware.features;
cfg = config.ooknet.host.hardware.battery; cfg = config.ooknet.host.hardware.battery;
inherit (lib) mkIf mkDefault mkOption types; inherit (lib) mkIf mkDefault;
inherit (builtins) elem; inherit (builtins) elem;
MHz = x: x * 1000; MHz = x: x * 1000;
in 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) { config = mkIf (elem "battery" features) {
boot = { boot = {
kernelModules = ["acpi_call"]; kernelModules = ["acpi_call"];

View file

@ -1,9 +1,3 @@
{ lib, config, ... }:
let
inherit (lib) types mkOption;
in
{ {
imports = [ imports = [
./bluetooth.nix ./bluetooth.nix
@ -13,10 +7,4 @@ in
./audio.nix ./audio.nix
./video.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";
};
} }

View file

@ -1,19 +1,7 @@
{ lib, ... }:
let
inherit (lib) types mkOption;
in
{ {
imports = [ imports = [
./amd.nix ./amd.nix
./intel.nix ./intel.nix
./nvidia.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";
};
} }

View file

@ -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.";
}];
};
}

View file

@ -1,19 +1,10 @@
{ lib, config, ... }: { config, ... }:
let let
inherit (lib) types mkOption;
cfg = config.ooknet.host; cfg = config.ooknet.host;
in in
{ {
options.ooknet.host = {
name = mkOption {
type = types.str;
default = "ooksgeneric";
description = "Name of host machine";
};
};
config = { config = {
networking.hostName = cfg.name; networking.hostName = cfg.name;
environment.sessionVariables.HN = cfg.name; environment.sessionVariables.HN = cfg.name;

View file

@ -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";
};
}

View file

@ -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";
};
}

133
nixos/options/host.nix Normal file
View file

@ -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.";
}];
};
}