2024-11-04 22:41:38 -05:00
|
|
|
{ lib, config, ... }:
|
|
|
|
{
|
|
|
|
options.system.wireguard = {
|
|
|
|
client = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Enable WireGuard client";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
server = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Enable WireGuard server";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
networking = {
|
|
|
|
firewall.allowedUDPPorts = [ 51820 ];
|
|
|
|
|
|
|
|
nat = {
|
|
|
|
enable = config.system.wireguard.server.enable;
|
|
|
|
externalInterface = "${config.ips.netInt}";
|
2024-11-07 18:17:51 -05:00
|
|
|
internalInterfaces = [ "wgs" ];
|
2024-11-04 22:41:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
wireguard.interfaces = {
|
2024-11-07 18:17:51 -05:00
|
|
|
wgc = lib.mkIf config.system.wireguard.client.enable {
|
2024-11-04 22:41:38 -05:00
|
|
|
# Define IP of client in per device config
|
|
|
|
listenPort = 51820;
|
|
|
|
privateKey = config.secrets.wgClientPriv;
|
|
|
|
peers = [
|
|
|
|
{ # NixOS Server
|
|
|
|
publicKey = "qnOT/lXOJMaQgDUdXpyfGZB2IEyUouRje2m/bCe9ux8=";
|
2024-11-07 18:17:51 -05:00
|
|
|
allowedIPs = [ "10.100.0.0/24" ];
|
2024-11-04 22:41:38 -05:00
|
|
|
endpoint = "sv.${config.domains.jim1}:51820";
|
|
|
|
persistentKeepalive = 25;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-11-07 18:17:51 -05:00
|
|
|
wgs = lib.mkIf config.system.wireguard.server.enable {
|
|
|
|
ips = [ "10.100.0.1/24" ];
|
2024-11-04 22:41:38 -05:00
|
|
|
listenPort = 51820;
|
|
|
|
privateKey = config.secrets.wgServerPriv;
|
|
|
|
peers = [
|
|
|
|
{ # NixOS
|
|
|
|
publicKey = "OKUH/h6YSURI4vgeTZKQD15QsqaygdbTn1mAWzQp9S0=";
|
2024-11-07 18:17:51 -05:00
|
|
|
allowedIPs = [ "10.100.0.16/28" ];
|
2024-11-04 22:41:38 -05:00
|
|
|
}
|
|
|
|
{ # Pixel 9
|
|
|
|
publicKey = "dPCtjm67adMZCnyL1O2L+uUOk0RbjA9T/tht1r+qcE4=";
|
2024-11-07 18:17:51 -05:00
|
|
|
allowedIPs = [ "10.100.0.2/32" ];
|
2024-11-04 22:41:38 -05:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|