nix-config/hosts/bind/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.1 KiB
Nix
Raw Normal View History

2023-03-09 21:47:10 +01:00
{ zentralwerk, config, pkgs, ... }:
2021-10-15 02:07:50 +02:00
let
2022-11-16 02:15:04 +01:00
# wrap reload in freeze/thaw so that zones are reloaded that had
# been updated by dyndns
2023-03-23 01:31:24 +01:00
reloadCommand = with pkgs; writeScriptBin "reload-bind" ''
#!${runtimeShell}
2022-11-16 02:15:04 +01:00
rndc() {
${bind}/sbin/rndc -k /etc/bind/rndc.key $@
}
rndc freeze
rndc reload
rndc thaw
'';
2021-10-15 02:07:50 +02:00
in
{
c3d2 = {
hq.statistics.enable = true;
deployment.server = "server10";
2021-10-15 02:07:50 +02:00
};
system.stateVersion = "22.05";
networking = {
hostName = "bind";
firewall = {
allowedTCPPorts = [
2022-12-18 23:47:42 +01:00
# DNS
53
];
allowedUDPPorts = [
2022-12-18 23:47:42 +01:00
# DNS
53
];
};
};
2021-10-15 02:07:50 +02:00
2021-10-18 04:04:40 +02:00
# DNS server
2021-10-15 02:07:50 +02:00
services.bind = {
enable = true;
extraConfig = ''
include "${config.users.users.c3d2-dns.home}/c3d2-dns/zones.conf";
include "${zentralwerk.packages.${pkgs.system}.dns-slaves}";
2021-10-16 01:51:27 +02:00
# for collectd
statistics-channels {
inet 127.0.0.1 port 8053;
};
2021-10-15 02:07:50 +02:00
'';
};
2023-03-23 01:31:24 +01:00
systemd.services.bind.serviceConfig = {
Restart = "always";
RestartSec = "5s";
2021-10-18 04:04:40 +02:00
};
# BIND statistics in Grafana
2021-10-16 01:51:27 +02:00
services.collectd.plugins.bind = ''
URL "http://127.0.0.1:8053/";
ParseTime false
OpCodes true
QTypes true
ServerStats true
ZoneMaintStats true
ResolverStats false
MemoryStats true
'';
2021-10-15 02:07:50 +02:00
# Build user
users.groups.c3d2-dns = {};
users.users.c3d2-dns = {
isSystemUser = true;
group = "c3d2-dns";
home = "/var/lib/c3d2-dns";
2023-03-23 01:31:24 +01:00
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHIkIN1gi5cX2wV2WuNph/QzVK7vvYkvqnR/P69s36mZ drone@c3d2"
];
packages = [ reloadCommand ];
2021-10-15 02:07:50 +02:00
};
systemd.tmpfiles.rules = [
"d ${config.users.users.c3d2-dns.home} 0755 c3d2-dns ${config.users.users.c3d2-dns.group} - -"
2021-10-16 01:51:39 +02:00
"d /var/lib/bind/slave 0755 named nogroup - -"
2021-10-15 02:07:50 +02:00
];
2023-03-23 01:31:24 +01:00
# Privileged commands triggered by deploy-c3d2-dns
2021-10-15 02:07:50 +02:00
security.sudo.extraRules = [ {
users = [ "c3d2-dns" ];
commands = [ {
2023-03-23 01:31:24 +01:00
command = "${reloadCommand}/bin/reload-bind";
2021-10-15 02:07:50 +02:00
options = [ "NOPASSWD" ];
} ];
} ];
}