refactor(dnsmasq): system host info

This commit is contained in:
arcnmx 2024-03-28 13:07:26 -07:00
parent 86ac38cf2c
commit 6c88d99ae6
30 changed files with 841 additions and 288 deletions

View file

@ -102,6 +102,9 @@
};
in {
options.access = with lib.types; {
fqdn = mkOption {
type = str;
};
hostName = mkOption {
type = str;
default = name;
@ -138,6 +141,7 @@ in {
hasLocal4 = hasLocal && local'interface.local.address4 or null != null;
hasLocal6 = hasLocal && local'interface.local.address6 or null != null;
in {
fqdn = mkOptionDefault "${cfg.hostName}.${cfg.domain}";
hostnameForNetwork = let
int = "${cfg.hostName}.int.${cfg.domain}";
local = "${cfg.hostName}.local.${cfg.domain}";

View file

@ -0,0 +1,71 @@
{config, lib, inputs, ...}: let
inherit (inputs.self.lib.lib) eui64;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkIf mkOptionDefault;
inherit (lib.trivial) mapNullable;
networkModule = { config, name, system, ... }: let
slaacPrefix = {
local = "fd0a:";
#int = "fd0c:";
};
in {
options = with lib.types; {
enable = mkEnableOption "network" // {
default = true;
};
slaac = {
enable = mkOption {
type = bool;
};
prefix = mkOption {
type = str;
};
postfix = mkOption {
type = str;
};
};
name = mkOption {
type = str;
default = name;
};
domain = mkOption {
type = nullOr str;
};
fqdn = mkOption {
type = nullOr str;
};
macAddress = mkOption {
type = nullOr str;
default = null;
};
address4 = mkOption {
type = nullOr str;
};
address6 = mkOption {
type = nullOr str;
};
};
config = {
slaac = {
enable = mkOptionDefault (slaacPrefix ? ${config.name});
prefix = mkIf (slaacPrefix ? ${config.name}) (mkOptionDefault slaacPrefix.${config.name});
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);
address6 = mkIf config.slaac.enable (mkOptionDefault "${config.slaac.prefix}:${config.slaac.postfix}");
};
};
in {
options.network = with lib.types; {
networks = mkOption {
type = attrsOf (submoduleWith {
modules = [ networkModule ];
specialArgs = {
system = config;
};
});
default = { };
};
};
}

View file

@ -1,10 +1,10 @@
{config, lib, inputs, ...}: let
inherit (inputs.self.lib.lib) unmerged eui64 toHexStringLower mkAlmostOptionDefault;
inherit (inputs.self.lib.lib) unmerged eui64 toHexStringLower mkAlmostOptionDefault mapAlmostOptionDefaults;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkIf mkMerge mkOptionDefault;
inherit (lib.attrsets) attrValues;
inherit (lib.lists) elem findSingle findFirst;
inherit (lib.strings) hasPrefix removePrefix replaceStrings;
inherit (lib.strings) hasPrefix removePrefix replaceStrings removeSuffix;
inherit (lib.trivial) mapNullable;
cfg = config.proxmox.network;
internalOffset = 32;
@ -105,6 +105,10 @@
];
networkd.networkSettings = {
name = mkAlmostOptionDefault config.name;
ipv6AcceptRAConfig = mkIf (config.address6 == "auto" && config.local.enable) {
UseDNS = mkOptionDefault false;
DHCPv6Client = mkOptionDefault false;
};
matchConfig = {
MACAddress = mkIf (config.macAddress != null) (mkOptionDefault config.macAddress);
Type = mkOptionDefault "ether";
@ -117,7 +121,7 @@
IPv6AcceptRA = true;
})
(mkIf config.mdns.enable {
MulticastDNS = true;
MulticastDNS = "resolve";
})
];
address = mkMerge [
@ -179,4 +183,19 @@ in {
};
local.interface = mkOptionDefault (findFirst (interface: interface.local.enable) null (attrValues cfg.interfaces));
};
config.network.networks = let
strip4 = mapNullable (removeSuffix "/24");
strip6 = mapNullable (removeSuffix "/64");
in {
int = mkIf (cfg.internal.interface != null) (mapAlmostOptionDefaults {
inherit (cfg.internal.interface) macAddress;
address4 = strip4 cfg.internal.interface.address4;
address6 = strip6 cfg.internal.interface.address6;
});
local = mkIf (cfg.local.interface != null) (mapAlmostOptionDefaults {
inherit (cfg.local.interface) macAddress;
address4 = strip4 cfg.local.interface.local.address4;
address6 = strip6 cfg.local.interface.local.address6;
});
};
}