@@ -6,8 +6,6 @@ let
66
77 stateDirectory = "/var/lib/dnscrypt-proxy";
88
9− localAddress = "${cfg.localAddress}:${toString cfg.localPort}";
10−
119 # The minisign public key used to sign the upstream resolver list.
1210 # This is somewhat more flexible than preloading the key as an
1311 # embedded string.
@@ -16,31 +14,36 @@ let
1614 sha256 = "18lnp8qr6ghfc2sd46nn1rhcpr324fqlvgsp4zaigw396cd7vnnh";
1715 };
1816
19− # Internal flag indicating whether the upstream resolver list is used
17+ # Internal flag indicating whether the upstream resolver list is used.
2018 useUpstreamResolverList = cfg.resolverList == null && cfg.customResolver == null;
2119
20+ # The final local address.
21+ localAddress = "${cfg.localAddress}:${toString cfg.localPort}";
22+
23+ # The final resolvers list path.
2224 resolverList =
2325 if (cfg.resolverList != null)
2426 then cfg.resolverList
2527 else "${stateDirectory}/dnscrypt-resolvers.csv";
2628
27− resolverArgs = if (cfg.customResolver != null)
28− then
29− [ "--resolver-address=${cfg.customResolver.address}:${toString cfg.customResolver.port}"
30− "--provider-name=${cfg.customResolver.name}"
31− "--provider-key=${cfg.customResolver.key}"
32− ]
33− else
34− [ "--resolvers-list=${resolverList}"
35− "--resolver-name=${cfg.resolverName}"
36− ];
37−
38− # The final command line arguments passed to the daemon
29+ # Build daemon command line
30+
31+ resolverArgs =
32+ if (cfg.customResolver == null)
33+ then
34+ [ "-L ${resolverList}"
35+ "-R ${cfg.resolverName}"
36+ ]
37+ else with cfg.customResolver;
38+ [ "-N ${name}"
39+ "-k ${key}"
40+ "-r ${address}:${toString port}"
41+ ];
42+
3943 daemonArgs =
40− [ "--local-address=${localAddress}" ]
41− ++ optional cfg.tcpOnly "--tcp-only"
42− ++ optional cfg.ephemeralKeys "-E"
43− ++ resolverArgs;
44+ [ "-a ${localAddress}" ]
45+ ++ resolverArgs
46+ ++ cfg.extraArgs;
4447in
4548
4649{
@@ -50,6 +53,9 @@ in
5053 };
5154
5255 options = {
56+ # Before adding another option, consider whether it could
57+ # equally well be passed via extraArgs.
58+
5359 services.dnscrypt-proxy = {
5460 enable = mkOption {
5561 default = false;
@@ -131,24 +137,13 @@ in
131137 }; }));
132138 };
133139
134− tcpOnly = mkOption {
135− default = false;
136− type = types.bool;
137− description = ''
138− Force sending encrypted DNS queries to the upstream resolver over
139− TCP instead of UDP (on port 443). Use only if the UDP port is blocked.
140− '';
141− };
142−
143− ephemeralKeys = mkOption {
144− default = false;
145− type = types.bool;
140+ extraArgs = mkOption {
141+ default = [];
142+ type = types.listOf types.str;
146143 description = ''
147− Compute a new key pair for every query. Enabling this option
148− increases CPU usage, but makes it more difficult for the upstream
149− resolver to track your usage of their service across IP addresses.
150− The default is to re-use the public key pair for all queries, making
151− tracking trivial.
144+ Additional command-line arguments passed verbatim to the daemon.
145+ See <citerefentry><refentrytitle>dnscrypt-proxy</refentrytitle>
146+ <manvolnum>8</manvolnum></citerefentry> for details.
152147 '';
153148 };
154149 };
@@ -309,5 +304,19 @@ in
309304
310305 imports = [
311306 (mkRenamedOptionModule [ "services" "dnscrypt-proxy" "port" ] [ "services" "dnscrypt-proxy" "localPort" ])
307+
308+ (mkChangedOptionModule
309+ [ "services" "dnscrypt-proxy" "tcpOnly" ]
310+ [ "services" "dnscrypt-proxy" "extraArgs" ]
311+ (config:
312+ let val = getAttrFromPath [ "services" "dnscrypt-proxy" "tcpOnly" ] config; in
313+ optional val "-T"))
314+
315+ (mkChangedOptionModule
316+ [ "services" "dnscrypt-proxy" "ephemeralKeys" ]
317+ [ "services" "dnscrypt-proxy" "extraArgs" ]
318+ (config:
319+ let val = getAttrFromPath [ "services" "dnscrypt-proxy" "ephemeralKeys" ] config; in
320+ optional val "-E"))
312321 ];
313322}