-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.nix
152 lines (133 loc) · 3.48 KB
/
options.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{ config, lib, ... }:
let
cfg = config.router;
inherit (import ./lib.nix { inherit lib; })
generateHextets
mkUlaNetwork
parseIpv6Network
;
inherit (lib)
mkDefault
mkEnableOption
mkIf
mkOption
types
;
guaNetwork = parseIpv6Network cfg.ipv6GuaPrefix;
ulaNetwork = parseIpv6Network cfg.ipv6UlaPrefix;
in
{
options.router = {
enable = mkEnableOption "nixos router";
ipv6Only = mkEnableOption "IPv6-only LAN";
wanInterface = mkOption {
type = types.str;
description = ''
The name of the WAN interface.
'';
};
wanSupportsDHCPv6 = mkOption {
type = types.bool;
default = true;
description = ''
Enable DHCPv6 on the WAN interface.
'';
};
wan6PrefixHint = mkOption {
type = types.int;
default = 56;
description = ''
Prefix length that the DHVPv6 client will use to hint to the server for
prefix delegation.
'';
};
heTunnelBroker = {
enable = mkEnableOption "Hurricane Electric TunnelBroker node";
name = mkOption {
type = types.str;
default = "hurricane";
description = ''
The name of the SIT netdev.
'';
};
mtu = mkOption {
type = types.number;
default = 1480;
description = ''
The MTU of the SIT netdev.
'';
};
serverIPv4Address = mkOption {
type = types.str;
example = "192.0.2.1";
description = ''
The IPv4 address of the tunnel broker server.
'';
};
serverIPv6Address = mkOption {
type = types.str;
example = "2001:db8::1";
description = ''
The IPv6 address of the tunnel broker server.
'';
};
clientIPv6Address = mkOption {
type = types.str;
example = "2001:db8::2/64";
description = ''
The IPv6 address of the tunnel broker client with the network's
prefix. This option must include the network prefix.
'';
};
};
lanInterface = mkOption {
type = types.str;
description = ''
The name of the physical interface that will be used for this network.
'';
};
ipv6GuaPrefix = mkOption {
type = types.nullOr types.str;
example = "2001:db8::1/64";
default = null;
description = ''
The 64-bit IPv6 GUA network prefix (in CIDR notation).
'';
};
ipv6UlaPrefix = mkOption {
internal = true;
readOnly = true;
type = types.str;
example = "fd38:5f81:b15d::/64";
description = ''
The 64-bit IPv6 ULA network prefix (in CIDR notation).
'';
};
dns = {
upstreamProvider = mkOption {
type = types.enum [
"google"
"cloudflare"
"quad9"
"quad9-ecs"
];
default = "google";
description = ''
The upstream DNS provider to use.
'';
};
};
};
config = mkIf cfg.enable {
assertions = [
{
# We cannot fit a host's MAC address in an IPv6 address if the network
# is smaller than a /64.
message = "ULA and GUA IPv6 network prefix must be greater than or equal to a /64";
assertion =
(cfg.ipv6GuaPrefix != null -> (guaNetwork.prefixLength <= 64)) && (ulaNetwork.prefixLength <= 64);
}
];
router.ipv6UlaPrefix = mkDefault (mkUlaNetwork (generateHextets config.networking.hostName) 64);
};
}