2021-07-24 22:38:42 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.acme-dns;
|
2021-07-24 22:58:13 +02:00
|
|
|
tomlFormat = pkgs.formats.toml {};
|
2021-07-24 22:38:42 +02:00
|
|
|
configFile = tomlFormat.generate "acme-dns.cfg" cfg.settings;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.acme-dns = {
|
2021-07-24 23:09:12 +02:00
|
|
|
enable = mkEnableOption "ACME DNS server";
|
2021-07-24 22:38:42 +02:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.rz.acme-dns;
|
|
|
|
defaultText = "pkgs.rz.acme-dns";
|
|
|
|
};
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/acme-dns";
|
|
|
|
};
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
nsname = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
nsadmin = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
records = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
api.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8090;
|
|
|
|
};
|
|
|
|
api.listen = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
};
|
|
|
|
dns.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 53;
|
|
|
|
};
|
|
|
|
dns.listen = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
};
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {
|
|
|
|
general = {
|
|
|
|
listen = "${cfg.dns.listen}:${toString cfg.dns.port}";
|
|
|
|
protocol = "both";
|
|
|
|
domain = cfg.domain;
|
|
|
|
nsname = cfg.nsname;
|
|
|
|
nsadmin = cfg.nsadmin;
|
|
|
|
records = cfg.records;
|
|
|
|
debug = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
database = {
|
2021-07-24 23:28:42 +02:00
|
|
|
engine = "sqlite3";
|
2021-07-24 22:38:42 +02:00
|
|
|
connection = "${cfg.stateDir}/acme-dns.db";
|
|
|
|
};
|
|
|
|
|
|
|
|
api = {
|
2021-07-24 22:42:05 +02:00
|
|
|
ip = cfg.api.listen;
|
2021-07-24 22:38:42 +02:00
|
|
|
disable_registration = false;
|
2021-07-24 23:27:15 +02:00
|
|
|
port = toString cfg.api.port;
|
2021-07-24 22:38:42 +02:00
|
|
|
tls = "none";
|
2021-07-24 23:05:26 +02:00
|
|
|
notification_email = config.security.acme.email;
|
2021-07-24 22:38:42 +02:00
|
|
|
corsorigins = [ "*" ];
|
|
|
|
use_header = false;
|
|
|
|
header_name = "X-Forwarded-For";
|
|
|
|
};
|
|
|
|
|
|
|
|
logconfig = {
|
|
|
|
loglevel = "debug";
|
|
|
|
logtype = "stdout";
|
|
|
|
logformat = "text";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-07-24 23:09:12 +02:00
|
|
|
config = mkIf cfg.enable {
|
2021-07-24 22:38:42 +02:00
|
|
|
systemd.services.acme-dns = {
|
|
|
|
description = "ACME-DNS name server for ACME DNS challenges";
|
|
|
|
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
startLimitBurst = 4;
|
|
|
|
startLimitIntervalSec = 5 * 60; # 5 mins
|
|
|
|
serviceConfig = {
|
|
|
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
|
|
|
DynamicUser = true;
|
2021-07-24 23:22:41 +02:00
|
|
|
StateDirectory = "acme-dns";
|
2021-07-24 23:24:58 +02:00
|
|
|
ExecStart = "${cfg.package}/bin/acme-dns -c ${configFile}";
|
2021-07-24 22:38:42 +02:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "4s";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|