system/wireguard: refactor and add caramel
This commit is contained in:
parent
11350fb5c2
commit
f774334203
4 changed files with 28 additions and 7 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
input
|
input
|
||||||
nix-porcupine
|
nix-porcupine
|
||||||
security
|
security
|
||||||
|
wireguard
|
||||||
|
|
||||||
./filesystem.nix
|
./filesystem.nix
|
||||||
./kernel.nix
|
./kernel.nix
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,31 @@ let
|
||||||
serverInterface = "ens3";
|
serverInterface = "ens3";
|
||||||
serverIp = "51.79.240.130";
|
serverIp = "51.79.240.130";
|
||||||
|
|
||||||
|
routeBypass = {
|
||||||
|
caramel = {
|
||||||
|
gateway = "192.168.100.1";
|
||||||
|
interface = "wlan0";
|
||||||
|
routes = [
|
||||||
|
serverIp
|
||||||
|
];
|
||||||
|
};
|
||||||
|
blossom = {
|
||||||
|
gateway = "192.168.100.1";
|
||||||
|
interface = "wlp3s0";
|
||||||
|
routes = [
|
||||||
|
serverIp
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
clients = {
|
clients = {
|
||||||
|
caramel = {
|
||||||
|
publicKey = "VDqcpS0lJzFgwikj61MJ1xc9P8Cuq0NXa+Hc+etn2iA=";
|
||||||
|
allowedIPs = [ "10.100.0.2/32" ];
|
||||||
|
};
|
||||||
blossom = {
|
blossom = {
|
||||||
publicKey = "6nVhazYdmC15A/nke9VrqIg3sOBVOmqj4GEsyBq7MVo=";
|
publicKey = "6nVhazYdmC15A/nke9VrqIg3sOBVOmqj4GEsyBq7MVo=";
|
||||||
allowedIPs = [ "10.100.0.3/32" ];
|
allowedIPs = [ "10.100.0.3/32" ];
|
||||||
interface = "wlp3s0";
|
|
||||||
gateway = "192.168.100.1";
|
|
||||||
};
|
};
|
||||||
strawberry = {
|
strawberry = {
|
||||||
publicKey = "Fkcp/VSN4Dkhly8V4hskF4lnDviA7VZHCnWf7OliFCg=";
|
publicKey = "Fkcp/VSN4Dkhly8V4hskF4lnDviA7VZHCnWf7OliFCg=";
|
||||||
|
|
@ -55,18 +74,18 @@ let
|
||||||
clientConfig = {
|
clientConfig = {
|
||||||
wireguard.interfaces.wg0 =
|
wireguard.interfaces.wg0 =
|
||||||
let
|
let
|
||||||
client = clients."${config.networking.hostName}";
|
client = routeBypass."${config.networking.hostName}";
|
||||||
|
mappedAdd = lib.concatMapStringsSep "\n" (r: "${pkgs.iproute2}/bin/ip route add ${r} via ${client.gateway} dev ${client.interface}") client.routes;
|
||||||
|
mappedDel = lib.concatMapStringsSep "\n" (r: "${pkgs.iproute2}/bin/ip route del ${r} via ${client.gateway} dev ${client.interface}") client.routes;
|
||||||
in {
|
in {
|
||||||
ips = client.allowedIPs;
|
ips = client.allowedIPs;
|
||||||
listenPort = port;
|
listenPort = port;
|
||||||
|
|
||||||
postSetup = ''
|
postSetup = mappedAdd + ''
|
||||||
${pkgs.iproute2}/bin/ip route add ${serverIp} via ${client.gateway} dev ${client.interface}
|
|
||||||
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o ${serverInterface} -j MASQUERADE
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o ${serverInterface} -j MASQUERADE
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postShutdown = ''
|
postShutdown = mappedDel + ''
|
||||||
${pkgs.iproute2}/bin/ip route del ${serverIp} via ${client.gateway} dev ${client.interface}
|
|
||||||
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o ${serverInterface} -j MASQUERADE
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o ${serverInterface} -j MASQUERADE
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,6 @@ in {
|
||||||
"secrets/wpa_conf.age".publicKeys = [ blossom caramel rin ];
|
"secrets/wpa_conf.age".publicKeys = [ blossom caramel rin ];
|
||||||
|
|
||||||
"secrets/wg_blossom.age".publicKeys = [ blossom rin ];
|
"secrets/wg_blossom.age".publicKeys = [ blossom rin ];
|
||||||
|
"secrets/wg_caramel.age".publicKeys = [ caramel rin ];
|
||||||
"secrets/wg_sugarcane.age".publicKeys = [ sugarcane rin ];
|
"secrets/wg_sugarcane.age".publicKeys = [ sugarcane rin ];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
secrets/wg_caramel.age
Normal file
BIN
secrets/wg_caramel.age
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue