refactor: system -> systemConfig

This commit is contained in:
arcnmx 2024-06-23 10:06:36 -07:00
parent 512b1fc75b
commit 45705650bb
31 changed files with 127 additions and 131 deletions

View file

@ -15,11 +15,10 @@
inherit (lib.lists) findSingle;
inherit (lib.trivial) mapNullable;
cfg = config.access;
systemConfig = config;
systemAccess = access;
nixosModule = {
config,
system,
systemConfig,
access,
...
}: let
@ -28,16 +27,16 @@
if config.networking.enableIPv6
then "address6ForNetwork"
else "address4ForNetwork";
has'Int = system.network.networks.int.enable or false;
has'Local = system.network.networks.local.enable or false;
has'Tail' = system.network.networks.tail.enable or false;
has'Int = systemConfig.network.networks.int.enable or false;
has'Local = systemConfig.network.networks.local.enable or false;
has'Tail' = systemConfig.network.networks.tail.enable or false;
has'Tail = lib.warnIf (has'Tail' != config.services.tailscale.enable) "tailscale set incorrectly in system.access for ${config.networking.hostName}" has'Tail';
in {
options.networking.access = with lib.types; {
global.enable =
mkEnableOption "global access"
// {
default = system.access.global.enable;
default = systemConfig.access.global.enable;
};
moduleArgAttrs = mkOption {
type = lazyAttrsOf unspecified;
@ -61,7 +60,7 @@
in
{
lan =
if hostName == system.name
if hostName == systemConfig.name
then forSystem.access.${addressForAttr}.localhost
else if has'Int && forSystemHas "int"
then int
@ -124,7 +123,7 @@
in
{
lan =
if hostName == system.name
if hostName == systemConfig.name
then forSystem.access.hostnameForNetwork.localhost
else if has'Int && forSystem.access.hostnameForNetwork ? int
then forSystem.access.hostnameForNetwork.int
@ -207,7 +206,7 @@ in {
};
global.enable = mkEnableOption "globally routeable";
online = let
proxmoxNodeAccess = systems.${config.proxmox.node.name}.config.access;
proxmoxNodeAccess = systems.${config.proxmox.node.name}.access;
in {
enable =
mkEnableOption "a deployed machine"
@ -288,22 +287,22 @@ in {
_module.args.access = {
inherit (cfg) hostnameForNetwork address4ForNetwork address6ForNetwork;
systemFor = hostName: systems.${hostName}.config;
systemForOrNull = hostName: systems.${hostName}.config or null;
systemFor = hostName: systems.${hostName};
systemForOrNull = hostName: systems.${hostName} or null;
nixosFor = hostName: nixosConfigurations.${hostName}.config or (access.systemFor hostName).built.config;
nixosForOrNull = hostName: nixosConfigurations.${hostName}.config or (access.systemForOrNull hostName).built.config or null;
systemForService = service: let
hasService = system: system.config.exports.services.${service}.enable;
hasService = system: system.exports.services.${service}.enable;
notFound = throw "no system found serving ${service}";
multiple = throw "multiple systems found serving ${service}";
in
(findSingle hasService notFound multiple (attrValues systems)).config;
(findSingle hasService notFound multiple (attrValues systems));
systemForServiceId = serviceId: let
hasService = system: findSingle (service: service.id == serviceId && service.enable) null multiple (attrValues system.config.exports.services) != null;
hasService = system: findSingle (service: service.id == serviceId && service.enable) null multiple (attrValues system.exports.services) != null;
notFound = throw "no system found serving ${serviceId}";
multiple = throw "multiple systems found serving ${serviceId}";
in
(findSingle hasService notFound multiple (attrValues systems)).config;
(findSingle hasService notFound multiple (attrValues systems));
};
};
}

View file

@ -7,7 +7,7 @@
inherit (lib.modules) mkOptionDefault;
in {
config.exports.services.dnsmasq = {
system,
systemConfig,
config,
...
}: {
@ -28,10 +28,10 @@ in {
settings = {
dns = {
query-type = mkOptionDefault "A";
query-name = mkOptionDefault system.access.fqdn;
query-name = mkOptionDefault systemConfig.access.fqdn;
};
conditions = mkOptionDefault [
"[BODY] == ${system.network.networks.local.address4}"
"[BODY] == ${systemConfig.network.networks.local.address4}"
];
};
};

View file

@ -1,6 +1,6 @@
let
portModule = {
system,
systemConfig,
config,
gensokyo-zone,
lib,
@ -20,7 +20,7 @@ let
enable =
mkEnableOption "health check alerts"
// {
default = system.exports.status.alert.enable;
default = systemConfig.exports.status.alert.enable;
};
};
gatus = {
@ -127,7 +127,7 @@ let
};
};
serviceModule = {
system,
systemConfig,
config,
gensokyo-zone,
lib,
@ -185,8 +185,8 @@ let
labels = mapOptionDefaults {
gensokyo_exports_service = config.name;
gensokyo_exports_id = config.id;
gensokyo_system = system.name;
gensokyo_host = system.access.fqdn;
gensokyo_system = systemConfig.name;
gensokyo_host = systemConfig.access.fqdn;
};
};
status = {

View file

@ -9,7 +9,7 @@
in {
config.exports.services.nginx = {
config,
system,
systemConfig,
...
}: let
mkAssertion = f: nixosConfig: let
@ -29,7 +29,7 @@ in {
message = "proxied.port mismatch";
};
in {
displayName = mkAlmostOptionDefault "NGINX/${system.name}";
displayName = mkAlmostOptionDefault "NGINX/${systemConfig.name}";
nixos = {
serviceAttr = "nginx";
assertions = mkIf config.enable (map mkAssertion [

View file

@ -76,7 +76,7 @@
};
};
serviceModule = {
system,
systemConfig,
config,
name,
machine,
@ -101,7 +101,7 @@
type = attrsOf (submoduleWith {
modules = [portModule];
specialArgs = {
inherit gensokyo-zone machine system;
inherit gensokyo-zone machine systemConfig;
service = config;
};
});
@ -153,7 +153,7 @@
};
nixosModule = {
config,
system,
systemConfig,
...
}: let
mapAssertion = service: a: let
@ -163,7 +163,7 @@
// {
message = "system.exports.${service.name}: " + res.message or "assertion failed";
};
assertions = mapAttrsToList (_: service: map (mapAssertion service) service.nixos.assertions) system.exports.services;
assertions = mapAttrsToList (_: service: map (mapAssertion service) service.nixos.assertions) systemConfig.exports.services;
in {
config = {
assertions = mkMerge assertions;
@ -183,7 +183,6 @@ in {
specialArgs = {
inherit gensokyo-zone;
machine = name;
system = config;
systemConfig = config;
};
});

View file

@ -111,8 +111,7 @@ in {
specialArgs = {
inherit name inputs std Std meta;
inherit (inputs.self.lib) gensokyo-zone;
systemType = config.folder;
system = config;
systemConfig = config;
};
};
}

View file

@ -11,7 +11,7 @@
networkModule = {
config,
name,
system,
systemConfig,
...
}: let
knownNetworks = {
@ -68,8 +68,8 @@
);
postfix = mkIf (config.macAddress != null) (mkOptionDefault (eui64 config.macAddress));
};
domain = mkOptionDefault "${config.name}.${system.access.domain}";
fqdn = mkOptionDefault (mapNullable (domain: "${system.access.hostName}.${domain}") config.domain);
domain = mkOptionDefault "${config.name}.${systemConfig.access.domain}";
fqdn = mkOptionDefault (mapNullable (domain: "${systemConfig.access.hostName}.${domain}") config.domain);
address6 = mkIf config.slaac.enable (mkOptionDefault "${config.slaac.prefix}:${config.slaac.postfix}");
};
};
@ -79,7 +79,7 @@ in {
type = attrsOf (submoduleWith {
modules = [networkModule];
specialArgs = {
system = config;
systemConfig = config;
};
});
default = {};

View file

@ -18,7 +18,7 @@
networkInterfaceModule = {
config,
name,
system,
systemConfig,
...
}: {
options = with lib.types; {
@ -81,7 +81,7 @@
local = {
enable = mkOption {
type = bool;
default = system.proxmox.node.name == "reisen" && config.id == "net0" && config.bridge == "vmbr0";
default = systemConfig.proxmox.node.name == "reisen" && config.id == "net0" && config.bridge == "vmbr0";
};
address4 = mkOption {
type = nullOr str;
@ -125,12 +125,12 @@
);
};
name = mkMerge [
(mkIf (hasPrefix "net" config.id && system.proxmox.container.enable) (mkOptionDefault ("eth" + removePrefix "net" config.id)))
(mkIf (hasPrefix "net" config.id && systemConfig.proxmox.container.enable) (mkOptionDefault ("eth" + removePrefix "net" config.id)))
# VMs have names like `ens18` for net0...
];
slaac.postfix = mkOptionDefault (mapNullable eui64 config.macAddress);
gateway4 = mkMerge [
(mkIf (system.proxmox.node.name == "reisen" && config.bridge == "vmbr0" && config.address4 != null && config.address4 != "dhcp") (mkAlmostOptionDefault "10.1.1.1"))
(mkIf (systemConfig.proxmox.node.name == "reisen" && config.bridge == "vmbr0" && config.address4 != null && config.address4 != "dhcp") (mkAlmostOptionDefault "10.1.1.1"))
];
networkd.name = mkIf config.local.enable (
mkDefault "_00-local"
@ -176,14 +176,14 @@
};
};
confInternal = let
index = system.proxmox.vm.id - internalOffset;
index = systemConfig.proxmox.vm.id - internalOffset;
in {
name = mkIf system.proxmox.container.enable (mkAlmostOptionDefault "eth9");
name = mkIf systemConfig.proxmox.container.enable (mkAlmostOptionDefault "eth9");
bridge = mkAlmostOptionDefault "vmbr9";
address4 = mkAlmostOptionDefault "10.9.1.${toString index}/24";
address6 = mkAlmostOptionDefault "fd0c::${UInt.toHexLower index}/64";
macAddress = mkIf (system.proxmox.network.interfaces.net0.macAddress or null != null && hasPrefix "BC:24:11:" system.proxmox.network.interfaces.net0.macAddress) (mkAlmostOptionDefault (
replaceStrings ["BC:24:11:"] ["BC:24:19:"] system.proxmox.network.interfaces.net0.macAddress
macAddress = mkIf (systemConfig.proxmox.network.interfaces.net0.macAddress or null != null && hasPrefix "BC:24:11:" systemConfig.proxmox.network.interfaces.net0.macAddress) (mkAlmostOptionDefault (
replaceStrings ["BC:24:11:"] ["BC:24:19:"] systemConfig.proxmox.network.interfaces.net0.macAddress
));
networkd.name = mkDefault "_00-int";
networkd.networkSettings = {
@ -210,7 +210,7 @@ in {
type = attrsOf (submoduleWith {
modules = [networkInterfaceModule];
specialArgs = {
system = config;
systemConfig = config;
};
});
default = {};