dns: use a hash to make a unique config file

This commit is contained in:
silver 2023-04-29 01:54:17 +01:00
parent e8254a0d65
commit ec8b458d75

View file

@ -6,6 +6,16 @@ let
current_date_path = pkgs.runCommand "current_date" {} "date '+%s' > $out"; current_date_path = pkgs.runCommand "current_date" {} "date '+%s' > $out";
# reads that date to a string # reads that date to a string
current_date = (lib.readFile current_date_path); current_date = (lib.readFile current_date_path);
# get all the records as a string (used later in teh zone file)
current_external = lib.strings.concatMapStrings (x: x + "\n") cfg.records.external;
current_cname = lib.strings.concatMapStrings (x: x + "\n") cfg.records.cname;
# get a hash of these two (cut down into a more manageable size)
current_hash = lib.substring 0 10 (builtins.hashString "md5" "${current_external}_${current_cname}");
# create a custom filepath
current_file = "${current_date}_${current_hash}";
in { in {
options = { options = {
skynet_dns = { skynet_dns = {
@ -136,7 +146,8 @@ in {
master = true; master = true;
slaves = [ ]; slaves = [ ];
# need to write this to a file # need to write this to a file
file = "/etc/dns_custom/dns_zone_skynet"; # using the date in it so it will trigger a restart
file = "/etc/dns_custom/dns_zone_skynet_${current_file}";
# no leading whitespace for first line # no leading whitespace for first line
}; };
@ -152,7 +163,7 @@ in {
environment.etc = { environment.etc = {
# Creates /etc/dns_custom/dns_zone_skynet # Creates /etc/dns_custom/dns_zone_skynet
"dns_custom/dns_zone_skynet" = { "dns_custom/dns_zone_skynet_${current_file}" = {
user = "named"; user = "named";
group = "named"; group = "named";
@ -189,7 +200,7 @@ in {
; External addresses ; External addresses
; ------------------------------------------ ; ------------------------------------------
${lib.strings.concatMapStrings (x: x + "\n") cfg.records.external} ${current_external}
; this is fixed for now ; this is fixed for now
@ -204,7 +215,7 @@ in {
; cname's ; cname's
; ------------------------------------------ ; ------------------------------------------
${lib.strings.concatMapStrings (x: x + "\n") cfg.records.cname} ${current_cname}
''; '';
}; };