refactor: further progress

This commit is contained in:
2026-04-25 00:19:20 +02:00
parent 55fbe82a42
commit 0500aab3cb
31 changed files with 680 additions and 398 deletions
+73 -32
View File
@@ -1,48 +1,80 @@
{ lib, config, ... }:
let
nixosModules = config.flake.modules.nixos;
hmModules = config.flake.modules.homeManager;
resolvePackagePath =
{
pkgs,
path,
}:
lib.attrByPath path null pkgs;
mkCaddyReverseProxy =
{
domain,
port,
extraHeaders ? [ ],
extraConfigText ? "",
}:
let
headerLines = map (header: " header_up ${header.name} ${header.value}") extraHeaders;
extraConfigLines = map (line: " ${line}") (
lib.filter (line: line != "") (lib.splitString "\n" extraConfigText)
);
bodyLines = headerLines ++ extraConfigLines;
body = lib.concatStringsSep "\n" bodyLines;
in
{
services.caddy.virtualHosts.${domain}.extraConfig =
if body == "" then
"reverse_proxy :${toString port}"
else
''
reverse_proxy :${toString port} {
${body}
}
'';
};
mkHost =
machine:
{ config, pkgs, ... }:
{ pkgs, ... }:
{
imports = [
nixosModules.host-base
nixosModules.meta
machine.module
];
meta.machine = machine;
networking.hostName = machine.name;
system.stateVersion = machine.stateVersion;
# TODO: Move this
programs.zsh.enable = true;
users.users = lib.mapAttrs (
_: account: {
inherit (account) name extraGroups;
isNormalUser = true;
home = account.homeDirectory;
# TODO: Move this
shell = pkgs.zsh;
}
);
users.users = lib.mapAttrs (_: user: {
isNormalUser = true;
home = user.account.homeDirectory;
extraGroups = [
"wheel"
"networkmanager"
];
shell = pkgs.zsh;
}) machine.users;
home-manager.users = lib.mapAttrs (
_: account: {
imports = [
hmModules.meta
account.baseModule
];
meta = {
inherit machine account;
};
home.homeDirectory = account.homeDirectory;
home.stateVersion = machine.hmStateVersion;
}
);
home-manager.users = lib.mapAttrs (name: user: {
imports = [ user.account.baseModule ];
meta = {
inherit machine user;
};
home = {
username = name;
homeDirectory = user.account.homeDirectory;
stateVersion = machine.hmStateVersion;
};
}) machine.users;
};
mkWorkstationHost =
@@ -54,11 +86,13 @@ let
nixosModules.workstation-base
];
home-manager.users = lib.mapAttrs (
_: account: {
imports = [ account.workstationModule ];
}
);
users.users = lib.mapAttrs (_: _: {
extraGroups = [ "networkmanager" ];
}) machine.users;
home-manager.users = lib.mapAttrs (_: user: {
imports = [ user.account.workstationModule ];
}) machine.users;
};
in
{
@@ -68,5 +102,12 @@ in
readOnly = true;
};
config.repo.helpers = { inherit mkHost mkWorkstationHost; };
config.repo.helpers = {
inherit
mkCaddyReverseProxy
mkHost
mkWorkstationHost
resolvePackagePath
;
};
}
+114 -20
View File
@@ -1,6 +1,10 @@
{ lib, ... }:
let
# Account types
sourceControlScopeType = lib.types.enum [
"personal"
"work"
];
emailProviderType = lib.types.enum [
"mxrouting"
"office365"
@@ -22,6 +26,21 @@ let
type = lib.mkOption {
type = emailProviderType;
};
scope = lib.mkOption {
type = lib.types.nullOr sourceControlScopeType;
default = null;
};
};
}
);
sourceControlAccountType = lib.types.submodule (
{ ... }:
{
options.projectScope = lib.mkOption {
type = sourceControlScopeType;
default = "personal";
};
}
);
@@ -33,7 +52,6 @@ let
name = lib.mkOption {
type = lib.types.str;
default = name;
readOnly = true;
};
realName = lib.mkOption {
@@ -55,11 +73,6 @@ let
default = { };
};
extraGroups = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
};
baseModule = lib.mkOption {
type = lib.types.deferredModule;
default = { };
@@ -70,9 +83,13 @@ let
default = { };
};
sourceControl = lib.mkOption {
type = sourceControlAccountType;
default = { };
};
primaryEmail = lib.mkOption {
type = lib.types.nullOr emailType;
readOnly = true;
description = "Derived primary email entry for this user.";
default =
let
@@ -84,7 +101,6 @@ let
}
);
# Machine types
displayType = lib.types.submodule (
{ ... }:
{
@@ -106,19 +122,77 @@ let
scale = lib.mkOption {
type = lib.types.nullOr lib.types.float;
default = 1.0;
default = null;
};
width = lib.mkOption {
type = lib.types.int;
type = lib.types.nullOr lib.types.int;
default = null;
};
height = lib.mkOption {
type = lib.types.int;
type = lib.types.nullOr lib.types.int;
default = null;
};
refresh = lib.mkOption {
type = lib.types.float;
type = lib.types.nullOr lib.types.float;
default = null;
};
};
}
);
sourceControlMachineKeyType = lib.types.submodule (
{ ... }:
{
options = {
publicKey = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
privateKeyPath = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
};
}
);
sourceControlMachineUserType = lib.types.submodule (
{ ... }:
{
options = {
personal = lib.mkOption {
type = lib.types.nullOr sourceControlMachineKeyType;
default = null;
};
work = lib.mkOption {
type = lib.types.nullOr sourceControlMachineKeyType;
default = null;
};
};
}
);
machineUserType = lib.types.submodule (
{ ... }:
{
options = {
account = lib.mkOption {
type = accountType;
};
sourceControl = lib.mkOption {
type = sourceControlMachineUserType;
default = { };
};
syncthingId = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
};
}
@@ -131,7 +205,6 @@ let
name = lib.mkOption {
type = lib.types.str;
default = name;
readOnly = true;
};
module = lib.mkOption {
@@ -157,8 +230,8 @@ let
default = { };
};
accounts = lib.mkOption {
type = lib.types.attrsOf accountType;
users = lib.mkOption {
type = lib.types.attrsOf machineUserType;
default = { };
};
};
@@ -171,14 +244,35 @@ in
type = lib.types.attrsOf accountType;
default = { };
};
machines = lib.mkOption {
type = lib.types.attrsOf machineType;
default = { };
};
contact = lib.mkOption {
type = lib.types.raw;
default = { };
};
desktop = lib.mkOption {
type = lib.types.raw;
default = { };
};
services = lib.mkOption {
type = lib.types.raw;
default = { };
};
theme = lib.mkOption {
type = lib.types.raw;
default = { };
};
};
config.flake.modules.nixos.meta =
{ config, ... }:
{ ... }:
{
options.meta.machine = lib.mkOption {
type = machineType;
@@ -186,15 +280,15 @@ in
};
config.flake.modules.homeManager.meta =
{ config, ... }:
{ ... }:
{
options.meta = {
machine = lib.mkOption {
type = machineType;
};
account = lib.mkOption {
type = accountType;
user = lib.mkOption {
type = machineUserType;
};
};
};