1
Fork 0

Better octodns file structure

This commit is contained in:
prescientmoon 2024-10-13 02:34:34 +02:00
commit 35bc79265c
Signed by: prescientmoon
SSH key fingerprint: SHA256:WFp/cO76nbarETAoQcQXuV+0h7XJsEsOCI0UsyPIy6U
33 changed files with 219 additions and 381 deletions
dns/implementation

View file

@ -0,0 +1,37 @@
{
config,
pkgs,
lib ? pkgs.lib,
}:
let
format = pkgs.formats.yaml { };
cfg = config.satellite.dns;
grouped = builtins.groupBy (entry: entry.zone) cfg.records;
cpInvocations = lib.mapAttrsToList (
zone: group:
let
grouped = builtins.groupBy (entry: entry.at) group;
contents = lib.mapAttrs (
at: entries:
lib.lists.forEach entries (
entry:
let
content =
if builtins.typeOf entry.value == "list" then
{ values = entry.value; }
else
{ inherit (entry) value; };
cloudflare = if entry.enableCloudflareProxy then { octodns.cloudflare.proxied = true; } else { };
in
{ inherit (entry) ttl type; } // content // cloudflare
)
) grouped;
file = format.generate "${zone}.yaml" contents;
in
"cp ${file} $out/${zone}.yaml"
) grouped;
in
pkgs.runCommand "octodns-zones" { } ''
mkdir $out
${lib.concatStringsSep "\n" cpInvocations}
''