Rename 'network' to 'zone' to be less ambiguous

This commit is contained in:
niten 2021-11-22 11:22:57 -08:00
parent f3c4e626d0
commit 0ef91c51ea
6 changed files with 34 additions and 29 deletions

View File

@ -21,9 +21,9 @@ let
default = null; default = null;
}; };
network-definition = mkOption { zone-definition = mkOption {
type = submodule (import ../types/network-definition.nix); type = submodule (import ../types/zone-definition.nix);
description = "Definition of network to be served by local server."; description = "Definition of network zone to be served by local server.";
}; };
default-host = mkOption { default-host = mkOption {
@ -139,7 +139,7 @@ in {
interfaces = cfg.listen-ips; interfaces = cfg.listen-ips;
stateDir = cfg.state-directory; stateDir = cfg.state-directory;
zones = mapAttrs' (dom: dom-cfg: let zones = mapAttrs' (dom: dom-cfg: let
net-cfg = dom-cfg.network-definition; net-cfg = dom-cfg.zone-definition;
in nameValuePair "${dom}." { in nameValuePair "${dom}." {
dnssec = dom-cfg.dnssec; dnssec = dom-cfg.dnssec;

View File

@ -77,6 +77,12 @@ let
description = "Hostname of the primary mail server for this domain."; description = "Hostname of the primary mail server for this domain.";
default = null; default = null;
}; };
zone = mkOption {
type = nullOr str;
description = "Name of the DNS zone associated with domain.";
default = null;
};
}; };
}; };

View File

@ -66,13 +66,11 @@ in {
(hostname: hostOpts: hostOpts.initrd-network != null) (hostname: hostOpts: hostOpts.initrd-network != null)
config.instance.local-hosts; config.instance.local-hosts;
in { in {
network-definition.hosts = mapAttrs' zone-definition.hosts = mapAttrs'
(hostname: hostOpts: nameValuePair "${hostname}-recovery" (hostname: hostOpts: nameValuePair "${hostname}-recovery" {
{ ipv4-address = hostOpts.initrd-network.ip;
ipv4-address = hostOpts.initrd-network.ip; description = "${hostname} initrd host";
description = "${hostname} initrd host"; }) initrd-network-hosts;
})
initrd-network-hosts;
extra-records = let extra-records = let
recs = (mapAttrsToList recs = (mapAttrsToList

View File

@ -74,11 +74,11 @@ in {
default = [ ]; default = [ ];
}; };
network-definition = let zone-definition = let
networkOpts = import ../types/network-definition.nix { inherit lib; }; zoneOpts = import ../types/zone-definition.nix { inherit lib; };
in mkOption { in mkOption {
type = submodule networkOpts; type = submodule zoneOpts;
description = "Definition of network to be served by local server."; description = "Definition of network zone to be served by local server.";
default = { }; default = { };
}; };
@ -94,12 +94,13 @@ in {
fudo.system.hostfile-entries = let fudo.system.hostfile-entries = let
other-hosts = filterAttrs other-hosts = filterAttrs
(hostname: hostOpts: hostname != config.instance.hostname) (hostname: hostOpts: hostname != config.instance.hostname)
cfg.network-definition.hosts; cfg.zone-definition.hosts;
in mapAttrs' (hostname: hostOpts: in mapAttrs' (hostname: hostOpts:
nameValuePair hostOpts.ipv4-address ["${hostname}.${cfg.domain}" hostname]) nameValuePair hostOpts.ipv4-address ["${hostname}.${cfg.domain}" hostname])
other-hosts; other-hosts;
services.dhcpd4 = let network = cfg.network-definition; services.dhcpd4 = let
zone = cfg.zone-definition;
in { in {
enable = true; enable = true;
@ -109,7 +110,7 @@ in {
ipAddress = hostOpts.ipv4-address; ipAddress = hostOpts.ipv4-address;
}) (filterAttrs (host: hostOpts: }) (filterAttrs (host: hostOpts:
hostOpts.mac-address != null && hostOpts.ipv4-address != null) hostOpts.mac-address != null && hostOpts.ipv4-address != null)
network.hosts); zone.hosts);
interfaces = cfg.dhcp-interfaces; interfaces = cfg.dhcp-interfaces;
@ -163,7 +164,7 @@ in {
ipToBlock = ip: ipToBlock = ip:
concatStringsSep "." (reverseList (take 3 (splitString "." ip))); concatStringsSep "." (reverseList (take 3 (splitString "." ip)));
compactHosts = compactHosts =
mapAttrsToList (host: data: data // { host = host; }) network.hosts; mapAttrsToList (host: data: data // { host = host; }) zone.hosts;
hostsByBlock = hostsByBlock =
groupBy (host-data: ipToBlock host-data.ipv4-address) compactHosts; groupBy (host-data: ipToBlock host-data.ipv4-address) compactHosts;
hostPtrRecord = host-data: hostPtrRecord = host-data:
@ -184,7 +185,7 @@ in {
(map (sshfp: "${host} IN SSHFP ${sshfp}") ssh-fingerprints); (map (sshfp: "${host} IN SSHFP ${sshfp}") ssh-fingerprints);
cnameRecord = alias: host: "${alias} IN CNAME ${host}"; cnameRecord = alias: host: "${alias} IN CNAME ${host}";
network = cfg.network-definition; zone = cfg.zone-definition;
known-hosts = config.fudo.hosts; known-hosts = config.fudo.hosts;
@ -219,17 +220,17 @@ in {
$TTL 30m $TTL 30m
${optionalString (network.gssapi-realm != null) ${optionalString (zone.gssapi-realm != null)
''_kerberos IN TXT "${network.gssapi-realm}"''} ''_kerberos IN TXT "${zone.gssapi-realm}"''}
${join-lines ${join-lines
(imap1 (i: server-ip: "ns${toString i} IN A ${server-ip}") (imap1 (i: server-ip: "ns${toString i} IN A ${server-ip}")
cfg.dns-servers)} cfg.dns-servers)}
${join-lines (mapAttrsToList hostARecord network.hosts)} ${join-lines (mapAttrsToList hostARecord zone.hosts)}
${join-lines (mapAttrsToList hostSshFpRecords network.hosts)} ${join-lines (mapAttrsToList hostSshFpRecords zone.hosts)}
${join-lines (mapAttrsToList cnameRecord network.aliases)} ${join-lines (mapAttrsToList cnameRecord zone.aliases)}
${join-lines network.verbatim-dns-records} ${join-lines zone.verbatim-dns-records}
${pkgs.lib.fudo.dns.srvRecordsToBindZone network.srv-records} ${pkgs.lib.fudo.dns.srvRecordsToBindZone zone.srv-records}
${join-lines cfg.extra-records} ${join-lines cfg.extra-records}
''; '';
}] ++ blockZones; }] ++ blockZones;

View File

@ -3,7 +3,7 @@
with lib; with lib;
let let
zoneOpts = zoneOpts =
import ../types/network-definition.nix { inherit lib; }; import ../types/zone-definition.nix { inherit lib; };
in { in {
options.fudo.zones = with types; mkOption { options.fudo.zones = with types; mkOption {
type = attrsOf (submodule zoneOpts); type = attrsOf (submodule zoneOpts);

View File

@ -101,7 +101,7 @@ in {
gssapi-realm = mkOption { gssapi-realm = mkOption {
type = nullOr str; type = nullOr str;
description = "Kerberos GSSAPI realm of the network."; description = "Kerberos GSSAPI realm of the zone.";
default = null; default = null;
}; };
}; };