flake/modules/services/wgautomesh.nix

39 lines
875 B
Nix
Raw Normal View History

{
config,
pkgs,
lib,
cfg,
...
2024-11-12 03:46:56 +01:00
}: let
2024-11-13 05:15:14 +01:00
prefix = "meshconfig";
2024-11-12 03:46:56 +01:00
# helper vars to prettify
2024-11-13 05:15:14 +01:00
meshnetwork = config.${prefix}.network;
currentHost = meshnetwork.hosts.${networking.hostName};
2024-11-12 03:46:56 +01:00
wireguardPort = currentHost.wg.port;
in {
opt.useIPv6 = lib.mkOption {
type = lib.types.bool;
description = "Whether to use IPv6. Defaults to true";
default = true;
};
networking.wireguard.interfaces.wg0 = {
2024-11-13 05:15:14 +01:00
ips = ["${meshnetwork.IPv4.wg_subnet}"];
listenPort = cfg.wireguardPort;
privateKeyFile = "/var/lib/wireguard-keys/private";
mtu = 1420;
};
services.wgautomesh = {
enable = true;
services.wgautomesh.settings = {
interface = "wg0";
peers =
2024-11-12 01:52:07 +01:00
if cfg.useIPv6
2024-11-13 05:15:14 +01:00
then meshnetwork.IPv6.peerlist
else meshnetwork.IPv4.peerlist;
upnp_forward_external_port = wireguardPort;
};
};
}