refactor: schema

This commit is contained in:
2026-05-06 21:57:58 +02:00
parent c01c13aa50
commit 4b6e05212c
27 changed files with 198 additions and 377 deletions
+16 -13
View File
@@ -37,26 +37,35 @@ let
};
mkHost =
machine:
name: machine:
{ pkgs, ... }:
let
account = config.repo.account;
accountHome = account.homeDirectory or "/home/${account.name}";
normalizedMachine = machine // {
inherit name;
displays = machine.displays or { };
hmStateVersion = machine.hmStateVersion or machine.stateVersion;
portable = machine.portable or false;
sshKeys = machine.sshKeys or { };
syncthingId = machine.syncthingId or null;
};
in
{
imports = [
nixosModules.${machine.name}
nixosModules.${name}
];
meta.machine = machine;
facts.machine = normalizedMachine;
networking.hostName = machine.name;
networking.hostName = name;
system.stateVersion = machine.stateVersion;
programs.zsh.enable = true;
users.users.${account.name} = {
isNormalUser = true;
home = account.homeDirectory;
home = accountHome;
extraGroups = [
"wheel"
"networkmanager"
@@ -67,19 +76,13 @@ let
home-manager.users.${account.name} = {
home = {
username = account.name;
homeDirectory = account.homeDirectory;
stateVersion = machine.hmStateVersion;
homeDirectory = accountHome;
stateVersion = normalizedMachine.hmStateVersion;
};
};
};
in
{
options.repo.helpers = lib.mkOption {
type = lib.types.attrsOf lib.types.raw;
internal = true;
readOnly = true;
};
config.repo.helpers = {
inherit
mkCaddyReverseProxy
+19 -207
View File
@@ -1,221 +1,33 @@
{ lib, ... }:
let
emailProviderType = lib.types.enum [
"mxrouting"
"office365"
];
emailType = lib.types.submodule (
{ ... }:
{
options = {
address = lib.mkOption {
type = lib.types.str;
};
primary = lib.mkOption {
type = lib.types.bool;
default = false;
};
type = lib.mkOption {
type = emailProviderType;
};
};
}
);
sshKeyType = lib.types.submodule (
{ name, ... }:
{
options = {
publicKey = lib.mkOption {
type = lib.types.str;
};
privateKeyPath = lib.mkOption {
type = lib.types.str;
default = "~/.ssh/id_${name}";
};
};
}
);
accountType = lib.types.submodule (
{ config, ... }:
{
options = {
name = lib.mkOption {
type = lib.types.str;
};
realName = lib.mkOption {
type = lib.types.str;
};
homeDirectory = lib.mkOption {
type = lib.types.str;
default = "/home/${config.name}";
};
nixosConfigurationPath = lib.mkOption {
type = lib.types.str;
default = "${config.homeDirectory}/.config/nixos";
};
emails = lib.mkOption {
type = lib.types.attrsOf emailType;
default = { };
};
primaryEmail = lib.mkOption {
type = lib.types.nullOr emailType;
description = "Derived primary email entry for this user.";
default =
let
emails = builtins.attrValues config.emails;
in
lib.findFirst (email: email.primary) null emails;
};
};
}
);
displayType = lib.types.submodule (
{ ... }:
{
options = {
primary = lib.mkOption {
type = lib.types.bool;
default = false;
};
x = lib.mkOption {
type = lib.types.int;
default = 0;
};
y = lib.mkOption {
type = lib.types.int;
default = 0;
};
scale = lib.mkOption {
type = lib.types.nullOr lib.types.float;
default = null;
};
width = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
};
height = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
};
refresh = lib.mkOption {
type = lib.types.nullOr lib.types.float;
default = null;
};
};
}
);
machineType = lib.types.submodule (
{ name, config, ... }:
{
options = {
name = lib.mkOption {
type = lib.types.str;
default = name;
};
stateVersion = lib.mkOption {
type = lib.types.str;
};
hmStateVersion = lib.mkOption {
type = lib.types.str;
default = config.stateVersion;
};
displays = lib.mkOption {
type = lib.types.attrsOf displayType;
default = { };
};
sshKeys = lib.mkOption {
type = lib.types.attrsOf sshKeyType;
default = { };
};
syncthingId = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
portable = lib.mkOption {
type = lib.types.bool;
default = false;
};
};
}
);
in
{
options.repo = {
account = lib.mkOption {
type = accountType;
};
options.repo = lib.mkOption {
type = lib.types.submodule {
freeformType = lib.types.attrsOf lib.types.anything;
machines = lib.mkOption {
type = lib.types.attrsOf machineType;
default = { };
};
services = lib.mkOption {
type = lib.types.raw;
default = { };
};
theme = lib.mkOption {
type = lib.types.raw;
default = { };
options.helpers = lib.mkOption {
type = lib.types.attrsOf lib.types.raw;
default = { };
internal = true;
};
};
default = { };
};
config.flake.modules.nixos.meta =
{ ... }:
config.flake.modules.nixos.facts =
{ lib, ... }:
{
options.meta.machine = lib.mkOption {
type = machineType;
options.facts.machine = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = { };
};
};
config.flake.modules.homeManager.meta =
{ ... }:
config.flake.modules.homeManager.facts =
{ lib, ... }:
{
options.meta.desktop.browserCommand = lib.mkOption {
type = lib.types.str;
};
options.meta.desktop.fileManagerCommand = lib.mkOption {
type = lib.types.str;
};
options.meta.desktop.terminalCommand = lib.mkOption {
type = lib.types.str;
};
options.meta.desktop.launcherCommand = lib.mkOption {
type = lib.types.str;
};
options.meta.pinentry.package = lib.mkOption {
type = lib.types.package;
options.facts.desktop = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = { };
};
};
}