-
Notifications
You must be signed in to change notification settings - Fork 2
/
dns.nix
62 lines (57 loc) · 1.58 KB
/
dns.nix
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{ cache-domains }: { config, lib, pkgs, ... }:
with lib;
with builtins;
let
cfg = config.lancache.dns;
domains = filter
(d: d != "" && match "^#.*" d == null)
(lib.lists.flatten (
map
(f: split "\n" (
readFile (cache-domains + "/${f}")
)
)
(filter (f: match ".*txt$" f != null) (attrNames (readDir cache-domains)))
));
ip = cfg.cacheIp;
zonefile = toFile "zonefile" "
\$TTL 600
@ IN SOA ns1 dns.lancache.net. (
${substring 0 8 cache-domains.lastModifiedDate}
604800
600
600
600 )
@ IN NS ns1
ns1 IN A ${ip}
@ IN A ${ip}
* IN A ${ip}
";
in
{
options = {
lancache.dns = {
enable = mkEnableOption "Enables the Lancache DNS server";
forwarders = mkOption {
description = "Upstream DNS servers. Defaults to CloudFlare and Google public DNS";
type = with types; listOf str;
default = [ "1.1.1.1" "8.8.8.8" ];
};
cacheIp = mkOption {
description = "IP of cache server to advertise via DNS";
type = with types; str;
};
};
};
config = mkIf cfg.enable {
services.bind = {
enable = true;
forwarders = cfg.forwarders;
cacheNetworks = [ "192.168.0.0/24" "127.0.0.0/24" ];
zones = listToAttrs (map (d: { name = d; value = { master = true; file = zonefile; }; }) (domains));
};
networking.firewall.allowedTCPPorts = [ 53 ];
networking.firewall.allowedUDPPorts = [ 53 ];
networking.resolvconf.useLocalResolver = true;
};
}