diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-06-14 16:40:48 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-06-14 16:40:48 +0530 |
| commit | 42df69164dbc74e5ddb54f5a7a01fd66260fef57 (patch) | |
| tree | bc8b19c39df9edf16ca6827005b3d5e1ef564764 /services/bacchus-dns.service.nix | |
| parent | 58519ea7b12e8ad58c0f97d9636d30572a789b41 (diff) | |
| download | homeserver-nixos-config-42df69164dbc74e5ddb54f5a7a01fd66260fef57.tar.gz homeserver-nixos-config-42df69164dbc74e5ddb54f5a7a01fd66260fef57.zip | |
Switch to coredns + refactor dns hosts mapping into service + more refactor
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 ]; + }; + }; +} |
