all repos

dotfiles @ 1e32754

i use rach linux btw

dotfiles/nix/modules/wireguard.nix (view raw)

1
{ config, pkgs, ... }:
2
{
3
4
  boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
5
6
  networking.nat = {
7
    enable = true;
8
    externalInterface = "ens3";
9
    internalInterfaces = [ "wg0" ];
10
  };
11
12
  age.secrets.wg-private-key.file = ../secrets/wg-private-key.age;
13
14
  networking.firewall.allowedUDPPorts = [ 51820 ];
15
  networking.wireguard.interfaces.wg0 = {
16
    ips = [ "10.100.0.1/24" ];
17
    listenPort = 51820;
18
    privateKeyFile = config.age.secrets.wg-private-key.path;
19
20
    postSetup = ''${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o ens3 -j MASQUERADE'';
21
    postShutdown = ''${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 10.100.0.0/24 -o ens3 -j MASQUERADE'';
22
23
    peers = [
24
      {
25
        publicKey = "cF0abpqZiMrofQUgFHS4D+FuXq3ZoCPBQUlr6WuvBwM="; # laptop
26
        allowedIPs = [ "10.100.0.2/32" ];
27
      }
28
      {
29
        publicKey = "GodHMXUBh/0aEyz+XBJID7pm/Hi8xnZv6YzkQbl/Uwc="; # phone
30
        allowedIPs = [ "10.100.0.3/32" ];
31
      }
32
    ];
33
  };
34
}