summaryrefslogtreecommitdiff
path: root/modules/wireguard.nix
blob: 43ffed161cf54abeb07fe89b91b887fa6f4c9f2a (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
{
  config,
  lib,
  pkgs,
  ...
}:

{
  options.custom.wireguardAddress = lib.mkOption {
    type = lib.types.str;
  };

  config = {
    # WireGuard — not started on boot, use `wg-quick up wg0` / `wg-quick down wg0`
    # Private key must be placed at /etc/wireguard/wg0.key (mode 600, owned by root)
    networking.wg-quick.interfaces.wg0 = {
      autostart = false;
      address = [ config.custom.wireguardAddress ];
      dns = [ "10.67.40.1" ];
      privateKeyFile = "/etc/wireguard/wg0.key";
      peers = [
        {
          publicKey = "wg37lctIxY4qbcyjVDrEI4mahH2Bhgv+73djEjJSyww=";
          endpoint = "vpn.soltermann.xyz:51820";
          allowedIPs = [ "10.67.40.0/24" ];
          persistentKeepalive = 25;
        }
      ];
    };

    programs.bash.shellAliases = {
      vpn-up = "sudo systemctl start wg-quick-wg0";
      vpn-down = "sudo systemctl stop wg-quick-wg0";
    };

    programs.fish.shellAliases = {
      vpn-up = "sudo systemctl start wg-quick-wg0";
      vpn-down = "sudo systemctl stop wg-quick-wg0";
    };

    home-manager.users.christian.custom.xmobarVpn = true;
  };
}