mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:39:23 +08:00
86 lines
2.2 KiB
Nix
86 lines
2.2 KiB
Nix
inputs:
|
|
{
|
|
options.nixos.services.coredns = let inherit (inputs.lib) mkOption types; in mkOption
|
|
{
|
|
type = types.nullOr (types.submodule (submoduleInputs: { options =
|
|
{
|
|
interface = mkOption { type = types.str; };
|
|
};}));
|
|
default = null;
|
|
};
|
|
config = let inherit (inputs.config.nixos.services) coredns; in inputs.lib.mkIf (coredns != null)
|
|
{
|
|
services.coredns =
|
|
{
|
|
enable = true;
|
|
config =
|
|
''
|
|
autoroute.chn.moe {
|
|
bind ${coredns.interface}
|
|
geoip ${inputs.config.services.geoipupdate.settings.DatabaseDirectory}/GeoLite2-Country.mmdb
|
|
log
|
|
errors
|
|
metadata
|
|
|
|
view china {
|
|
expr metadata('geoip/country/code') == 'CN'
|
|
}
|
|
template IN A autoroute.chn.moe {
|
|
match ^autoroute\.chn\.moe\.$
|
|
answer "{{.Name}} 60 IN A ${inputs.topInputs.self.config.dns."chn.moe".getAddress "vps6"}"
|
|
}
|
|
template IN AAAA autoroute.chn.moe {
|
|
match ^autoroute\.chn\.moe\.$
|
|
rcode NOERROR
|
|
}
|
|
header {
|
|
response set aa
|
|
}
|
|
}
|
|
|
|
autoroute.chn.moe {
|
|
bind ${coredns.interface}
|
|
log
|
|
errors
|
|
metadata
|
|
|
|
template IN A autoroute.chn.moe {
|
|
match ^autoroute\.chn\.moe\.$
|
|
answer "{{.Name}} 60 IN A ${inputs.topInputs.self.config.dns."chn.moe".getAddress "vps9"}"
|
|
}
|
|
template IN AAAA autoroute.chn.moe {
|
|
match ^autoroute\.chn\.moe\.$
|
|
rcode NOERROR
|
|
}
|
|
header {
|
|
response set aa
|
|
}
|
|
}
|
|
|
|
ts.chn.moe {
|
|
bind ${coredns.interface}
|
|
template IN SOA ts.chn.moe {
|
|
match ".*"
|
|
answer "{{ .Name }} 60 IN SOA vps6.chn.moe. chn.chn.moe. 2023010100 7200 3600 1209600 3600"
|
|
}
|
|
forward . 100.100.100.100
|
|
header {
|
|
response set aa
|
|
}
|
|
log
|
|
errors
|
|
}
|
|
|
|
. {
|
|
bind ${coredns.interface}
|
|
acl {}
|
|
errors
|
|
log
|
|
}
|
|
'';
|
|
};
|
|
nixos.services.geoipupdate = {};
|
|
networking.firewall.allowedUDPPorts = [ 53 ];
|
|
};
|
|
}
|