aboutsummaryrefslogtreecommitdiff
path: root/hosts/mercury/wireguard.nix
blob: 105d10bbc64607030d016993c2522be3c2f52c83 (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
{
  config,
  hosts,
  pkgs,
  lib,
  ...
}: {
  environment.systemPackages = [pkgs.wireguard-tools];

  systemd.services.udp2raw-client = {
    description = "udp2raw WireGuard transport";
    wantedBy = ["multi-user.target"];
    after = ["network-online.target"];
    wants = ["network-online.target"];

    serviceConfig = {
      ExecStart = "${lib.getExe pkgs.udp2raw} -c -l 127.0.0.1:51820 -r 70.130.121.193:51843 -k shared-secret -a";
      Restart = "on-failure";
      RestartSec = "2s";
    };
  };

  systemd.network.netdevs."10-wg" = {
    netdevConfig = {
      Kind = "wireguard";
      Name = "wg0";
      MTUBytes = 1200;
    };
    wireguardConfig = {
      PrivateKeyFile = config.collinux.secrets."wireguard-privkey".path;
      ListenPort = 9918;
    };
    wireguardPeers = [
      {
        PublicKey = hosts.ganymede.wg_pubkey;
        AllowedIPs = ["10.100.0.0/24"];
        Endpoint = "127.0.0.1:51820";
      }
    ];
  };
  systemd.network.networks."wg0" = {
    matchConfig.Name = "wg0";
    address = ["${hosts.mercury.wg_ip}/24"];
    DHCP = "no";
    dns = [hosts.ganymede.wg_ip];
    domains = ["~ganymede"];
    networkConfig.IPv6AcceptRA = false;
    extraConfig = ''
      DNSOverTLS=no
      DNSSEC=no
    '';
  };
}