-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
90 lines (74 loc) · 2.67 KB
/
flake.nix
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
description = "lounge.rocks VPN config";
inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; };
outputs = { self, nixpkgs, ... }@inputs:
with inputs; rec {
nixosModules.lounge-vpn-client = { config, pkgs, lib, ... }:
with lib;
let cfg = config.lounge-rocks.vpn-client;
in {
options.lounge-rocks.vpn-client = {
enable = mkEnableOption "wireguard client configuration";
keyfile = mkOption {
type = types.str;
example = "/var/src/secrets/lounge-rocks-secretkey";
description = ''
Path to the file containing the secret key
'';
};
client-ip = mkOption {
type = types.str;
default = "0.0.0.0";
example = "192.168.7.1/24";
description = ''
IP address of the host.
Make sure to also set the peer entry for the server accordingly.
'';
};
};
config = mkIf cfg.enable {
networking.wireguard.interfaces = {
lounge-rocks-wg = {
ips = [ "${cfg.client-ip}/24" ];
privateKeyFile = cfg.keyfile;
peers = [{
publicKey =
"TODO"; # Public key of the server (not a file path).
# TODO Don't forward all the traffic via VPN, only particular subnets
# allowedIPs = [ "192.168.7.0/24" ];
endpoint = "vpn.lounge.rocks:51820";
persistentKeepalive = 25;
}];
};
};
};
};
nixosModules.lounge-vpn-server = { config, pkgs, lib, ... }:
with lib;
let cfg = config.lounge-rocks.vpn-client;
in {
options.lounge-rocks.vpn-server = {
enable = mkEnableOption "wireguard server configuration";
keyfile = mkOption {
type = types.str;
example = "/var/src/secrets/lounge-rocks-secretskey";
description = ''
Path to the file containing the secret key
'';
};
};
config = mkIf cfg.enable {
networking.wireguard.interfaces = {
lounge-rocks-wg = {
# Determines the IP address and subnet of the client's end of the
# tunnel interface.
# TODO ips = [ "192.168.7.1/24" ];
listenPort = 51820;
privateKeyFile = cfg.keyfile;
peers = import ./peers.nix;
};
};
};
};
};
}