infrastructure/meta/network.nix
Tom Hubrecht ade91c7bfd
All checks were successful
lint / check (push) Successful in 32s
build configuration / build_vault01 (push) Successful in 1m2s
build configuration / build_web02 (push) Successful in 1m2s
build configuration / build_storage01 (push) Successful in 1m7s
build configuration / build_compute01 (push) Successful in 1m10s
build configuration / build_web01 (push) Successful in 1m26s
ds-fr update / npins_update (push) Successful in 1m56s
feat(infra): Deploy geo02
2024-02-20 17:57:38 +01:00

189 lines
3.3 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};
filterIPv4 = ip: builtins.substring 0 7 ip != "192.168";
filterIPv6 = _: true;
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
// rec {
publicV4 = builtins.filter filterIPv4 _addresses.ipv4;
publicV6 = builtins.filter filterIPv6 _addresses.ipv6;
public = publicV4 ++ publicV6;
};
};
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";
};
geo01 = {
interfaces = {
eno1 = {
ipv4 = [
{
address = "129.199.210.194";
prefixLength = 24;
}
];
gateways = [ "129.199.210.254" ];
};
};
hostId = "b88fee0c";
dns = [
"129.199.96.11"
"129.199.72.99"
];
};
geo02 = {
interfaces = {
eno1 = {
ipv4 = [
{
address = "129.199.210.69";
prefixLength = 24;
}
];
gateways = [ "129.199.210.254" ];
};
};
hostId = "45d65237";
dns = [
"129.199.96.11"
"129.199.72.99"
];
};
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";
};
vault01 = {
interfaces = {
enp130s0f0 = {
ipv4 = [
{
address = "129.199.210.85";
prefixLength = 24;
}
];
gateways = [ "129.199.210.254" ];
};
};
hostId = "e83b600d";
};
web01 = {
interfaces = {
ens3 = {
ipv4 = [
{
address = "129.199.129.53";
prefixLength = 24;
}
];
gateways = [ "129.199.129.1" ];
};
};
hostId = "050df79e";
};
web02 = {
interfaces = {
ens3 = {
ipv4 = [
{
address = "129.199.129.235";
prefixLength = 24;
}
];
gateways = [ "129.199.129.1" ];
};
};
hostId = "b431ca10";
};
}