dotfiles/systems/ceres/config/wireguard.nix

68 lines
1.4 KiB
Nix
Raw Normal View History

2025-07-01 16:08:54 -05:00
{ config, flake, ... }:
2025-07-01 04:11:32 -05:00
let
2025-07-01 13:54:00 -05:00
inherit (flake.config.services.instances) wireGuard;
2025-07-01 04:32:00 -05:00
inherit (flake.config.machines.devices) mars ceres;
2025-07-01 04:11:32 -05:00
service = wireGuard;
in
{
networking = {
firewall = {
2025-07-01 15:39:57 -05:00
allowedTCPPorts = [
service.ports.port0
];
2025-07-01 04:11:32 -05:00
allowedUDPPorts = [
2025-07-01 16:15:28 -05:00
8888
2025-07-01 04:11:32 -05:00
service.ports.port0
2025-07-01 13:54:00 -05:00
service.ports.port1
2025-07-01 04:11:32 -05:00
];
};
nat = {
enable = true;
enableIPv6 = true;
externalInterface = "eth0";
internalInterfaces = [ "wg0" ];
};
2025-07-01 16:08:54 -05:00
wireguard.interfaces = {
2025-07-01 04:11:32 -05:00
wg0 = {
2025-07-01 16:08:54 -05:00
ips = [ "${ceres.wireguard.ip0}/24" ];
2025-07-01 13:54:00 -05:00
listenPort = service.ports.port1;
2025-07-01 04:11:32 -05:00
privateKeyFile = config.sops.secrets."${service.name}-private".path;
peers = [
{
publicKey = "9zfRPxkxTLHM9tABC8lIaDMrzdjcF2l1mtG82uqGKUQ=";
2025-07-01 16:08:54 -05:00
allowedIPs = [ "${mars.wireguard.ip0}/32" ];
2025-07-01 04:11:32 -05:00
}
];
};
};
};
2025-07-01 04:16:52 -05:00
sops =
2025-07-01 04:11:32 -05:00
let
sopsPath = secret: {
2025-07-01 04:16:52 -05:00
path = "${service.sops.path0}/${service.name}-${secret}-pass";
2025-07-01 04:11:32 -05:00
owner = "root";
mode = "600";
};
in
2025-07-01 04:16:52 -05:00
{
secrets = builtins.listToAttrs (
map
(secret: {
name = "${service.name}-${secret}";
value = sopsPath secret;
})
[
"private"
"public"
]
);
};
2025-07-01 04:11:32 -05:00
boot.kernel.sysctl = {
"net.ipv4.ip_forward" = 1;
};
}