nixos/home/routing-common: Add initial VRRP
This commit is contained in:
parent
63f36fabbb
commit
7404779c6d
@ -64,6 +64,7 @@ in
|
|||||||
{
|
{
|
||||||
imports = map (m: import m index) [
|
imports = map (m: import m index) [
|
||||||
./mstpd.nix
|
./mstpd.nix
|
||||||
|
./keepalived.nix
|
||||||
./dns.nix
|
./dns.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
41
nixos/boxes/home/routing-common/keepalived.nix
Normal file
41
nixos/boxes/home/routing-common/keepalived.nix
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
index: { lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
inherit (builtins) attrNames;
|
||||||
|
inherit (lib.my) net;
|
||||||
|
inherit (lib.my.c.home) prefixes vips;
|
||||||
|
|
||||||
|
vrrpIPs = family: map (vlan: {
|
||||||
|
addr = "${vips.${vlan}.${family}}/${toString (net.cidr.length prefixes.${vlan}.${family})}";
|
||||||
|
dev = "lan-${vlan}";
|
||||||
|
}) (attrNames vips);
|
||||||
|
mkVRRP = family: routerId: {
|
||||||
|
state = if index == 0 then "MASTER" else "BACKUP";
|
||||||
|
interface = "lan-core";
|
||||||
|
priority = 255 - index;
|
||||||
|
virtualRouterId = routerId;
|
||||||
|
virtualIps = vrrpIPs family;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
services = {
|
||||||
|
keepalived = {
|
||||||
|
enable = true;
|
||||||
|
extraGlobalDefs = ''
|
||||||
|
vrrp_version 3
|
||||||
|
nftables keepalived
|
||||||
|
'';
|
||||||
|
vrrpInstances = {
|
||||||
|
v4 = mkVRRP "v4" 51;
|
||||||
|
v6 = mkVRRP "v6" 52;
|
||||||
|
};
|
||||||
|
extraConfig = ''
|
||||||
|
vrrp_sync_group main {
|
||||||
|
group {
|
||||||
|
v4
|
||||||
|
v6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user