feat: simplified the dns a tad by passing through vars to functions

This commit is contained in:
silver 2024-03-12 00:11:11 +00:00
parent 97e18e5514
commit 5141b57eb5
2 changed files with 60 additions and 52 deletions

View file

@ -11,9 +11,9 @@
current_date = lib.readFile "${pkgs.runCommand "timestamp" {} "echo -n `date +%s` > $out"}"; current_date = lib.readFile "${pkgs.runCommand "timestamp" {} "echo -n `date +%s` > $out"}";
# gets a list of records that match this type # gets a list of records that match this type
filter_records_type = r_type: builtins.filter (x: x.r_type == r_type) records; filter_records_type = records: r_type: builtins.filter (x: x.r_type == r_type) records;
filter_records_server = builtins.filter (x: builtins.hasAttr "server" x && x.server) (filter_records_type "A"); filter_records_server = records: builtins.filter (x: builtins.hasAttr "server" x && x.server) (filter_records_type records "A");
filter_records_a = builtins.filter (x: builtins.hasAttr "server" x && !x.server) (filter_records_type "A"); filter_records_a = records: builtins.filter (x: builtins.hasAttr "server" x && !x.server) (filter_records_type records "A");
process_ptr = records: lib.lists.forEach records (x: process_ptr_sub x); process_ptr = records: lib.lists.forEach records (x: process_ptr_sub x);
process_ptr_sub = record: { process_ptr_sub = record: {
@ -23,11 +23,11 @@
}; };
ip_ptr_to_int = ip: lib.strings.toInt (builtins.substring 9 3 ip); ip_ptr_to_int = ip: lib.strings.toInt (builtins.substring 9 3 ip);
sort_records_server = builtins.sort (a: b: a.record < b.record) filter_records_server; sort_records_server = records: builtins.sort (a: b: a.record < b.record) (filter_records_server records);
sort_records_a = builtins.sort (a: b: (ip_ptr_to_int a.value) < (ip_ptr_to_int b.value)) filter_records_a; sort_records_a = records: builtins.sort (a: b: (ip_ptr_to_int a.value) < (ip_ptr_to_int b.value)) (filter_records_a records);
sort_records_cname = builtins.sort (a: b: a.value < b.value) (filter_records_type "CNAME"); sort_records_cname = records: builtins.sort (a: b: a.value < b.value) (filter_records_type records "CNAME");
sort_records_ptr = builtins.sort (a: b: (lib.strings.toInt a.record) < (lib.strings.toInt b.record)) (process_ptr (filter_records_type "PTR")); sort_records_ptr = records: builtins.sort (a: b: (lib.strings.toInt a.record) < (lib.strings.toInt b.record)) (process_ptr (filter_records_type records "PTR"));
sort_records_srv = builtins.sort (a: b: a.record < b.record) (filter_records_type "SRV"); sort_records_srv = records: builtins.sort (a: b: a.record < b.record) (filter_records_type records "SRV");
format_records = records: offset: lib.strings.concatMapStrings (x: "${padString x.record offset} IN ${padString x.r_type 5} ${x.value}\n") records; format_records = records: offset: lib.strings.concatMapStrings (x: "${padString x.record offset} IN ${padString x.r_type 5} ${x.value}\n") records;
@ -46,7 +46,7 @@
# base config for domains we own (skynet.ie, csn.ul.ie, ulcompsoc.ie) # base config for domains we own (skynet.ie, csn.ul.ie, ulcompsoc.ie)
get_config_file = ( get_config_file = (
domain: '' domain: records: ''
$TTL 60 ; 1 minute $TTL 60 ; 1 minute
; hostmaster@${domain} is an email address that recieves stuff related to dns ; hostmaster@${domain} is an email address that recieves stuff related to dns
@ IN SOA ${nameserver}.${domain}. hostmaster.${domain}. ( @ IN SOA ${nameserver}.${domain}. hostmaster.${domain}. (
@ -63,38 +63,38 @@
@ NS ns2.skynet.ie. @ NS ns2.skynet.ie.
; can have multiple mailserves ; can have multiple mailserves
@ MX 10 mail.${domain}. @ MX 10 mail.skynet.ie.
; ------------------------------------------ ; ------------------------------------------
; Server Names (A Records) ; Server Names (A Records)
; ------------------------------------------ ; ------------------------------------------
${format_records sort_records_server 31} ${format_records (sort_records_server records) 31}
; ------------------------------------------ ; ------------------------------------------
; A (non server names ; A (non server names
; ------------------------------------------ ; ------------------------------------------
${format_records sort_records_a 31} ${format_records (sort_records_a records) 31}
; ------------------------------------------ ; ------------------------------------------
; CNAMES ; CNAMES
; ------------------------------------------ ; ------------------------------------------
${format_records sort_records_cname 31} ${format_records (sort_records_cname records) 31}
; ------------------------------------------ ; ------------------------------------------
; TXT ; TXT
; ------------------------------------------ ; ------------------------------------------
${format_records (filter_records_type "TXT") 31} ${format_records (filter_records_type records "TXT") 31}
; ------------------------------------------ ; ------------------------------------------
; MX ; MX
; ------------------------------------------ ; ------------------------------------------
${format_records (filter_records_type "MX") 31} ${format_records (filter_records_type records "MX") 31}
; ------------------------------------------ ; ------------------------------------------
; SRV ; SRV
; ------------------------------------------ ; ------------------------------------------
${format_records sort_records_srv 65} ${format_records (sort_records_srv records) 65}
'' ''
@ -103,7 +103,7 @@
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/4/html/reference_guide/s2-bind-configuration-zone-reverse # https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/4/html/reference_guide/s2-bind-configuration-zone-reverse
# config for our reverse dnspointers (not properly working) # config for our reverse dnspointers (not properly working)
get_config_file_rev = ( get_config_file_rev = (
domain: '' domain: records: ''
$ORIGIN 64-64.99.1.193.in-addr.arpa. $ORIGIN 64-64.99.1.193.in-addr.arpa.
$TTL 60 ; 1 minute $TTL 60 ; 1 minute
; hostmaster@skynet.ie is an email address that recieves stuff related to dns ; hostmaster@skynet.ie is an email address that recieves stuff related to dns
@ -122,27 +122,7 @@
; ------------------------------------------ ; ------------------------------------------
; PTR ; PTR
; ------------------------------------------ ; ------------------------------------------
${format_records sort_records_ptr 3} ${format_records (sort_records_ptr records) 3}
''
);
# domains we dont have proper ownship over, only here to ensure the logs dont get cluttered.
get_config_file_old_domains = (
domain: ''
$TTL 60 ; 1 minute
; hostmaster@skynet.ie is an email address that recieves stuff related to dns
@ IN SOA ${nameserver}.skynet.ie. hostmaster.skynet.ie. (
; Serial (YYYYMMDDCC) this has to be updated for each time the record is updated
${current_date}
600 ; Refresh (10 minutes)
300 ; Retry (5 minutes)
604800 ; Expire (1 week)
3600 ; Minimum (1 hour)
)
@ NS ns1.skynet.ie.
@ NS ns2.skynet.ie.
'' ''
); );
@ -188,13 +168,11 @@
# (text.owned "csn.ul.ie") # (text.owned "csn.ul.ie")
# standard function to create the etc file, pass in the text and domain and it makes it # standard function to create the etc file, pass in the text and domain and it makes it
create_entry_etc = domain: type: create_entry_etc = domain: type: records:
if type == "owned" if type == "owned"
then create_entry_etc_sub domain (text.owned domain) then create_entry_etc_sub domain (text.owned domain records)
else if type == "reverse" else if type == "reverse"
then create_entry_etc_sub domain (text.reverse domain) then create_entry_etc_sub domain (text.reverse domain records)
else if type == "old"
then create_entry_etc_sub domain (text.old domain)
else {}; else {};
create_entry_zone = domain: { create_entry_zone = domain: {
@ -221,9 +199,8 @@
}; };
text = { text = {
owned = domain: get_config_file domain; owned = domain: records: get_config_file domain records;
reverse = domain: get_config_file_rev domain; reverse = domain: records: get_config_file_rev domain records;
old = domain: get_config_file_old_domains domain;
}; };
records = records =
@ -329,12 +306,12 @@ in {
// (create_entry_zone "edelharty.net" ); // (create_entry_zone "edelharty.net" );
environment.etc = environment.etc =
(create_entry_etc "csn.ul.ie" "owned") (create_entry_etc "csn.ul.ie" "owned" records)
// (create_entry_etc "skynet.ie" "owned") // (create_entry_etc "skynet.ie" "owned" records)
// (create_entry_etc "ulcompsoc.ie" "owned") // (create_entry_etc "ulcompsoc.ie" "owned" records)
// (create_entry_etc "64-64.99.1.193.in-addr.arpa" "reverse") // (create_entry_etc "64-64.99.1.193.in-addr.arpa" "reverse" records)
// (create_entry_etc "conradcollins.net" "old") // (create_entry_etc "conradcollins.net" "owned" config.skynet.records."conradcollins.net")
// (create_entry_etc "edelharty.net" "old"); // (create_entry_etc "edelharty.net" "owned" config.skynet.records."edelharty.net");
# secrets required # secrets required
age.secrets.dns_dnskeys = { age.secrets.dns_dnskeys = {

View file

@ -48,7 +48,38 @@
# some space to avoid conflicts # some space to avoid conflicts
"conradcollins.net" = [];
"edelharty.net" = [];
"brendan.ie" = [
{
record = "optimus-reborn2";
r_type = "A";
value = "193.1.99.90";
server = true;
}
{
record = "panel.games";
r_type = "CNAME";
value = "optimus-reborn";
}
{
record = "bumblebee";
r_type = "A";
value = "193.1.99.91";
server = true;
}
{
record = "minecraft.compsoc.games";
r_type = "CNAME";
value = "bumblebee";
}
{
record = "_minecraft._tcp.minecraft.compsoc.games.skynet.ie.";
r_type = "SRV";
value = "0 10 25518 minecraft.compsoc.games.skynet.ie.";
}
];
}; };
}; };