infrastructure/meta/network.nix

69 lines
1.6 KiB
Nix

let
mkDefaultInterface = _: attrs: { ipv4 = [ ]; ipv6 = [ ]; gateways = [ ]; } // attrs;
mkBase = config: config // { interfaces = builtins.mapAttrs mkDefaultInterface (config.interfaces or { }); };
getAddresses = version: interface: builtins.map (builtins.getAttr "address") interface.${version};
mkNet = _: value:
let base = mkBase value; in
base // {
addresses =
let
_addresses = builtins.foldl'
({ ipv4, ipv6 }: net: {
ipv4 = ipv4 ++ getAddresses "ipv4" net;
ipv6 = ipv6 ++ getAddresses "ipv6" net;
})
{ ipv4 = [ ]; ipv6 = [ ]; }
(builtins.attrValues base.interfaces);
in
_addresses // {
public = (builtins.filter
(ip: builtins.substring 0 7 ip != "192.168")
_addresses.ipv4) ++ _addresses.ipv6;
};
};
in
builtins.mapAttrs mkNet {
compute01 = {
interfaces = {
eno1 = {
ipv4 = [
{ address = "129.199.146.147"; prefixLength = 24; }
{ address = "192.168.1.147"; prefixLength = 24; }
];
gateways = [ "129.199.146.254" ];
};
};
hostId = "8df60941";
};
storage01 = {
interfaces = {
eno1 = {
ipv4 = [
{ address = "129.199.146.148"; prefixLength = 24; }
{ address = "192.168.1.148"; prefixLength = 24; }
];
gateways = [ "129.199.146.254" ];
};
};
hostId = "d4e7c369";
};
web01 = {
interfaces = {
ens3 = {
ipv4 = [{ address = "129.199.129.53"; prefixLength = 24; }];
gateways = [ "129.199.129.1" ];
};
};
};
}