aboutsummaryrefslogtreecommitdiff
path: root/hosts/sagittarius/network.nix
blob: 9612011cade79006face18a3bd90791c9c3b2372 (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
58
59
60
61
62
63
64
{ config, ... }:
let
  # NOTE: port is the same on every host
  wgPort = 51820;
in
{
  networking = {
    hostName = "sagittarius";
    useNetworkd = true;
    firewall = {
      allowedTCPPorts = [ 22 ];
      allowedUDPPorts = [ wgPort ];
    };
  };

  systemd.network = {
    enable = true;

    networks = {
      "10-wan" = {
        matchConfig.Name = "enp1s0";
        networkConfig.DHCP = "ipv4";
        address = [ "2a01:4f9:c012:c7a7::1/64" ];
        routes = [ { Gateway = "fe80::1"; } ];
      };
      "50-wg" = {
        matchConfig.Name = "wg0";
        address = [
          "2301:db8:acad:a::1/128"
          "192.168.23.1/32"
        ];
      };
    };

    netdevs."50-wg" = {
      netdevConfig = {
        Kind = "wireguard";
        Name = "wg0";
      };

      wireguardConfig = {
        ListenPort = wgPort;
        PrivateKeyFile = config.sops.secrets."wg-priv-key".path;
        # To automatically create routes for everything in AllowedIPs,
        # add RouteTable=main
        RouteTable = "main";
        # FirewallMark marks all packets send and received by wg0 with the
        # number 42, which can be used to define policy rules on these packets.
        FirewallMark = 42;
      };

      wireguardPeers = [
        {
          # nyaan
          PublicKey = "u5nh+YNV84IbS7g0ncfs/V+cqEudNh500LQ7pmdS7j0=";
          AllowedIPs = [
            "2301:db8:acad:a::2/128"
            "192.168.23.2/32"
          ];
        }
      ];
    };
  };
}