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 (net: dhcpData: {
dhcp = {
inherit (dhcpData) start end time max-time fixed-hosts;
inherit (dhcpData) start end time max-time;
server =
if netHasDHCP net
then "${net}-gw"
else null;
fixed-hosts =
if dhcpData ? fixed-hosts
then dhcpData.fixed-hosts
else {};
router = dhcpData.host-opts.routers;
domainName = dhcpData.string-opts.domain-name;
};
@ -68,24 +72,39 @@ in
role = "ap";
}) pillar.cpe)
(builtins.mapAttrs (name: container: {
role = "container";
location = mainServer;
interfaces =
builtins.mapAttrs (_: interface:
renameAttr "gw" "gw4"
(forceVeth interface)
) 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) {
(builtins.mapAttrs (name: container:
let
ctPillar = self.lib.saltPillarFor name;
in {
role = "container";
location = mainServer;
interfaces =
builtins.mapAttrs (net: interface:
renameAttr "gw" "gw4"
(forceVeth interface) // {
upstream =
if ctPillar ? upstream &&
ctPillar.upstream.interface == net
then {
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;
};
}) pillar.containers)
};
forwardedPorts =
if ctPillar ? port-forwarding
then ctPillar.port-forwarding
else [];
}) pillar.containers)
] ++
(map (net:

View File

@ -96,6 +96,11 @@ let
};
};
};
upstreamOpts = {
upBandwidth = mkOption {
type = with types; nullOr int;
};
};
interfaceOpts = { name, ... }: {
options = {
hwaddr = mkOption {
@ -113,6 +118,10 @@ let
type = with types; nullOr str;
default = null;
};
upstream = mkOption {
type = with types; nullOr (submodule { options = upstreamOpts; });
default = null;
};
};
};
hostOpts = { name, ... }: {
@ -147,6 +156,20 @@ let
type = types.bool;
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 {
type = with types; listOf str;
default = [];