feat(dns): Split out config

This commit is contained in:
Tom Hubrecht 2024-02-23 12:20:12 +01:00
parent 9767dc35a0
commit 58c8d0f6d2
4 changed files with 38 additions and 47 deletions

View file

@ -63,6 +63,8 @@ in
import ./meta/nodes.nix import ./meta/nodes.nix
); );
dns = import ./meta/dns.nix;
shells = { shells = {
default = pkgs.mkShell { default = pkgs.mkShell {
name = "dgnum-infra"; name = "dgnum-infra";

View file

@ -2,11 +2,8 @@
# Metadata for the nodes. You can add custom attributes, they are # Metadata for the nodes. You can add custom attributes, they are
# accessible through the specialArg meta in the config. # accessible through the specialArg meta in the config.
let
dns = args: import ./dns.nix (args // { inherit meta; });
meta =
lib: lib:
(lib.evalModules { (lib.evalModules {
modules = [ modules = [
./options.nix ./options.nix
@ -17,9 +14,4 @@ let
} }
]; ];
class = "dgnumMeta"; class = "dgnumMeta";
}).config; }).config
in
{
inherit dns meta;
}

View file

@ -1,35 +1,21 @@
{ { lib, dns, ... }:
lib,
meta,
dns,
...
}:
let let
inherit (lib) mapAttrs' nameValuePair;
inherit (lib.extra) fuseAttrs mapSingleFuse; inherit (lib.extra) fuseAttrs mapSingleFuse;
inherit (dns.lib.combinators) mx spf ttl; inherit (dns.lib.combinators) mx spf ttl;
meta' = meta lib; meta = (import ./.) lib;
mkCNAME = host: { CNAME = [ host ]; }; mkCNAME = host: { CNAME = [ host ]; };
mkRecord = mkHosted = server: mapSingleFuse (_: mkCNAME "${server}.${meta.nodes.${server}.site}.infra");
host:
let
net = meta'.network.${host};
in
{
A = net.addresses.publicV4;
AAAA = net.addresses.publicV6;
};
mkHosted = server: mapSingleFuse (_: mkCNAME "${server}.${meta'.nodes.${server}.site}.infra");
cnames = builtins.mapAttrs (_: to: { CNAME = [ to ]; }) { cnames = builtins.mapAttrs (_: to: { CNAME = [ to ]; }) {
dev = "dev.pages.codeberg.page."; "dev" = "dev.pages.codeberg.page.";
irc = "public.p.lahfa.xyz."; "irc" = "public.p.lahfa.xyz.";
webmail = "kurisu.dual.lahfa.xyz."; "webmail" = "kurisu.dual.lahfa.xyz.";
"*.cal" = "cal.dgnum.eu."; "*.cal" = "cal.dgnum.eu.";
"retired" = "web-static"; "retired" = "web-static";
@ -108,10 +94,6 @@ let
) )
); );
infra.subdomains =
builtins.mapAttrs (_: nodes: { subdomains = mapSingleFuse mkRecord nodes; })
meta.infra;
kurisuDKIM = [ kurisuDKIM = [
{ {
selector = "kurisu"; selector = "kurisu";
@ -164,12 +146,27 @@ in
}; };
} }
// { // {
infra = infra // { infra = {
MX = map (ttl 3600) [ (mx.mx 10 "kurisu.lahfa.xyz.") ]; MX = map (ttl 3600) [ (mx.mx 10 "kurisu.lahfa.xyz.") ];
TXT = [ (spf.strict [ "a:kurisu.lahfa.xyz" ]) ]; TXT = [ (spf.strict [ "a:kurisu.lahfa.xyz" ]) ];
DMARC = [ { p = "none"; } ]; DMARC = [ { p = "none"; } ];
DKIM = kurisuDKIM; DKIM = kurisuDKIM;
subdomains =
mapAttrs'
(
host:
{ site, ... }:
nameValuePair "${host}.${site}" (
with meta.network.${host}.addresses;
{
A = ipv4;
AAAA = ipv6;
}
)
)
meta.nodes;
}; };
}; };
} }

View file

@ -3,4 +3,4 @@ let
pkgs = import sources.nixpkgs { }; pkgs = import sources.nixpkgs { };
in in
builtins.deepSeq ((import ./.).meta pkgs.lib) { } builtins.deepSeq ((import ./.) pkgs.lib) { }