Make 'default-host' a full networkHost, not a str
This commit is contained in:
parent
cd1c104bce
commit
a241c56c59
|
@ -92,13 +92,14 @@ in {
|
||||||
default = [ ];
|
default = [ ];
|
||||||
};
|
};
|
||||||
|
|
||||||
zone-definition = let
|
zone-definition =
|
||||||
zoneOpts = import ../types/zone-definition.nix { inherit lib; };
|
let zoneOpts = import ../types/zone-definition.nix { inherit lib; };
|
||||||
in mkOption {
|
in mkOption {
|
||||||
type = submodule zoneOpts;
|
type = submodule zoneOpts;
|
||||||
description = "Definition of network zone to be served by local server.";
|
description =
|
||||||
default = { };
|
"Definition of network zone to be served by local server.";
|
||||||
};
|
default = { };
|
||||||
|
};
|
||||||
|
|
||||||
extra-records = mkOption {
|
extra-records = mkOption {
|
||||||
type = listOf str;
|
type = listOf str;
|
||||||
|
@ -109,16 +110,17 @@ in {
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
fudo.system.hostfile-entries = let
|
fudo.system.hostfile-entries = let
|
||||||
other-hosts = filterAttrs
|
other-hosts =
|
||||||
(hostname: hostOpts: hostname != config.instance.hostname)
|
filterAttrs (hostname: hostOpts: hostname != config.instance.hostname)
|
||||||
cfg.zone-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 [
|
||||||
other-hosts;
|
"${hostname}.${cfg.domain}"
|
||||||
|
hostname
|
||||||
services.dhcpd4 = let
|
]) other-hosts;
|
||||||
zone = cfg.zone-definition;
|
|
||||||
|
services.dhcpd4 = let zone = cfg.zone-definition;
|
||||||
in {
|
in {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
|
@ -179,19 +181,22 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
filterRedundantIps = official-hosts: hosts: let
|
filterRedundantIps = official-hosts: hosts:
|
||||||
host-by-ip = groupBy (hostOpts: hostOpts.ipv4-address) hosts;
|
let host-by-ip = groupBy (hostOpts: hostOpts.ipv4-address) hosts;
|
||||||
in filter (hostOpts:
|
in filter (hostOpts:
|
||||||
if (length (getAttr hostOpts.ipv4-address host-by-ip) == 1) then
|
if (length (getAttr hostOpts.ipv4-address host-by-ip) == 1) then
|
||||||
true
|
true
|
||||||
else elem hostOpts.hostname official-hosts) hosts;
|
else
|
||||||
|
elem hostOpts.hostname official-hosts) hosts;
|
||||||
ipTo24Block = ip:
|
ipTo24Block = ip:
|
||||||
concatStringsSep "." (reverseList (take 3 (splitString "." ip)));
|
concatStringsSep "." (reverseList (take 3 (splitString "." ip)));
|
||||||
hostsByBlock = official-hosts:
|
hostsByBlock = official-hosts:
|
||||||
groupBy (host-data: ipTo24Block host-data.ipv4-address)
|
groupBy (host-data: ipTo24Block host-data.ipv4-address)
|
||||||
(filterRedundantIps official-hosts (attrValues zone.hosts));
|
(filterRedundantIps official-hosts (attrValues zone.hosts));
|
||||||
hostPtrRecord = host-data:
|
hostPtrRecord = host-data:
|
||||||
"${last (splitString "." host-data.ipv4-address)} IN PTR ${host-data.hostname}.${cfg.domain}.";
|
"${
|
||||||
|
last (splitString "." host-data.ipv4-address)
|
||||||
|
} IN PTR ${host-data.hostname}.${cfg.domain}.";
|
||||||
|
|
||||||
blockZones = official-hosts:
|
blockZones = official-hosts:
|
||||||
mapAttrsToList blockHostsToZone (hostsByBlock official-hosts);
|
mapAttrsToList blockHostsToZone (hostsByBlock official-hosts);
|
||||||
|
@ -213,16 +218,18 @@ in {
|
||||||
|
|
||||||
domain-name = config.instance.local-domain;
|
domain-name = config.instance.local-domain;
|
||||||
|
|
||||||
domain-hosts =
|
domain-hosts = attrNames
|
||||||
attrNames
|
(filterAttrs (_: hostOpts: hostOpts.domain == domain-name)
|
||||||
(filterAttrs (_: hostOpts:
|
config.fudo.hosts);
|
||||||
hostOpts.domain == domain-name)
|
|
||||||
config.fudo.hosts);
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
enable = true;
|
enable = true;
|
||||||
cacheNetworks = [ cfg.network "localhost" "localnets" ];
|
cacheNetworks = [ cfg.network "localhost" "localnets" ];
|
||||||
forwarders = [ "${cfg.recursive-resolver.host} port ${toString cfg.recursive-resolver.port}" ];
|
forwarders = [
|
||||||
|
"${cfg.recursive-resolver.host} port ${
|
||||||
|
toString cfg.recursive-resolver.port
|
||||||
|
}"
|
||||||
|
];
|
||||||
listenOn = cfg.dns-listen-ips;
|
listenOn = cfg.dns-listen-ips;
|
||||||
listenOnIpv6 = cfg.dns-listen-ipv6s;
|
listenOnIpv6 = cfg.dns-listen-ipv6s;
|
||||||
extraOptions = concatStringsSep "\n" [
|
extraOptions = concatStringsSep "\n" [
|
||||||
|
@ -235,43 +242,11 @@ in {
|
||||||
master = true;
|
master = true;
|
||||||
name = cfg.domain;
|
name = cfg.domain;
|
||||||
file = let
|
file = let
|
||||||
zone-data = pkgs.lib.dns.zoneToZonefile
|
zone-data =
|
||||||
config.instance.build-timestamp
|
pkgs.lib.dns.zoneToZonefile config.instance.build-timestamp
|
||||||
cfg.domain
|
cfg.domain zone;
|
||||||
zone;
|
|
||||||
in pkgs.writeText "zone-${cfg.domain}" zone-data;
|
in pkgs.writeText "zone-${cfg.domain}" zone-data;
|
||||||
# file = pkgs.writeText "${cfg.domain}-zone" ''
|
}] ++ (optionals cfg.enable-reverse-mappings (blockZones domain-hosts));
|
||||||
# @ IN SOA ns1.${cfg.domain}. hostmaster.${cfg.domain}. (
|
|
||||||
# ${toString config.instance.build-timestamp}
|
|
||||||
# 5m
|
|
||||||
# 2m
|
|
||||||
# 6w
|
|
||||||
# 5m)
|
|
||||||
|
|
||||||
# $TTL 1h
|
|
||||||
|
|
||||||
# @ IN NS ns1.${cfg.domain}.
|
|
||||||
|
|
||||||
# $ORIGIN ${cfg.domain}.
|
|
||||||
|
|
||||||
# $TTL 30m
|
|
||||||
|
|
||||||
# ${optionalString (zone.gssapi-realm != null)
|
|
||||||
# ''_kerberos IN TXT "${zone.gssapi-realm}"''}
|
|
||||||
|
|
||||||
# ${join-lines
|
|
||||||
# (imap1 (i: server-ip: "ns${toString i} IN A ${server-ip}")
|
|
||||||
# cfg.dns-servers)}
|
|
||||||
# ${join-lines (mapAttrsToList hostARecord zone.hosts)}
|
|
||||||
# ${join-lines (mapAttrsToList hostSshFpRecords zone.hosts)}
|
|
||||||
# ${join-lines (mapAttrsToList cnameRecord zone.aliases)}
|
|
||||||
# ${join-lines zone.verbatim-dns-records}
|
|
||||||
# ${pkgs.lib.dns.srvRecordsToBindZone zone.srv-records}
|
|
||||||
# ${join-lines cfg.extra-records}
|
|
||||||
# '';
|
|
||||||
}] ++ (optionals
|
|
||||||
cfg.enable-reverse-mappings
|
|
||||||
(blockZones domain-hosts));
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,8 @@ let
|
||||||
nameservers = mkOption {
|
nameservers = mkOption {
|
||||||
type = listOf str;
|
type = listOf str;
|
||||||
description = "List of zone nameservers.";
|
description = "List of zone nameservers.";
|
||||||
example = [
|
example = [ "ns1.fudo.org." "10.0.0.1" ];
|
||||||
"ns1.fudo.org."
|
default = [ ];
|
||||||
"10.0.0.1"
|
|
||||||
];
|
|
||||||
default = [];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
srv-records = mkOption {
|
srv-records = mkOption {
|
||||||
|
@ -91,12 +88,10 @@ let
|
||||||
port = 443;
|
port = 443;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
rspamd = [
|
rspamd = [{
|
||||||
{
|
host = "mail-host.my-domain.com";
|
||||||
host = "mail-host.my-domain.com";
|
port = 443;
|
||||||
port = 443;
|
}];
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
@ -127,7 +122,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
default-host = mkOption {
|
default-host = mkOption {
|
||||||
type = nullOr str;
|
type = nullOr (submodule networkHostOpts);
|
||||||
description =
|
description =
|
||||||
"IP of the host which will act as the default server for this domain, if any.";
|
"IP of the host which will act as the default server for this domain, if any.";
|
||||||
default = null;
|
default = null;
|
||||||
|
@ -165,7 +160,7 @@ let
|
||||||
subdomains = mkOption {
|
subdomains = mkOption {
|
||||||
type = attrsOf (submodule zoneOpts);
|
type = attrsOf (submodule zoneOpts);
|
||||||
description = "Subdomains of the current zone.";
|
description = "Subdomains of the current zone.";
|
||||||
default = {};
|
default = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue