2024-01-02 19:03:24 -08:00
|
|
|
{ config, pkgs, ...}:
|
2024-01-02 17:52:56 -08:00
|
|
|
|
|
|
|
let
|
|
|
|
in
|
|
|
|
{
|
2024-01-02 19:03:24 -08:00
|
|
|
networking.firewall = {
|
|
|
|
allowedUDPPorts = [
|
|
|
|
53
|
|
|
|
];
|
|
|
|
allowedTCPPorts = [
|
|
|
|
53
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.wg-quick.interfaces."protonvpn" = {
|
2024-01-02 17:52:56 -08:00
|
|
|
autostart = false;
|
2024-01-02 19:03:24 -08:00
|
|
|
privateKeyFile = "/home/nixolas/.passfiles/protonvpn";
|
|
|
|
address = [ "10.2.0.2/32" ];
|
|
|
|
listenPort = 51820;
|
|
|
|
|
|
|
|
peers = [
|
|
|
|
{
|
|
|
|
publicKey = "yB6ySO0kjqbgVWanDYKDgWoAMwM3X//nBiKXwaqmiwU=";
|
|
|
|
allowedIPs = [ "0.0.0.0/0" "::/0" ];
|
|
|
|
endpoint = "89.187.180.55:51820";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# This allows the wireguard server to route your traffic to the internet and hence be like a VPN
|
|
|
|
postUp = ''
|
2024-01-06 19:59:12 -08:00
|
|
|
${pkgs.nftables}/bin/nft -f - <<EOF
|
|
|
|
add table ip tailscale-wg;
|
|
|
|
add chain ip tailscale-wg preraw;
|
|
|
|
flush chain ip tailscale-wg preraw;
|
|
|
|
delete chain ip tailscale-wg preraw;
|
|
|
|
|
2024-01-06 21:23:01 -08:00
|
|
|
add chain ip tailscale-wg postrouting;
|
|
|
|
flush chain ip tailscale-wg postrouting;
|
|
|
|
delete chain ip tailscale-wg postrouting;
|
|
|
|
|
2024-01-06 19:59:12 -08:00
|
|
|
table ip tailscale-wg {
|
|
|
|
chain preraw {
|
|
|
|
type filter hook prerouting priority raw; policy accept;
|
|
|
|
|
|
|
|
# ip daddr 100.64.0.1 dport != 22 nftrace set 1;
|
2024-01-06 21:00:13 -08:00
|
|
|
# iifname "tailscale0" ip daddr != 100.64.0.1 nftrace set 1;
|
2024-01-06 19:59:12 -08:00
|
|
|
iifname "tailscale0" ip daddr != 100.64.0.0/16 mark set 51820;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
2024-01-06 21:00:13 -08:00
|
|
|
|
|
|
|
${pkgs.wireguard-tools}/bin/wg set protonvpn fwmark off
|
|
|
|
|
2024-01-06 19:59:12 -08:00
|
|
|
# table inet tailscale-wg { for ipv4 + ipv6
|
|
|
|
${pkgs.iproute2}/bin/ip -4 rule del not fwmark 51820 table 51820
|
|
|
|
# ${pkgs.iproute2}/bin/ip -6 rule del not fwmark 51820 table 51820
|
|
|
|
|
|
|
|
${pkgs.iproute2}/bin/ip -4 rule add fwmark 51820 table 51820
|
|
|
|
# ${pkgs.iproute2}/bin/ip -6 rule add fwmark 51820 table 51820
|
|
|
|
|
2024-01-02 19:03:24 -08:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Undo the above
|
|
|
|
preDown = ''
|
2024-01-06 19:59:12 -08:00
|
|
|
${pkgs.nftables}/bin/nft -f - <<EOF
|
|
|
|
add table ip tailscale-wg;
|
|
|
|
|
|
|
|
add chain ip tailscale-wg preraw;
|
|
|
|
flush chain ip tailscale-wg preraw;
|
|
|
|
delete chain ip tailscale-wg preraw;
|
|
|
|
|
2024-01-06 21:23:01 -08:00
|
|
|
add chain ip tailscale-wg postrouting;
|
|
|
|
flush chain ip tailscale-wg postrouting;
|
|
|
|
delete chain ip tailscale-wg postrouting;
|
|
|
|
|
2024-01-06 19:59:12 -08:00
|
|
|
delete table ip tailscale-wg;
|
|
|
|
EOF
|
|
|
|
|
2024-01-02 19:03:24 -08:00
|
|
|
'';
|
2024-01-02 17:52:56 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|