tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nixos/dnscrypt-wrapper: make provider keys configurable
rnhmjoj
5 years ago
743eea4c
fd3727a3
+44
-7
1 changed file
expand all
collapse all
unified
split
nixos
modules
services
networking
dnscrypt-wrapper.nix
+44
-7
nixos/modules/services/networking/dnscrypt-wrapper.nix
reviewed
···
5
5
cfg = config.services.dnscrypt-wrapper;
6
6
dataDir = "/var/lib/dnscrypt-wrapper";
7
7
8
8
+
mkPath = path: default:
9
9
+
if path != null
10
10
+
then toString path
11
11
+
else default;
12
12
+
13
13
+
publicKey = mkPath cfg.providerKey.public "${dataDir}/public.key";
14
14
+
secretKey = mkPath cfg.providerKey.secret "${dataDir}/secret.key";
15
15
+
8
16
daemonArgs = with cfg; [
9
17
"--listen-address=${address}:${toString port}"
10
18
"--resolver-address=${upstream.address}:${toString upstream.port}"
11
19
"--provider-name=${providerName}"
12
12
-
"--provider-publickey-file=public.key"
13
13
-
"--provider-secretkey-file=secret.key"
20
20
+
"--provider-publickey-file=${publicKey}"
21
21
+
"--provider-secretkey-file=${secretKey}"
14
22
"--provider-cert-file=${providerName}.crt"
15
23
"--crypt-secretkey-file=${providerName}.key"
16
24
];
···
24
32
dnscrypt-wrapper --gen-cert-file \
25
33
--crypt-secretkey-file=${cfg.providerName}.key \
26
34
--provider-cert-file=${cfg.providerName}.crt \
27
27
-
--provider-publickey-file=public.key \
28
28
-
--provider-secretkey-file=secret.key \
35
35
+
--provider-publickey-file=${publicKey} \
36
36
+
--provider-secretkey-file=${secretKey} \
29
37
--cert-file-expire-days=${toString cfg.keys.expiration}
30
38
}
31
39
32
40
cd ${dataDir}
33
41
34
42
# generate provider keypair (first run only)
35
35
-
if [ ! -f public.key ] || [ ! -f secret.key ]; then
36
36
-
dnscrypt-wrapper --gen-provider-keypair
37
37
-
fi
43
43
+
${optionalString (cfg.providerKey.public == null || cfg.providerKey.secret == null) ''
44
44
+
if [ ! -f ${publicKey} ] || [ ! -f ${secretKey} ]; then
45
45
+
dnscrypt-wrapper --gen-provider-keypair
46
46
+
fi
47
47
+
''}
38
48
39
49
# generate new keys for rotation
40
50
if [ ! -f ${cfg.providerName}.key ] || [ ! -f ${cfg.providerName}.crt ]; then
···
139
149
'';
140
150
};
141
151
152
152
+
providerKey.public = mkOption {
153
153
+
type = types.nullOr types.path;
154
154
+
default = null;
155
155
+
example = "/etc/secrets/public.key";
156
156
+
description = ''
157
157
+
The filepath to the provider public key. If not given a new
158
158
+
provider key pair will be generated on the first run.
159
159
+
'';
160
160
+
};
161
161
+
162
162
+
providerKey.secret = mkOption {
163
163
+
type = types.nullOr types.path;
164
164
+
default = null;
165
165
+
example = "/etc/secrets/secret.key";
166
166
+
description = ''
167
167
+
The filepath to the provider secret key. If not given a new
168
168
+
provider key pair will be generated on the first run.
169
169
+
'';
170
170
+
};
171
171
+
142
172
upstream.address = mkOption {
143
173
type = types.str;
144
174
default = "127.0.0.1";
···
236
266
OnUnitActiveSec = cfg.keys.checkInterval * 60;
237
267
};
238
268
};
269
269
+
270
270
+
assertions = with cfg; [
271
271
+
{ assertion = (providerKey.public == null && providerKey.secret == null) ||
272
272
+
(providerKey.secret != null && providerKey.public != null);
273
273
+
message = "The secret and public provider key must be set together.";
274
274
+
}
275
275
+
];
239
276
240
277
};
241
278