at 24.11-pre 2.4 kB view raw
1{ config 2, lib 3, pkgs 4, ... 5}: 6 7with lib; 8 9let 10 cfg = config.services.routedns; 11 settingsFormat = pkgs.formats.toml { }; 12in 13{ 14 options.services.routedns = { 15 enable = mkEnableOption "RouteDNS - DNS stub resolver, proxy and router"; 16 17 settings = mkOption { 18 type = settingsFormat.type; 19 example = literalExpression '' 20 { 21 resolvers.cloudflare-dot = { 22 address = "1.1.1.1:853"; 23 protocol = "dot"; 24 }; 25 groups.cloudflare-cached = { 26 type = "cache"; 27 resolvers = ["cloudflare-dot"]; 28 }; 29 listeners.local-udp = { 30 address = "127.0.0.1:53"; 31 protocol = "udp"; 32 resolver = "cloudflare-cached"; 33 }; 34 listeners.local-tcp = { 35 address = "127.0.0.1:53"; 36 protocol = "tcp"; 37 resolver = "cloudflare-cached"; 38 }; 39 } 40 ''; 41 description = '' 42 Configuration for RouteDNS, see <https://github.com/folbricht/routedns/blob/master/doc/configuration.md> 43 for more information. 44 ''; 45 }; 46 47 configFile = mkOption { 48 default = settingsFormat.generate "routedns.toml" cfg.settings; 49 defaultText = "A RouteDNS configuration file automatically generated by values from services.routedns.*"; 50 type = types.path; 51 example = literalExpression ''"''${pkgs.routedns}/cmd/routedns/example-config/use-case-1.toml"''; 52 description = "Path to RouteDNS TOML configuration file."; 53 }; 54 55 package = mkPackageOption pkgs "routedns" { }; 56 }; 57 58 config = mkIf cfg.enable { 59 systemd.services.routedns = { 60 description = "RouteDNS - DNS stub resolver, proxy and router"; 61 after = [ "network.target" ]; # in case a bootstrap resolver is used, this might fail a few times until the respective server is actually reachable 62 wantedBy = [ "multi-user.target" ]; 63 wants = [ "network.target" ]; 64 startLimitIntervalSec = 30; 65 startLimitBurst = 5; 66 serviceConfig = { 67 Restart = "on-failure"; 68 RestartSec = "5s"; 69 LimitNPROC = 512; 70 LimitNOFILE = 1048576; 71 DynamicUser = true; 72 AmbientCapabilities = "CAP_NET_BIND_SERVICE"; 73 NoNewPrivileges = true; 74 ExecStart = "${getBin cfg.package}/bin/routedns -l 4 ${cfg.configFile}"; 75 }; 76 }; 77 }; 78 meta.maintainers = with maintainers; [ jsimonetti ]; 79}