git.iko.soy/typeable/nixpkgs
on master help sign in
dnscrypt-proxy service: support custom providers

The primary use-case is private DNSCrypt providers. Also rename the `port` option to differentiate it from the `customResolver.port` option.

commitffc6275e552b0fbc955ce96865de2fbb5a4c89d0 authorJoachim Fasting <joachifm@fastmail.fm> dateTue 14 Apr 2015, 23:11 (12 years ago) parent8131065
2 files changed+56−8
nixos/modules/rename.nix+3 nixos/modules/services/networking/dnscrypt-proxy.nix+53−8
nixos/modules/rename.nix+3
@@ -141,6 +141,9 @@ in zipModules ([]
141141++ obsolete [ "services" "xserver" "windowManager" "xbmc" ] [ "services" "xserver" "desktopManager" "kodi" ]
142142++ obsolete [ "services" "xserver" "desktopManager" "xbmc" ] [ "services" "xserver" "desktopManager" "kodi" ]
143143
144+# DNSCrypt-proxy
145+++ obsolete [ "services" "dnscrypt-proxy" "port" ] [ "services" "dnscrypt-proxy" "localPort" ]
146+
144147# Options that are obsolete and have no replacement.
145148++ obsolete' [ "boot" "loader" "grub" "bootDevice" ]
146149++ obsolete' [ "boot" "initrd" "luks" "enable" ]
nixos/modules/services/networking/dnscrypt-proxy.nix+53−8
@@ -6,12 +6,22 @@ let
66 dnscrypt-proxy = pkgs.dnscrypt-proxy;
77 cfg = config.services.dnscrypt-proxy;
88 resolverListFile = "${dnscrypt-proxy}/share/dnscrypt-proxy/dnscrypt-resolvers.csv";
9+ localAddress = "${cfg.localAddress}:${toString cfg.localPort}";
910 daemonArgs =
10− [ "--local-address=${cfg.localAddress}:${toString cfg.port}"
11+ [ "--local-address=${localAddress}"
1112 (optionalString cfg.tcpOnly "--tcp-only")
12− "--resolvers-list=${resolverListFile}"
13− "--resolver-name=${cfg.resolverName}"
14− ];
13+ ]
14+ ++ resolverArgs;
15+ resolverArgs = if (cfg.customResolver != null)
16+ then
17+ [ "--resolver-address=${cfg.customResolver.address}:${toString cfg.customResolver.port}"
18+ "--provider-name=${cfg.customResolver.name}"
19+ "--provider-key=${cfg.customResolver.key}"
20+ ]
21+ else
22+ [ "--resolvers-list=${resolverListFile}"
23+ "--resolver-name=${toString cfg.resolverName}"
24+ ];
1525in
1626
1727{
@@ -31,7 +41,7 @@ in
3141 Listen for DNS queries on this address.
3242 '';
3343 };
34− port = mkOption {
44+ localPort = mkOption {
3545 default = 53;
3646 type = types.int;
3747 description = ''
@@ -40,7 +50,7 @@ in
4050 };
4151 resolverName = mkOption {
4252 default = "opendns";
43− type = types.string;
53+ type = types.nullOr types.string;
4454 description = ''
4555 The name of the upstream DNSCrypt resolver to use. See
4656 <literal>${resolverListFile}</literal> for alternative resolvers
@@ -48,6 +58,35 @@ in
4858 location).
4959 '';
5060 };
61+ customResolver = mkOption {
62+ default = null;
63+ description = ''
64+ Use a resolver not listed in the upstream list (e.g.,
65+ a private DNSCrypt provider). For advanced users only.
66+ If specified, this option takes precedence.
67+ '';
68+ type = types.nullOr (types.submodule ({ ... }: { options = {
69+ address = mkOption {
70+ type = types.str;
71+ description = "Resolver IP address";
72+ example = "208.67.220.220";
73+ };
74+ port = mkOption {
75+ type = types.int;
76+ description = "Resolver port";
77+ default = 443;
78+ };
79+ name = mkOption {
80+ type = types.str;
81+ description = "Provider fully qualified domain name";
82+ example = "2.dnscrypt-cert.opendns.com";
83+ };
84+ key = mkOption {
85+ type = types.str;
86+ description = "Provider public key";
87+ example = "B735:1140:206F:225D:3E2B:D822:D7FD:691E:A1C3:3CC8:D666:8D0C:BE04:BFAB:CA43:FB79";
88+ }; }; }));
89+ };
5190 tcpOnly = mkOption {
5291 default = false;
5392 type = types.bool;
@@ -62,6 +101,12 @@ in
62101
63102 config = mkIf cfg.enable {
64103
104+ assertions = [
105+ { assertion = (cfg.customResolver != null) || (cfg.resolverName != null);
106+ message = "please configure upstream DNSCrypt resolver";
107+ }
108+ ];
109+
65110 security.apparmor.profiles = mkIf apparmorEnabled (singleton (pkgs.writeText "apparmor-dnscrypt-proxy" ''
66111 ${dnscrypt-proxy}/bin/dnscrypt-proxy {
67112 /dev/null rw,
@@ -99,8 +144,8 @@ in
99144 systemd.sockets.dnscrypt-proxy = {
100145 description = "dnscrypt-proxy listening socket";
101146 socketConfig = {
102− ListenStream = "${cfg.localAddress}:${toString cfg.port}";
103− ListenDatagram = "${cfg.localAddress}:${toString cfg.port}";
147+ ListenStream = "${localAddress}";
148+ ListenDatagram = "${localAddress}";
104149 };
105150 wantedBy = [ "sockets.target" ];
106151 };