1 { lib, pkgs, config, ... }:
6 inherit (lib.types) attrsOf coercedTo listOf oneOf str int bool;
7 cfg = config.services.smartdns;
9 confFile = pkgs.writeText "smartdns.conf" (with generators;
11 mkKeyValue = mkKeyValueDefault {
14 if v then "yes" else "no"
16 mkValueStringDefault { } v;
18 listsAsDuplicateKeys =
19 true; # Allowing duplications because we need to deal with multiple entries with the same key.
22 options.services.smartdns = {
23 enable = mkEnableOption "SmartDNS DNS server";
28 description = "DNS listening port number.";
33 let atom = oneOf [ str int bool ];
34 in attrsOf (coercedTo atom toList (listOf atom));
35 example = literalExpression ''
37 bind = ":5353 -no-rule -group example";
39 server-tls = [ "8.8.8.8:853" "1.1.1.1:853" ];
40 server-https = "https://cloudflare-dns.com/dns-query -exclude-default-group";
41 prefetch-domain = true;
42 speed-check-mode = "ping,tcp:80";
46 A set that will be generated into configuration file, see the [SmartDNS README](https://github.com/pymumu/smartdns/blob/master/ReadMe_en.md#configuration-parameter) for details of configuration parameters.
47 You could override the options here like {option}`services.smartdns.bindPort` by writing `settings.bind = ":5353 -no-rule -group example";`.
52 config = lib.mkIf cfg.enable {
53 services.smartdns.settings.bind = mkDefault ":${toString cfg.bindPort}";
55 systemd.packages = [ pkgs.smartdns ];
56 systemd.services.smartdns.wantedBy = [ "multi-user.target" ];
57 systemd.services.smartdns.restartTriggers = [ confFile ];
58 environment.etc."smartdns/smartdns.conf".source = confFile;
59 environment.etc."default/smartdns".source =
60 "${pkgs.smartdns}/etc/default/smartdns";