nix-config/hosts/bind/default.nix

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

121 lines
2.6 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 $@
}
chmod a+rwx /var/lib/c3d2-dns/zones
2022-11-16 02:15:04 +01:00
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
};
2023-11-08 21:14:58 +01:00
environment = {
etc.gitconfig.text = ''
[url "gitea@gitea.c3d2.de:"]
insteadOf = https://gitea.c3d2.de/
'';
systemPackages = with pkgs; [
rsync # used in drone CI
];
};
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
2023-03-23 21:36:53 +01:00
# Privileged commands triggered by deploy-c3d2-dns
security.sudo.extraRules = [ {
users = [ "c3d2-dns" ];
commands = [ {
2023-12-16 18:07:37 +01:00
command = "/etc/profiles/per-user/c3d2-dns/bin/reload-bind";
2023-03-23 21:36:53 +01:00
options = [ "NOPASSWD" ];
} ];
} ];
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}/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
'';
};
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
sops = {
defaultSopsFile = ./secrets.yaml;
secrets = {
"ssh-keys/c3d2-dns/private" = {
owner = "c3d2-dns";
path = "/var/lib/c3d2-dns/.ssh/id_ed25519";
};
"ssh-keys/c3d2-dns/public" = {
owner = "c3d2-dns";
path = "/var/lib/c3d2-dns/.ssh/id_ed25519.pub";
};
};
};
2023-03-23 21:36:53 +01:00
system.stateVersion = "22.05";
systemd.services.bind.serviceConfig = {
Restart = "always";
RestartSec = "5s";
};
systemd.tmpfiles.rules = [
"d ${config.users.users.c3d2-dns.home} 0755 c3d2-dns ${config.users.users.c3d2-dns.group} - -"
"d /var/lib/bind/slave 0755 named nogroup - -"
];
2021-10-15 02:07:50 +02:00
# Build user
users.groups.c3d2-dns = {};
users.users.c3d2-dns = {
2023-03-23 01:39:41 +01:00
isNormalUser = true;
2021-10-15 02:07:50 +02:00
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
};
}