nixos/services: make dns configuration easier
This commit is contained in:
@@ -28,14 +28,6 @@ in
|
||||
./vm.nix
|
||||
];
|
||||
|
||||
age.secrets = {
|
||||
dns-root-key = {
|
||||
file = ../agenix/dns/tuxcord.key;
|
||||
group = "named";
|
||||
owner = "named";
|
||||
};
|
||||
};
|
||||
|
||||
nix = {
|
||||
package = inputs'.nix-super.packages.default;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
./storage.nix
|
||||
];
|
||||
|
||||
dns.enable = true;
|
||||
networking.fqdn = "tuxcord.net";
|
||||
time.timeZone = "Canada/Eastern";
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
dns.enable = true;
|
||||
networking.fqdn = "tuxcord.test";
|
||||
}
|
||||
|
||||
+81
-39
@@ -1,58 +1,100 @@
|
||||
{ config, ... }:
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
fqdn = "tuxcord.net";
|
||||
# fqdn = config.networking.fqdn;
|
||||
agenixDnsDir = ../../agenix/dns + "/${config.dns.domain}";
|
||||
agenixKeys = builtins.attrNames (builtins.readDir agenixDnsDir);
|
||||
|
||||
zonesub = _: "zonesub";
|
||||
subdomain = name: "subdomain ${name}";
|
||||
keys = map (
|
||||
filename:
|
||||
let
|
||||
zonesub = _: "zonesub";
|
||||
subdomain = name: "subdomain ${name}";
|
||||
|
||||
# careful, assumes the fqdn (name) matches the key name content
|
||||
keys = [
|
||||
zoneDomain =
|
||||
if lib.strings.hasSuffix ".key.age" filename then
|
||||
lib.strings.removeSuffix ".key.age" filename
|
||||
else
|
||||
throw "${filename} is not a `.key.age` file";
|
||||
in
|
||||
{
|
||||
name = "tuxcord.net";
|
||||
path = config.age.secrets.dns-root-key.path;
|
||||
type = zonesub;
|
||||
name = zoneDomain;
|
||||
path = config.age.secrets."dns/${filename}".path;
|
||||
type = if zoneDomain == config.dns.domain then zonesub else subdomain;
|
||||
}
|
||||
];
|
||||
) agenixKeys;
|
||||
|
||||
cfg = config.dns;
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkOption
|
||||
mkIf
|
||||
;
|
||||
in
|
||||
{
|
||||
services.bind = {
|
||||
enable = true;
|
||||
options.dns = {
|
||||
enable = mkEnableOption "" // {
|
||||
default = true;
|
||||
};
|
||||
|
||||
extraConfig = builtins.concatStringsSep "\n" (map (key: "include \"${key.path}\";") keys);
|
||||
|
||||
zones = {
|
||||
"${fqdn}" = {
|
||||
# grant "tuxcord.net" zonesub ANY;
|
||||
extraConfig = ''
|
||||
update-policy {
|
||||
${builtins.concatStringsSep "\n" (
|
||||
map (key: "grant \"${key.name}\" ${key.type key.name} ANY;") keys
|
||||
)}
|
||||
};
|
||||
'';
|
||||
file = "/var/dns/${fqdn}.zone"; # need to put default stuff
|
||||
master = true;
|
||||
};
|
||||
domain = mkOption {
|
||||
type = with lib.types; str;
|
||||
default = config.networking.fqdn;
|
||||
};
|
||||
};
|
||||
|
||||
environment.persistence."/persist" = {
|
||||
directories = [
|
||||
config = mkIf cfg.enable {
|
||||
age.secrets = builtins.listToAttrs (
|
||||
map (
|
||||
filename:
|
||||
let
|
||||
path = "${agenixDnsDir}/${filename}";
|
||||
in
|
||||
{
|
||||
name = "dns/${filename}";
|
||||
value = {
|
||||
file = path;
|
||||
group = "named";
|
||||
owner = "named";
|
||||
};
|
||||
}
|
||||
) agenixKeys
|
||||
);
|
||||
|
||||
services.bind = {
|
||||
enable = true;
|
||||
|
||||
extraConfig = builtins.concatStringsSep "\n" (map (key: "include \"${key.path}\";") keys);
|
||||
|
||||
zones = {
|
||||
"${config.dns.domain}" = {
|
||||
# grant "tuxcord.net" zonesub ANY;
|
||||
extraConfig = ''
|
||||
update-policy {
|
||||
${builtins.concatStringsSep "\n" (
|
||||
map (key: "grant \"${key.name}\" ${key.type key.name} ANY;") keys
|
||||
)}
|
||||
};
|
||||
'';
|
||||
file = "/var/dns/${config.dns.domain}.zone"; # need to put default stuff
|
||||
master = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
environment.persistence."/persist".directories = [
|
||||
{
|
||||
directory = "/var/dns";
|
||||
group = "named";
|
||||
user = "named";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
networking.firewall =
|
||||
let
|
||||
ports = [ config.services.bind.listenOnPort ];
|
||||
in
|
||||
{
|
||||
allowedTCPPorts = ports;
|
||||
allowedUDPPorts = ports;
|
||||
};
|
||||
networking.firewall =
|
||||
let
|
||||
ports = [ config.services.bind.listenOnPort ];
|
||||
in
|
||||
{
|
||||
allowedTCPPorts = ports;
|
||||
allowedUDPPorts = ports;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user