2023-01-25 11:48:44 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.skynet_dns;
|
2023-04-23 12:37:42 +00:00
|
|
|
|
2023-04-29 01:35:58 +00:00
|
|
|
# reads that date to a string (will need to be fixed in 2038)
|
|
|
|
current_date = toString builtins.currentTime;
|
2023-04-29 00:54:17 +00:00
|
|
|
|
2023-01-25 11:48:44 +00:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
skynet_dns = {
|
|
|
|
enable = lib.mkEnableOption {
|
|
|
|
default = false;
|
|
|
|
example = true;
|
|
|
|
description = "Skynet DNS";
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
own = {
|
|
|
|
nameserver = lib.mkOption {
|
|
|
|
default = "ns1";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
the hostname of this nameserver, eg ns1, ns2
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
external = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
description = ''
|
|
|
|
External records like: agentjones A 193.1.99.72
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cname = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
description = ''
|
|
|
|
External records like: ns1 CNAME ns1
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
records = {
|
|
|
|
external = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
description = ''
|
|
|
|
External records like: agentjones A 193.1.99.72
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cname = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
description = ''
|
|
|
|
External records like: ns1 CNAME ns1
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2023-04-20 18:22:17 +00:00
|
|
|
# secrets required
|
2023-04-20 22:10:47 +00:00
|
|
|
age.secrets.dns_dnskeys = {
|
|
|
|
file = ../secrets/dns_dnskeys.conf.age;
|
|
|
|
owner = "named";
|
|
|
|
group = "named";
|
|
|
|
};
|
2023-04-20 18:22:17 +00:00
|
|
|
|
2023-04-20 23:53:25 +00:00
|
|
|
networking.firewall = {
|
|
|
|
allowedTCPPorts = [53];
|
|
|
|
allowedUDPPorts = [53];
|
|
|
|
};
|
|
|
|
|
2023-01-25 11:48:44 +00:00
|
|
|
services.bind = {
|
2023-04-23 03:22:01 +00:00
|
|
|
enable = true;
|
|
|
|
|
|
|
|
ipv4Only = true;
|
|
|
|
|
|
|
|
# need to take a look at https://nixos.org/manual/nixos/unstable/#module-security-acme-config-dns
|
|
|
|
extraConfig = ''
|
|
|
|
include "/run/agenix/dns_dnskeys";
|
|
|
|
'';
|
|
|
|
|
2023-04-24 19:17:24 +00:00
|
|
|
# piles of no valid RRSIG resolving 'com/DS/IN' errors
|
2023-04-25 14:11:02 +00:00
|
|
|
extraOptions = ''
|
|
|
|
dnssec-validation yes;
|
|
|
|
'';
|
2023-04-24 19:17:24 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
# set the upstream dns servers
|
|
|
|
# overrides the default dns servers
|
|
|
|
forwarders = [
|
|
|
|
# Cloudflare
|
|
|
|
"1.1.1.1"
|
|
|
|
# Google
|
|
|
|
"8.8.8.8"
|
|
|
|
# Quad9
|
|
|
|
"9.9.9.9"
|
|
|
|
];
|
|
|
|
|
|
|
|
cacheNetworks = [
|
|
|
|
# this server itself
|
|
|
|
"127.0.0.0/24"
|
|
|
|
# all of skynet can use this as a resolver
|
2023-05-05 13:40:27 +00:00
|
|
|
/*
|
|
|
|
Origianl idea, however all external traffic had the ip of the router
|
2023-04-23 03:22:01 +00:00
|
|
|
"193.1.99.64/26"
|
2023-05-05 13:40:27 +00:00
|
|
|
|
|
|
|
So to fix this we need to allow smaller ranges? - Didnt work
|
|
|
|
Fallback is explisitly listing each ip we have
|
|
|
|
*/
|
|
|
|
|
|
|
|
"193.1.99.71/32"
|
|
|
|
"193.1.99.72/32"
|
|
|
|
"193.1.99.73/32"
|
|
|
|
"193.1.99.71/32"
|
|
|
|
"193.1.99.74/32"
|
|
|
|
"193.1.99.75/32"
|
|
|
|
"193.1.99.76/32"
|
|
|
|
"193.1.99.77/32"
|
|
|
|
"193.1.99.78/32"
|
|
|
|
"193.1.99.79/32"
|
|
|
|
|
|
|
|
"193.1.99.80/32"
|
|
|
|
"193.1.99.81/32"
|
|
|
|
"193.1.99.82/32"
|
|
|
|
"193.1.99.83/32"
|
|
|
|
"193.1.99.81/32"
|
|
|
|
"193.1.99.84/32"
|
|
|
|
"193.1.99.85/32"
|
|
|
|
"193.1.99.86/32"
|
|
|
|
"193.1.99.87/32"
|
|
|
|
"193.1.99.88/32"
|
|
|
|
"193.1.99.89/32"
|
|
|
|
|
|
|
|
"193.1.99.90/32"
|
|
|
|
"193.1.99.91/32"
|
|
|
|
"193.1.99.92/32"
|
|
|
|
"193.1.99.93/32"
|
|
|
|
"193.1.99.91/32"
|
|
|
|
"193.1.99.94/32"
|
|
|
|
"193.1.99.95/32"
|
|
|
|
"193.1.99.96/32"
|
|
|
|
"193.1.99.97/32"
|
|
|
|
"193.1.99.98/32"
|
|
|
|
"193.1.99.99/32"
|
|
|
|
|
|
|
|
|
|
|
|
"193.1.99.100/32"
|
|
|
|
"193.1.99.101/32"
|
|
|
|
"193.1.99.102/32"
|
|
|
|
"193.1.99.103/32"
|
|
|
|
"193.1.99.101/32"
|
|
|
|
"193.1.99.104/32"
|
|
|
|
"193.1.99.105/32"
|
|
|
|
"193.1.99.106/32"
|
|
|
|
"193.1.99.107/32"
|
|
|
|
"193.1.99.108/32"
|
|
|
|
"193.1.99.109/32"
|
|
|
|
|
|
|
|
"193.1.99.110/32"
|
|
|
|
"193.1.99.111/32"
|
|
|
|
"193.1.99.112/32"
|
|
|
|
"193.1.99.113/32"
|
|
|
|
"193.1.99.111/32"
|
|
|
|
"193.1.99.114/32"
|
|
|
|
"193.1.99.115/32"
|
|
|
|
"193.1.99.116/32"
|
|
|
|
"193.1.99.117/32"
|
|
|
|
"193.1.99.118/32"
|
|
|
|
"193.1.99.119/32"
|
|
|
|
|
|
|
|
"193.1.99.120/32"
|
|
|
|
"193.1.99.121/32"
|
|
|
|
"193.1.99.122/32"
|
|
|
|
"193.1.99.123/32"
|
|
|
|
"193.1.99.121/32"
|
|
|
|
"193.1.99.124/32"
|
|
|
|
"193.1.99.125/32"
|
|
|
|
"193.1.99.126/32"
|
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
zones = {
|
|
|
|
/*
|
|
|
|
put any other zones above skynet and link to their files like so:
|
|
|
|
|
|
|
|
example.ie = {
|
|
|
|
extraConfig = "";
|
|
|
|
file = ./dns/example;
|
2023-01-25 11:48:44 +00:00
|
|
|
master = true;
|
2023-04-23 03:22:01 +00:00
|
|
|
masters = [];
|
2023-01-25 11:48:44 +00:00
|
|
|
slaves = [ ];
|
2023-04-23 03:22:01 +00:00
|
|
|
};
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
Skynet is handled a bit more dynamically since it is the key one we should focus on
|
|
|
|
*/
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
"skynet.ie" = {
|
2023-04-25 14:11:02 +00:00
|
|
|
extraConfig = ''
|
|
|
|
allow-update { key rfc2136key.skynet.ie.; };
|
|
|
|
|
|
|
|
dnssec-policy default;
|
|
|
|
inline-signing yes;
|
2023-04-29 01:35:58 +00:00
|
|
|
|
|
|
|
// for bumping the config
|
|
|
|
// ${current_date}
|
2023-04-25 14:11:02 +00:00
|
|
|
'';
|
2023-04-23 03:22:01 +00:00
|
|
|
# really wish teh nixos config didnt use master/slave
|
|
|
|
master = true;
|
|
|
|
slaves = [ ];
|
|
|
|
# need to write this to a file
|
2023-04-29 00:54:17 +00:00
|
|
|
# using the date in it so it will trigger a restart
|
2023-04-29 01:35:58 +00:00
|
|
|
file = "/etc/dns_custom/dns_zone_skynet";
|
2023-04-23 03:22:01 +00:00
|
|
|
# no leading whitespace for first line
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
# creates a folder in /etc for the dns to use
|
|
|
|
users.users.named = {
|
|
|
|
createHome = true;
|
|
|
|
home = "/etc/dns_custom";
|
|
|
|
};
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
environment.etc = {
|
|
|
|
# Creates /etc/dns_custom/dns_zone_skynet
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-29 01:35:58 +00:00
|
|
|
"dns_custom/dns_zone_skynet" = {
|
2023-04-23 03:22:01 +00:00
|
|
|
user = "named";
|
|
|
|
group = "named";
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
# The UNIX file mode bits
|
|
|
|
mode = "0644";
|
2023-01-25 11:48:44 +00:00
|
|
|
|
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
text =
|
|
|
|
''
|
|
|
|
$TTL 60 ; 1 minute
|
|
|
|
; hostmaster@skynet.ie is an email address that recieves stuff related to dns
|
2023-04-24 19:19:16 +00:00
|
|
|
@ IN SOA ${cfg.own.nameserver}.skynet.ie. hostmaster.skynet.ie. (
|
2023-04-24 19:14:24 +00:00
|
|
|
; Serial (YYYYMMDDCC) this has to be updated for each time the record is updated
|
|
|
|
${current_date}
|
|
|
|
600 ; Refresh (10 minutes)
|
2023-04-24 19:19:16 +00:00
|
|
|
300 ; Retry (5 minutes)
|
|
|
|
604800 ; Expire (1 week)
|
2023-04-24 19:14:24 +00:00
|
|
|
3600 ; Minimum (1 hour)
|
|
|
|
)
|
2023-04-24 19:40:48 +00:00
|
|
|
|
|
|
|
@ NS ns1.skynet.ie.
|
|
|
|
@ NS ns2.skynet.ie.
|
2023-04-24 19:14:24 +00:00
|
|
|
; @ stands for teh root domain so teh A record below is where skynet.ie points to
|
2023-04-24 19:40:48 +00:00
|
|
|
@ A 193.1.99.76
|
|
|
|
;@ MX 5 mail.skynet.ie.
|
2023-04-23 12:37:42 +00:00
|
|
|
|
|
|
|
; can have multiple mailserves
|
2023-04-24 19:40:48 +00:00
|
|
|
;@ MX 20 mail2.skynet.ie.
|
2023-01-25 11:48:44 +00:00
|
|
|
|
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
; ------------------------------------------
|
|
|
|
; Server Names
|
|
|
|
; ------------------------------------------
|
2023-01-25 11:48:44 +00:00
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
; External addresses
|
|
|
|
; ------------------------------------------
|
2023-04-29 01:35:58 +00:00
|
|
|
${lib.strings.concatMapStrings (x: x + "\n") cfg.records.external}
|
2023-01-25 11:48:44 +00:00
|
|
|
|
|
|
|
|
2023-04-23 03:22:01 +00:00
|
|
|
; this is fixed for now
|
|
|
|
wintermute A 193.1.101.148
|
|
|
|
|
|
|
|
|
|
|
|
; internal addresses
|
|
|
|
; ------------------------------------------
|
|
|
|
; May come back to this idea in teh future
|
|
|
|
; agentjones.int A 172.20.20.1
|
|
|
|
|
|
|
|
|
|
|
|
; cname's
|
|
|
|
; ------------------------------------------
|
2023-04-29 01:35:58 +00:00
|
|
|
${lib.strings.concatMapStrings (x: x + "\n") cfg.records.cname}
|
2023-04-23 03:22:01 +00:00
|
|
|
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-01-17 22:40:04 +00:00
|
|
|
}
|