1
0
Fork 0
mirror of https://github.com/mdlayher/homelab.git synced 2024-12-14 11:47:32 +00:00

nixos: refactor out network interface creation

This commit is contained in:
Matt Layher 2020-01-24 12:10:03 -05:00
parent d72df0d9d5
commit ef20bb32f6

View file

@ -10,6 +10,25 @@ let
wan0 = vars.interfaces.wan0;
wg0 = vars.interfaces.wg0;
# Produces the configuration for a LAN interface.
mkInterface = (ifi: {
ipv4.addresses = [{
address = "${ifi.ipv4}";
prefixLength = 24;
}];
ipv6.addresses = [
{
address = "${ifi.ipv6.lla}";
prefixLength = 64;
}
{
address = "${ifi.ipv6.ula}";
prefixLength = 64;
}
];
preferTempAddress = false;
});
in {
# LAN interface.
networking = {
@ -37,76 +56,10 @@ in {
};
interfaces = {
# Trusted LANs.
${lan0.name} = {
ipv4.addresses = [{
address = "${lan0.ipv4}";
prefixLength = 24;
}];
ipv6.addresses = [
{
address = "${lan0.ipv6.lla}";
prefixLength = 64;
}
{
address = "${lan0.ipv6.ula}";
prefixLength = 64;
}
];
preferTempAddress = false;
};
${lab0.name} = {
ipv4.addresses = [{
address = "${lab0.ipv4}";
prefixLength = 24;
}];
ipv6.addresses = [
{
address = "${lab0.ipv6.lla}";
prefixLength = 64;
}
{
address = "${lab0.ipv6.ula}";
prefixLength = 64;
}
];
preferTempAddress = false;
};
# Untrusted LANs.
${guest0.name} = {
ipv4.addresses = [{
address = "${guest0.ipv4}";
prefixLength = 24;
}];
ipv6.addresses = [
{
address = "${guest0.ipv6.lla}";
prefixLength = 64;
}
{
address = "${guest0.ipv6.ula}";
prefixLength = 64;
}
];
preferTempAddress = false;
};
${iot0.name} = {
ipv4.addresses = [{
address = "${iot0.ipv4}";
prefixLength = 24;
}];
ipv6.addresses = [
{
address = "${iot0.ipv6.lla}";
prefixLength = 64;
}
{
address = "${iot0.ipv6.ula}";
prefixLength = 64;
}
];
preferTempAddress = false;
};
${lan0.name} = mkInterface lan0;
${lab0.name} = mkInterface lab0;
${guest0.name} = mkInterface guest0;
${iot0.name} = mkInterface iot0;
};
vlans = {