1
Fork 0
satellite/modules/common/octodns.nix

49 lines
1.3 KiB
Nix
Raw Normal View History

2024-10-11 14:11:52 +02:00
{
config,
pkgs,
lib,
...
}:
2024-07-08 03:06:27 +02:00
let
format = pkgs.formats.yaml { };
cfg = config.satellite.dns;
in
{
options.satellite.dns.octodns = lib.mkOption {
description = "Derivation building a directory containing all the zone files";
type = lib.types.path;
};
config.satellite.dns.octodns =
let
grouped = builtins.groupBy (entry: entry.zone) cfg.records;
2024-10-11 14:11:52 +02:00
cpLines = 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;
2024-07-08 03:06:27 +02:00
in
pkgs.runCommand "octodns-zones" { } ''
mkdir $out
${lib.concatStringsSep "\n" cpLines}
'';
}