forked from zentralwerk/network
nix/lib/config: add hosts4/6 options
This commit is contained in:
parent
59c61fb42f
commit
b570447d01
|
@ -3,6 +3,13 @@
|
||||||
let
|
let
|
||||||
mainServer = "server1";
|
mainServer = "server1";
|
||||||
pillar = self.lib.saltPillarFor mainServer;
|
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
|
in
|
||||||
{
|
{
|
||||||
options.salt-pillar = lib.mkOption {};
|
options.salt-pillar = lib.mkOption {};
|
||||||
|
@ -10,11 +17,16 @@ in
|
||||||
|
|
||||||
config.site.net = lib.mkMerge ([
|
config.site.net = lib.mkMerge ([
|
||||||
(builtins.mapAttrs (_: vlan: { vlan = vlan; }) pillar.vlans)
|
(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:
|
map (ctx:
|
||||||
builtins.mapAttrs (_: subnet: { subnets6.${ctx} = subnet; }) pillar.subnets-inet6.${ctx}
|
builtins.mapAttrs (_: subnet: { subnets6.${ctx} = subnet; }) pillar.subnets-inet6.${ctx}
|
||||||
) (builtins.attrNames pillar.subnets-inet6)
|
) (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 (
|
config.site.hosts = lib.mkMerge (
|
||||||
|
@ -36,7 +48,10 @@ in
|
||||||
(builtins.mapAttrs (_: container: {
|
(builtins.mapAttrs (_: container: {
|
||||||
role = "container";
|
role = "container";
|
||||||
location = mainServer;
|
location = mainServer;
|
||||||
inherit (container) interfaces;
|
interfaces =
|
||||||
|
builtins.mapAttrs (_:
|
||||||
|
renameAttr "gw" "gw6"
|
||||||
|
) container.interfaces;
|
||||||
}) pillar.containers)
|
}) pillar.containers)
|
||||||
] ++
|
] ++
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,16 @@ let
|
||||||
type = with types; attrsOf str;
|
type = with types; attrsOf str;
|
||||||
default = {};
|
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, ... }: {
|
interfaceOpts = { name, ... }: {
|
||||||
|
@ -29,7 +39,7 @@ let
|
||||||
type = mkOption {
|
type = mkOption {
|
||||||
type = types.enum [ "veth" "phys" ];
|
type = types.enum [ "veth" "phys" ];
|
||||||
};
|
};
|
||||||
gw = mkOption {
|
gw4 = mkOption {
|
||||||
type = with types; nullOr str;
|
type = with types; nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,14 +13,14 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
networks =
|
networks =
|
||||||
builtins.mapAttrs (ifName: { gw, gw6, ... }: {
|
builtins.mapAttrs (ifName: { gw4, gw6, ... }: {
|
||||||
matchConfig.Name = ifName;
|
matchConfig.Name = ifName;
|
||||||
# addresses = [ {
|
# addresses = [ {
|
||||||
# addressConfig.Address = "127.0.0.1/8";
|
# addressConfig.Address = "127.0.0.1/8";
|
||||||
# } ];
|
# } ];
|
||||||
# TODO: lookup hostname
|
# TODO: lookup hostname
|
||||||
gateway = with lib;
|
gateway = with lib;
|
||||||
optional (gw != null) gw ++
|
optional (gw4 != null) gw4 ++
|
||||||
optional (gw6 != null) gw6;
|
optional (gw6 != null) gw6;
|
||||||
}) config.site.hosts.${hostName}.interfaces;
|
}) config.site.hosts.${hostName}.interfaces;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user