modules/wg-clerie: add module for public IPv6 vpn
This commit is contained in:
parent
93f1fa77e0
commit
c8acc39d8d
@ -26,39 +26,10 @@
|
|||||||
|
|
||||||
networking.firewall.enable = false;
|
networking.firewall.enable = false;
|
||||||
|
|
||||||
networking.iproute2.enable = true;
|
services.wg-clerie = {
|
||||||
networking.iproute2.rttablesExtraConfig = ''
|
|
||||||
200 wg-clerie
|
|
||||||
'';
|
|
||||||
|
|
||||||
petabyte.policyrouting = {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
rules6 = [
|
ipv6s = [ "2a01:4f8:c0c:15f1::8108/128" ];
|
||||||
{ rule = "from 2a01:4f8:c0c:15f1::8108/128 lookup wg-clerie"; prio = 20000; }
|
ipv4s = [ "10.20.30.108/32" ];
|
||||||
{ rule = "from 2a01:4f8:c0c:15f1::8108/128 unreachable"; prio = 20001; }
|
|
||||||
];
|
|
||||||
rules4 = [
|
|
||||||
{ rule = "from 10.20.30.108/32 lookup wg-clerie"; prio = 20000; }
|
|
||||||
{ rule = "from 10.20.30.108/32 unreachable"; prio = 20001; }
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
networking.wireguard.enable = true;
|
|
||||||
networking.wireguard.interfaces = {
|
|
||||||
wg-clerie = {
|
|
||||||
ips = [ "2a01:4f8:c0c:15f1::8108/128" "10.20.30.108/32" ];
|
|
||||||
table = "wg-clerie";
|
|
||||||
peers = [
|
|
||||||
{
|
|
||||||
endpoint = "vpn.clerie.de:51820";
|
|
||||||
persistentKeepalive = 25;
|
|
||||||
allowedIPs = [ "0.0.0.0/0" "::/0" "10.20.30.0/24" "2a01:4f8:c0c:15f1::/113" ];
|
|
||||||
publicKey = "2p1Jqs3bkXbXHFWE6vp1yxHIFoUaZQEARS2nJzbkuBA=";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
privateKeyFile = "/var/src/secrets/wireguard/wg-clerie";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
clerie.monitoring = {
|
clerie.monitoring = {
|
||||||
|
@ -11,5 +11,6 @@
|
|||||||
./monitoring
|
./monitoring
|
||||||
./nginx-port-forward
|
./nginx-port-forward
|
||||||
./nixfiles
|
./nixfiles
|
||||||
|
./wg-clerie
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
67
modules/wg-clerie/default.nix
Normal file
67
modules/wg-clerie/default.nix
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.wg-clerie;
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
services.wg-clerie = {
|
||||||
|
enable = mkEnableOption "VPN for public static IP";
|
||||||
|
privateKeyFile = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "/var/src/secrets/wireguard/wg-clerie";
|
||||||
|
description = "Path to file containing private key for wireguard interface";
|
||||||
|
};
|
||||||
|
ipv6s = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [];
|
||||||
|
description = "IPv6 interface addresses";
|
||||||
|
};
|
||||||
|
ipv4s = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [];
|
||||||
|
description = "IPv4 interface addresses";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
networking.iproute2.enable = true;
|
||||||
|
networking.iproute2.rttablesExtraConfig = ''
|
||||||
|
200 wg-clerie
|
||||||
|
'';
|
||||||
|
|
||||||
|
petabyte.policyrouting = {
|
||||||
|
enable = true;
|
||||||
|
rules6 = concatMap (ip: [
|
||||||
|
{ rule = "from ${ip} lookup wg-clerie"; prio = 20000; }
|
||||||
|
{ rule = "from ${ip} unreachable"; prio = 20001; }
|
||||||
|
]) cfg.ipv6s;
|
||||||
|
rules4 = concatMap (ip: [
|
||||||
|
{ rule = "from ${ip} lookup wg-clerie"; prio = 20000; }
|
||||||
|
{ rule = "from ${ip} unreachable"; prio = 20001; }
|
||||||
|
]) cfg.ipv4s;
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.wireguard.enable = true;
|
||||||
|
networking.wireguard.interfaces = {
|
||||||
|
wg-clerie = {
|
||||||
|
inherit (cfg) privateKeyFile;
|
||||||
|
ips = cfg.ipv6s ++ cfg.ipv4s;
|
||||||
|
table = "wg-clerie";
|
||||||
|
peers = [
|
||||||
|
{
|
||||||
|
endpoint = "vpn.clerie.de:51820";
|
||||||
|
persistentKeepalive = 25;
|
||||||
|
dynamicEndpointRefreshSeconds = 5;
|
||||||
|
allowedIPs = [ "0.0.0.0/0" "::/0" "10.20.30.0/24" "2a01:4f8:c0c:15f1::/113" ];
|
||||||
|
publicKey = "2p1Jqs3bkXbXHFWE6vp1yxHIFoUaZQEARS2nJzbkuBA=";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user