From ec8b458d751a4075aab09ec3995385baf70fc383 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sat, 29 Apr 2023 01:54:17 +0100 Subject: [PATCH] dns: use a hash to make a unique config file --- applications/dns.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/applications/dns.nix b/applications/dns.nix index 44003af..03a8dfa 100644 --- a/applications/dns.nix +++ b/applications/dns.nix @@ -6,6 +6,16 @@ let current_date_path = pkgs.runCommand "current_date" {} "date '+%s' > $out"; # reads that date to a string 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 { options = { skynet_dns = { @@ -136,7 +146,8 @@ in { master = true; slaves = [ ]; # 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 }; @@ -152,7 +163,7 @@ in { environment.etc = { # Creates /etc/dns_custom/dns_zone_skynet - "dns_custom/dns_zone_skynet" = { + "dns_custom/dns_zone_skynet_${current_file}" = { user = "named"; group = "named"; @@ -189,7 +200,7 @@ in { ; External addresses ; ------------------------------------------ - ${lib.strings.concatMapStrings (x: x + "\n") cfg.records.external} + ${current_external} ; this is fixed for now @@ -204,7 +215,7 @@ in { ; cname's ; ------------------------------------------ - ${lib.strings.concatMapStrings (x: x + "\n") cfg.records.cname} + ${current_cname} ''; };