aboutsummaryrefslogtreecommitdiff
path: root/hosts/ganymede/wireguard.nix
blob: a1be5f7208f0393995b749b98d2cb6c68c68f40e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{
  config,
  hosts,
  pkgs,
  ...
}: {
  environment.systemPackages = [pkgs.wireguard-tools];

  services.dnsmasq = {
    enable = true;
    settings = {
      port = 5353;
      local = "/ganymede/";
      address = "/.ganymede/10.100.0.1";
      listen-address = ["127.0.0.1" "10.100.0.1"];
    };
  };

  boot.kernel.sysctl."net.ipv4.ip_forward" = 1;

  networking.firewall.allowedUDPPorts = [51820 5353];
  systemd.network.netdevs."50-wg0" = {
    netdevConfig = {
      Kind = "wireguard";
      Name = "wg0";
      MTUBytes = "1300";
    };
    wireguardConfig = {
      PrivateKeyFile = config.collinux.secrets."wireguard-privkey".path;
      ListenPort = 51820;
    };
    wireguardPeers = [
      {
        PublicKey = hosts.mercury.wg_pubkey;
        AllowedIPs = ["${hosts.mercury.wg_ip}/32"];
      }
      {
        PublicKey = hosts.terra.wg_pubkey;
        AllowedIPs = ["${hosts.terra.wg_ip}/32"];
      }
    ];
  };
  systemd.network.networks."wg0" = {
    matchConfig.Name = "wg0";
    address = ["${hosts.ganymede.wg_ip}/24"];
    dns = ["127.0.0.1:5353"];
    domains = ["~ganymede"];
    networkConfig = {
      IPMasquerade = "ipv4";
      IPv4Forwarding = true;
    };
    extraConfig = ''
      DNSOverTLS=no
      DNSSEC=no
    '';
  };
}