diff options
Diffstat (limited to 'services/bacchus-dns.service.nix')
| -rw-r--r-- | services/bacchus-dns.service.nix | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/services/bacchus-dns.service.nix b/services/bacchus-dns.service.nix new file mode 100644 index 0000000..d6f45f9 --- /dev/null +++ b/services/bacchus-dns.service.nix @@ -0,0 +1,39 @@ +{ lib, config, ... }: +with lib; +let + cfg = config.services.bacchus-dns; +in +{ + options.services.bacchus-dns = { + enable = mkEnableOption "dns server mappings"; + port = mkOption { type = types.int; default = 53; }; + openFirewall = mkEnableOption "open required ports in firewall"; + ttl = mkOption { type = types.int; default = 3600; }; + fallback = mkOption { type = types.listOf types.str; default = [ "1.1.1.1" ]; }; + hosts = mkOption { type = types.attrsOf types.str; default = {}; }; + }; + + config = { + services.coredns = mkIf cfg.enable { + enable = true; + extraArgs = [ "-dns.port=${toString cfg.port}" ]; + config = '' + . { + hosts { + ${concatStringsSep "\n" ( + mapAttrsToList (domain: target: "${target} ${domain}") cfg.hosts)} + fallthrough + } + forward . ${concatStringsSep " " cfg.fallback} + cache ${toString cfg.ttl} + errors + } + ''; + }; + + networking.firewall = mkIf cfg.openFirewall { + allowedTCPPorts = [ cfg.port ]; + allowedUDPPorts = [ cfg.port ]; + }; + }; +} |
