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
63
64
65
66
67
68
69
70
71
|
{ config, lib, pkgs, ... }:
with lib;
let
inherit (pkgs) stdenv;
cfg = config.networking.nextdns;
identifyingPrefix = if cfg.identifyDevice then "${config.networking.hostName}-" else "";
kresdConfig = {
enable = true;
extraConfig = ''
modules = { 'hints > iterate' }
localTrees = policy.todnames({
'lan.',
'home.',
'10.in-addr.arpa.',
'172.in-addr.arpa.',
'192.in-addr.arpa.'
})
hints.add_hosts()
policy.add(policy.suffix(policy.FLAGS({'NO_CACHE'}), localTrees))
policy.add(policy.suffix(policy.STUB({ '192.168.0.1', '192.168.1.1', '172.30.42.1', '10.0.0.1' }), localTrees))
policy.add(policy.all(policy.TLS_FORWARD({
{'45.90.28.0', hostname='${identifyingPrefix}${cfg.configID}.dns1.nextdns.io'},
{'2a07:a8c0::', hostname='${identifyingPrefix}${cfg.configID}.dns1.nextdns.io'},
{'45.90.30.0', hostname='${identifyingPrefix}${cfg.configID}.dns2.nextdns.io'},
{'2a07:a8c1::', hostname='${identifyingPrefix}${cfg.configID}.dns2.nextdns.io'}
})))
'';
};
in
{
options = {
networking.nextdns.enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable DNS resolution via NextDNS";
};
networking.nextdns.configID = mkOption {
type = types.str;
default = "";
example = literalExample "abcdef";
description = "NextDNS configuration ID";
};
networking.nextdns.identifyDevice = mkOption {
type = types.bool;
default = false;
description = "Whether to send hostname for identifying in your logs";
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = !(stdenv.isDarwin);
message = "NextDNS module is not supported on Darwin";
}
];
networking = {
networkmanager.dns = "none";
resolvconf.useLocalResolver = true;
};
services.kresd = kresdConfig;
};
}
|