refactor(nixos): move hardware config options to machine nixos module

This commit is contained in:
Mohammad Rafiq 2025-06-16 19:59:45 +08:00
parent 91c2790b62
commit 8165d96d7c
No known key found for this signature in database
15 changed files with 70 additions and 84 deletions

View file

@ -6,7 +6,7 @@
... ...
}: }:
let let
inherit (lib) mkOption; inherit (lib) mkOption singleton;
inherit (lib.types) inherit (lib.types)
listOf listOf
str str
@ -14,6 +14,7 @@ let
submodule submodule
; ;
inherit (lib.pantheon) mkStrOption; inherit (lib.pantheon) mkStrOption;
inherit (lib.snowfall.fs) get-file;
rootDir = submodule { rootDir = submodule {
options = { options = {
directory = mkOption { type = str; }; directory = mkOption { type = str; };
@ -73,12 +74,13 @@ in
}; };
time.timeZone = "Asia/Singapore"; time.timeZone = "Asia/Singapore";
i18n.defaultLocale = "en_US.UTF-8"; i18n.defaultLocale = "en_US.UTF-8";
users.mutableUsers = false; users = {
users.groups.users = { mutableUsers = false;
groups.users = {
gid = 100; gid = 100;
members = [ "${config.mainUser.name}" ]; members = [ "${config.mainUser.name}" ];
}; };
users.users."${config.mainUser.name}" = { users."${config.mainUser.name}" = {
linger = true; linger = true;
uid = 1000; uid = 1000;
isNormalUser = true; isNormalUser = true;
@ -86,11 +88,12 @@ in
extraGroups = [ "wheel" ]; extraGroups = [ "wheel" ];
openssh.authorizedKeys.keys = [ config.mainUser.publicKey ]; openssh.authorizedKeys.keys = [ config.mainUser.publicKey ];
}; };
users.users.root.openssh.authorizedKeys.keys = lib.singleton config.mainUser.publicKey; users.root.openssh.authorizedKeys.keys = singleton config.mainUser.publicKey;
};
services.getty.autologinUser = config.mainUser.name; services.getty.autologinUser = config.mainUser.name;
security.sudo.wheelNeedsPassword = false; security.sudo.wheelNeedsPassword = false;
sops = { sops = {
defaultSopsFile = lib.snowfall.fs.get-file "secrets/secrets.yaml"; defaultSopsFile = get-file "secrets/secrets.yaml";
age.sshKeyPaths = [ "/persist/home/rafiq/.ssh/id_ed25519" ]; age.sshKeyPaths = [ "/persist/home/rafiq/.ssh/id_ed25519" ];
secrets = { secrets = {
"keys/openrouter" = { }; "keys/openrouter" = { };

View file

@ -1,3 +0,0 @@
{
imports = [ ./x86_64.nix ];
}

View file

@ -1,18 +0,0 @@
{ config, lib, ... }:
let
inherit (lib) singleton mkOption;
inherit (lib.types) enum;
cfg = config.hardware.platform;
in
{
options.hardware.platform = mkOption {
type = enum [
"amd"
"intel"
];
};
config = {
hardware.cpu.${cfg}.updateMicrocode = true;
boot.kernelModules = singleton "kvm-${cfg}";
};
}

View file

@ -1,13 +1,16 @@
{ {
config, config,
lib, lib,
modulesPath,
... ...
}: }:
let
inherit (lib.pantheon) mkStrOption;
cfg = config.machine.bootloader;
in
{ {
imports = [ options.machine.bootloader = {
(modulesPath + "/installer/scan/not-detected.nix") type = mkStrOption;
]; };
config = lib.mkMerge [ config = lib.mkMerge [
{ {
boot.initrd.availableKernelModules = [ boot.initrd.availableKernelModules = [
@ -20,7 +23,7 @@
]; ];
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
} }
(lib.mkIf (config.system.bootloader == "systemd-boot") { (lib.mkIf (config.machine.bootloader.type == "systemd-boot") {
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
}) })
]; ];

View file

@ -1,8 +1,12 @@
{ lib, ... }: { lib, modulesPath, ... }:
let let
inherit (lib) singleton; inherit (lib) singleton;
in in
{ {
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
];
config = { config = {
services.fwupd.enable = true; services.fwupd.enable = true;
persistDirs = singleton "/var/lib/bluetooth"; persistDirs = singleton "/var/lib/bluetooth";

View file

@ -2,7 +2,7 @@
let let
inherit (lib) mkIf mkEnableOption; inherit (lib) mkIf mkEnableOption;
inherit (lib.pantheon) mkStrOption; inherit (lib.pantheon) mkStrOption;
cfg = config.hardware.drives.btrfs; cfg = config.machine.drives.btrfs;
ephemeralRootCfg = { ephemeralRootCfg = {
boot.initrd.postDeviceCommands = lib.mkAfter '' boot.initrd.postDeviceCommands = lib.mkAfter ''
mkdir /btrfs_tmp mkdir /btrfs_tmp
@ -44,7 +44,7 @@ let
}; };
in in
{ {
options.hardware.drives.btrfs = { options.machine.drives.btrfs = {
enable = mkEnableOption ""; enable = mkEnableOption "";
drive = mkStrOption; drive = mkStrOption;
ephemeralRoot = mkEnableOption ""; ephemeralRoot = mkEnableOption "";

View file

@ -11,10 +11,10 @@ let
mkEnableOption mkEnableOption
singleton singleton
; ;
cfg = config.hardware.gpu; cfg = config.machine.gpu;
in in
{ {
options.hardware.gpu = { options.machine.gpu = {
nvidia.enable = mkEnableOption ""; nvidia.enable = mkEnableOption "";
}; };
config = mkMerge [ config = mkMerge [

View file

@ -0,0 +1,21 @@
{ config, lib, ... }:
let
inherit (lib) singleton mkOption;
inherit (lib.types) enum;
cfg = config.machine.platform;
in
{
options.machine.platform = {
type = mkOption {
type = enum [
"amd"
"intel"
];
};
};
config = {
hardware.cpu.${cfg.type}.updateMicrocode = true;
boot.kernelModules = singleton "kvm-${cfg.type}";
};
}

View file

@ -11,10 +11,10 @@ let
mkMerge mkMerge
singleton singleton
; ;
cfg = config.hardware.usb; cfg = config.machine.usb;
in in
{ {
options.hardware.usb = { options.machine.usb = {
automount = mkEnableOption ""; automount = mkEnableOption "";
enableQmk = mkEnableOption ""; enableQmk = mkEnableOption "";
}; };

View file

@ -15,7 +15,7 @@ mkWebApp {
}; };
extraConfig = { extraConfig = {
assertions = singleton { assertions = singleton {
assertion = config.hardware.gpu.nvidia.enable; assertion = config.machine.gpu.nvidia.enable;
message = "You must run the sd-webui-forge service only with an nvidia gpu."; message = "You must run the sd-webui-forge service only with an nvidia gpu.";
}; };
services.sd-webui-forge = { services.sd-webui-forge = {

View file

@ -1,15 +0,0 @@
{
config,
lib,
pkgs,
...
}:
{
imports = [
./boot.nix
];
options.system = {
bootloader = lib.pantheon.mkStrOption;
};
}

View file

@ -6,12 +6,9 @@
imports = lib.singleton ../common.nix; imports = lib.singleton ../common.nix;
hostname = "apollo"; hostname = "apollo";
system = { machine = {
bootloader = "systemd-boot"; platform.type = "intel";
}; bootloader.type = "systemd-boot";
hardware = {
platform = "intel";
drives.btrfs = { drives.btrfs = {
enable = true; enable = true;
drive = "/dev/disk/by-id/nvme-eui.002538d221b47b01"; drive = "/dev/disk/by-id/nvme-eui.002538d221b47b01";

View file

@ -11,7 +11,7 @@
window-manager.hyprland.enable = true; window-manager.hyprland.enable = true;
}; };
hardware.usb = { machine.usb = {
automount = true; automount = true;
enableQmk = true; enableQmk = true;
}; };

View file

@ -5,17 +5,14 @@
]; ];
hostname = "mellinoe"; hostname = "mellinoe";
system = { machine = {
bootloader = "systemd-boot"; platform.type = "intel";
}; bootloader.type = "systemd-boot";
hardware = {
drives.btrfs = { drives.btrfs = {
enable = true; enable = true;
drive = "/dev/disk/by-id/nvme-KBG40ZPZ128G_TOSHIBA_MEMORY_Z0U103PCNCDL"; drive = "/dev/disk/by-id/nvme-KBG40ZPZ128G_TOSHIBA_MEMORY_Z0U103PCNCDL";
ephemeralRoot = true; ephemeralRoot = true;
}; };
platform = "intel";
}; };
desktop.mainMonitor = { desktop.mainMonitor = {

View file

@ -5,18 +5,15 @@
]; ];
hostname = "nemesis"; hostname = "nemesis";
system = { machine = {
bootloader = "systemd-boot"; platform.type = "amd";
}; gpu.nvidia.enable = true;
bootloader.type = "systemd-boot";
hardware = {
drives.btrfs = { drives.btrfs = {
enable = true; enable = true;
drive = "/dev/disk/by-id/nvme-CT2000P3SSD8_2325E6E77434"; drive = "/dev/disk/by-id/nvme-CT2000P3SSD8_2325E6E77434";
ephemeralRoot = true; ephemeralRoot = true;
}; };
platform = "amd";
gpu.nvidia.enable = true;
}; };
desktop = { desktop = {