nix/lib/config: add hosts4/6 options
This commit is contained in:
parent
59c61fb42f
commit
b570447d01
|
@ -3,6 +3,13 @@
|
|||
let
|
||||
mainServer = "server1";
|
||||
pillar = self.lib.saltPillarFor mainServer;
|
||||
|
||||
renameAttr = from: to: attrset:
|
||||
builtins.foldl' (result: name:
|
||||
if name == from
|
||||
then result // { "${to}" = attrset.${name}; }
|
||||
else result // { "${name}" = attrset.${name}; }
|
||||
) {} (builtins.attrNames attrset);
|
||||
in
|
||||
{
|
||||
options.salt-pillar = lib.mkOption {};
|
||||
|
@ -10,11 +17,16 @@ in
|
|||
|
||||
config.site.net = lib.mkMerge ([
|
||||
(builtins.mapAttrs (_: vlan: { vlan = vlan; }) pillar.vlans)
|
||||
(builtins.mapAttrs (_: subnet: { subnet4 = subnet; }) pillar.subnets-inet)
|
||||
(builtins.mapAttrs (_: subnet4: { inherit subnet4; }) pillar.subnets-inet)
|
||||
(builtins.mapAttrs (_: hosts4: { inherit hosts4; }) pillar.hosts-inet)
|
||||
] ++ (
|
||||
map (ctx:
|
||||
builtins.mapAttrs (_: subnet: { subnets6.${ctx} = subnet; }) pillar.subnets-inet6.${ctx}
|
||||
) (builtins.attrNames pillar.subnets-inet6)
|
||||
) ++ (
|
||||
map (ctx:
|
||||
builtins.mapAttrs (_: subnet: { hosts6.${ctx} = subnet; }) pillar.hosts-inet6.${ctx}
|
||||
) (builtins.attrNames pillar.hosts-inet6)
|
||||
));
|
||||
|
||||
config.site.hosts = lib.mkMerge (
|
||||
|
@ -36,7 +48,10 @@ in
|
|||
(builtins.mapAttrs (_: container: {
|
||||
role = "container";
|
||||
location = mainServer;
|
||||
inherit (container) interfaces;
|
||||
interfaces =
|
||||
builtins.mapAttrs (_:
|
||||
renameAttr "gw" "gw6"
|
||||
) container.interfaces;
|
||||
}) pillar.containers)
|
||||
] ++
|
||||
|
||||
|
|
|
@ -18,6 +18,16 @@ let
|
|||
type = with types; attrsOf str;
|
||||
default = {};
|
||||
};
|
||||
hosts4 = mkOption {
|
||||
description = "Attribute set of hostnames to IPv4 addresses";
|
||||
type = with types; attrsOf str;
|
||||
default = {};
|
||||
};
|
||||
hosts6 = mkOption {
|
||||
description = "Attribute set of contexts to attribute sets of hostnames to IPv4 addresses";
|
||||
type = with types; attrsOf (attrsOf str);
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
};
|
||||
interfaceOpts = { name, ... }: {
|
||||
|
@ -29,7 +39,7 @@ let
|
|||
type = mkOption {
|
||||
type = types.enum [ "veth" "phys" ];
|
||||
};
|
||||
gw = mkOption {
|
||||
gw4 = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
};
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
enable = true;
|
||||
|
||||
networks =
|
||||
builtins.mapAttrs (ifName: { gw, gw6, ... }: {
|
||||
builtins.mapAttrs (ifName: { gw4, gw6, ... }: {
|
||||
matchConfig.Name = ifName;
|
||||
# addresses = [ {
|
||||
# addressConfig.Address = "127.0.0.1/8";
|
||||
# } ];
|
||||
# TODO: lookup hostname
|
||||
gateway = with lib;
|
||||
optional (gw != null) gw ++
|
||||
optional (gw4 != null) gw4 ++
|
||||
optional (gw6 != null) gw6;
|
||||
}) config.site.hosts.${hostName}.interfaces;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue