9 cfg = config.services.doh-server;
10 toml = pkgs.formats.toml { };
13 options.services.doh-server = {
14 enable = lib.mkEnableOption "DNS-over-HTTPS server";
16 package = lib.mkPackageOption pkgs "dns-over-https" { };
18 settings = lib.mkOption {
19 type = lib.types.submodule {
20 freeformType = toml.type;
23 listen = lib.mkOption {
24 type = lib.types.listOf lib.types.str;
30 description = "HTTP listen address and port";
35 default = "/dns-query";
36 example = "/dns-query";
37 description = "HTTP path for resolve application";
40 upstream = lib.mkOption {
41 type = lib.types.listOf lib.types.str;
48 example = [ "udp:127.0.0.1:53" ];
50 Upstream DNS resolver.
51 If multiple servers are specified, a random one will be chosen each time.
52 You can use "udp", "tcp" or "tcp-tls" for the type prefix.
53 For "udp", UDP will first be used, and switch to TCP when the server asks to or the response is too large.
54 For "tcp", only TCP will be used.
55 For "tcp-tls", DNS-over-TLS (RFC 7858) will be used to secure the upstream connection.
59 timeout = lib.mkOption {
63 description = "Upstream timeout";
66 tries = lib.mkOption {
70 description = "Number of tries if upstream DNS fails";
73 verbose = lib.mkOption {
74 type = lib.types.bool;
77 description = "Enable logging";
80 log_guessed_client_ip = lib.mkOption {
81 type = lib.types.bool;
85 Enable log IP from HTTPS-reverse proxy header: X-Forwarded-For or X-Real-IP
86 Note: http uri/useragent log cannot be controlled by this config
90 ecs_allow_non_global_ip = lib.mkOption {
91 type = lib.types.bool;
95 By default, non global IP addresses are never forwarded to upstream servers.
96 This is to prevent two things from happening:
97 1. the upstream server knowing your private LAN addresses;
98 2. the upstream server unable to provide geographically near results,
99 or even fail to provide any result.
100 However, if you are deploying a split tunnel corporation network environment, or for any other reason you want to inhibit this behavior and allow local (eg RFC1918) address to be forwarded, change the following option to "true".
104 ecs_use_precise_ip = lib.mkOption {
105 type = lib.types.bool;
109 If ECS is added to the request, let the full IP address or cap it to 24 or 128 mask. This option is to be used only on private networks where knowledge of the terminal endpoint may be required for security purposes (eg. DNS Firewalling). Not a good option on the internet where IP address may be used to identify the user and not only the approximate location.
116 listen = [ ":8153" ];
117 upstream = [ "udp:127.0.0.1:53" ];
119 description = "Configuration of doh-server in toml. See example in https://github.com/m13253/dns-over-https/blob/master/doh-server/doh-server.conf";
122 useACMEHost = lib.mkOption {
123 type = lib.types.nullOr lib.types.str;
125 example = "doh.example.com";
127 A host of an existing Let's Encrypt certificate to use.
128 *Note that this option does not create any certificates, nor it does add subdomains to existing ones – you will need to create them manually using [](#opt-security.acme.certs).*
132 configFile = lib.mkOption {
133 type = lib.types.path;
134 example = "/path/to/doh-server.conf";
136 The config file for the doh-server.
137 Setting this option will override any configuration applied by the `settings` option.
141 config = lib.mkIf cfg.enable {
142 services.doh-server.configFile = lib.mkDefault (toml.generate "doh-server.conf" cfg.settings);
143 services.doh-server.settings = lib.mkIf (cfg.useACMEHost != null) (
145 sslCertDir = config.security.acme.certs.${cfg.useACMEHost}.directory;
148 cert = "${sslCertDir}/cert.pem";
149 key = "${sslCertDir}/key.pem";
152 systemd.services.doh-server = {
153 description = "DNS-over-HTTPS Server";
154 documentation = [ "https://github.com/m13253/dns-over-https" ];
157 ] ++ lib.optional (cfg.useACMEHost != null) "acme-${cfg.useACMEHost}.service";
158 wants = lib.optional (cfg.useACMEHost != null) "acme-finished-${cfg.useACMEHost}.target";
159 wantedBy = [ "multi-user.target" ];
161 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
162 ExecStart = "${cfg.package}/bin/doh-server -conf ${cfg.configFile}";
163 LimitNOFILE = 1048576;
168 SupplementaryGroups = lib.optional (cfg.useACMEHost != null) "acme";
173 meta.maintainers = with lib.maintainers; [ DictXiong ];
174 meta.doc = ./doh-server.md;