blob: d6f45f9d974c95e6442c5c5e5930a3c5fc7c72d4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 ];
};
};
}
|