mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-03-22 23:29:08 +01:00
nameservers: Restructure modules
This commit is contained in:
parent
1f2c921b81
commit
2b26c715f2
6 changed files with 10 additions and 10 deletions
83
modules/nixos/services/nameservers/private.nix
Normal file
83
modules/nixos/services/nameservers/private.nix
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
{
|
||||
config,
|
||||
inputs,
|
||||
self,
|
||||
lib,
|
||||
allHosts,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.custom.services.private-nameserver;
|
||||
netCfg = config.custom.networking;
|
||||
|
||||
zoneData = inputs.dns.lib.toString netCfg.overlay.domain {
|
||||
SOA = {
|
||||
nameServer = "${netCfg.overlay.fqdn}.";
|
||||
adminEmail = "hostmaster@sstork.dev";
|
||||
serial = 1;
|
||||
};
|
||||
|
||||
NS =
|
||||
allHosts
|
||||
|> lib.attrValues
|
||||
|> lib.filter (host: host.config.custom.services.private-nameserver.enable)
|
||||
|> lib.map (host: "${host.config.custom.networking.overlay.fqdn}.");
|
||||
|
||||
subdomains =
|
||||
let
|
||||
mkSubdomain =
|
||||
{ name, address }:
|
||||
{
|
||||
inherit name;
|
||||
value.A = [ address ];
|
||||
};
|
||||
|
||||
nodeRecords =
|
||||
netCfg.nodes
|
||||
|> lib.map (node: {
|
||||
name = node.hostName;
|
||||
inherit (node.overlay) address;
|
||||
});
|
||||
|
||||
serviceRecords =
|
||||
allHosts
|
||||
|> lib.attrValues
|
||||
|> lib.concatMap (
|
||||
host:
|
||||
host.config.custom.services.caddy.virtualHosts
|
||||
|> lib.attrValues
|
||||
|> lib.map (vHost: vHost.domain)
|
||||
|> lib.filter (domain: self.lib.isPrivateDomain domain)
|
||||
|> lib.map (domain: {
|
||||
name = domain |> lib.removeSuffix ".${netCfg.overlay.domain}";
|
||||
inherit (host.config.custom.networking.overlay) address;
|
||||
})
|
||||
);
|
||||
in
|
||||
(nodeRecords ++ serviceRecords) |> lib.map mkSubdomain |> lib.listToAttrs;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.custom.services.private-nameserver.enable = lib.mkEnableOption "";
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
services = {
|
||||
nsd = {
|
||||
enable = true;
|
||||
interfaces = [ netCfg.overlay.interface ];
|
||||
zones.${netCfg.overlay.domain}.data = zoneData;
|
||||
};
|
||||
|
||||
nebula.networks.mesh.firewall.inbound = lib.singleton {
|
||||
port = 53;
|
||||
proto = "any";
|
||||
host = "any";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.nsd = {
|
||||
requires = [ netCfg.overlay.systemdUnit ];
|
||||
after = [ netCfg.overlay.systemdUnit ];
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue