nix/lib/config: add upstream, forwardedPorts, fix fixed-hosts

This commit is contained in:
Astro 2021-03-31 02:46:21 +02:00
parent 775b91fb18
commit 881f985450
2 changed files with 60 additions and 18 deletions

View File

@ -32,11 +32,15 @@ in
(builtins.mapAttrs (_: hosts4: { inherit hosts4; }) pillar.hosts-inet) (builtins.mapAttrs (_: hosts4: { inherit hosts4; }) pillar.hosts-inet)
(builtins.mapAttrs (net: dhcpData: { (builtins.mapAttrs (net: dhcpData: {
dhcp = { dhcp = {
inherit (dhcpData) start end time max-time fixed-hosts; inherit (dhcpData) start end time max-time;
server = server =
if netHasDHCP net if netHasDHCP net
then "${net}-gw" then "${net}-gw"
else null; else null;
fixed-hosts =
if dhcpData ? fixed-hosts
then dhcpData.fixed-hosts
else {};
router = dhcpData.host-opts.routers; router = dhcpData.host-opts.routers;
domainName = dhcpData.string-opts.domain-name; domainName = dhcpData.string-opts.domain-name;
}; };
@ -68,24 +72,39 @@ in
role = "ap"; role = "ap";
}) pillar.cpe) }) pillar.cpe)
(builtins.mapAttrs (name: container: { (builtins.mapAttrs (name: container:
role = "container"; let
location = mainServer; ctPillar = self.lib.saltPillarFor name;
interfaces = in {
builtins.mapAttrs (_: interface: role = "container";
renameAttr "gw" "gw4" location = mainServer;
(forceVeth interface) interfaces =
) container.interfaces; builtins.mapAttrs (net: interface:
ospf = renameAttr "gw" "gw4"
let (forceVeth interface) // {
hostPillar = self.lib.saltPillarFor name; upstream =
ospfConf = hostPillar.ospf; if ctPillar ? upstream &&
in lib.optionalAttrs (hostPillar ? ospf && ospfConf ? stubnets-inet) { ctPillar.upstream.interface == net
stubNets4 = ospfConf.stubnets-inet; then {
} // lib.optionalAttrs (hostPillar ? ospf && ospfConf ? stubnets-inet6) { upBandwidth = ctPillar.upstream.up-bandwidth;
}
else null;
}
) container.interfaces;
ospf =
let
hostPillar = self.lib.saltPillarFor name;
ospfConf = hostPillar.ospf;
in lib.optionalAttrs (hostPillar ? ospf && ospfConf ? stubnets-inet) {
stubNets4 = ospfConf.stubnets-inet;
} // lib.optionalAttrs (hostPillar ? ospf && ospfConf ? stubnets-inet6) {
stubNets6 = ospfConf.stubnets-inet6; stubNets6 = ospfConf.stubnets-inet6;
}; };
}) pillar.containers) forwardedPorts =
if ctPillar ? port-forwarding
then ctPillar.port-forwarding
else [];
}) pillar.containers)
] ++ ] ++
(map (net: (map (net:

View File

@ -96,6 +96,11 @@ let
}; };
}; };
}; };
upstreamOpts = {
upBandwidth = mkOption {
type = with types; nullOr int;
};
};
interfaceOpts = { name, ... }: { interfaceOpts = { name, ... }: {
options = { options = {
hwaddr = mkOption { hwaddr = mkOption {
@ -113,6 +118,10 @@ let
type = with types; nullOr str; type = with types; nullOr str;
default = null; default = null;
}; };
upstream = mkOption {
type = with types; nullOr (submodule { options = upstreamOpts; });
default = null;
};
}; };
}; };
hostOpts = { name, ... }: { hostOpts = { name, ... }: {
@ -147,6 +156,20 @@ let
type = types.bool; type = types.bool;
default = config.site.hosts.${name}.interfaces ? core; default = config.site.hosts.${name}.interfaces ? core;
}; };
forwardedPorts = mkOption {
type = with types; listOf (submodule { options = {
proto = mkOption {
type = types.enum [ "tcp" "udp" ];
};
port = mkOption {
type = types.int;
};
to = mkOption {
type = types.str;
};
}; });
default = [];
};
ospf.stubNets4 = mkOption { ospf.stubNets4 = mkOption {
type = with types; listOf str; type = with types; listOf str;
default = []; default = [];