aboutsummaryrefslogtreecommitdiff
path: root/modules/services/nixos/wireguard/client.nix
blob: ec41ad5401466210dea653b0073b8829685583c8 (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
{
  config,
  lib,
  ...
}: let
  cfg = config.collinux.services.networking.wireguard;
in
  lib.mkIf (cfg.enable && cfg.localPeer.role == "spoke") {
    boot.extraModulePackages = [config.boot.kernelPackages.wireguard];

    # we know the machine is configured to use networkd already
    systemd.network = {
      netdevs = {
        "10-wg0" = {
          netdevConfig = {
            Kind = "wireguard";
            Name = "wg0";
          };

          wireguardConfig = {
            PrivateKeyFile = cfg.privateKeyFile;
            ListenPort = 51820;
          };

          wireguardPeers = [
            {
              PublicKey = ""; # will configure later
              AllowedIPs = ["100.100.0.1"];
              Endpoint = "williamsfam.us.com:51820"; # not configured yet
            }
          ];
        };
      };

      networks."12-wireguard" = {
        name = "wg0";

        networkConfig = {
          Address = cfg.ip;
          Gateway = "100.100.0.1";
          DHCP = "no";

          # disable ipv6 addresses
          IPv6AcceptRA = "no";
          IPv6PrivacyExtensions = "no";
          LinkLocalAddressing = "no";
        };
      };
    };
  }