···
+
cfgs = config.services;
+
dataDir = "/var/lib/dnschain";
+
configFile = pkgs.writeText "dnschain.conf" ''
+
host = ${cfg.dns.address}
+
port = ${toString cfg.dns.port}
oldDNSMethod = NO_OLD_DNS
+
externalIP = ${cfg.dns.address}
+
host = ${cfg.api.hostname}
+
port = ${toString cfg.api.port}
+
tlsPort = ${toString cfg.api.tlsPort}
···
+
enable = mkEnableOption ''
+
DNSChain, a blockchain based DNS + HTTP server.
+
To resolve .bit domains set <literal>services.namecoind.enable = true;</literal>
+
and an RPC username/password.
+
dns.address = mkOption {
+
The IP address that will be used to reach this machine.
+
Leave this unchanged if you do not wish to directly expose the DNSChain resolver.
+
The port the DNSChain resolver will bind to.
+
api.hostname = mkOption {
+
The hostname (or IP address) the DNSChain API server will bind to.
+
The port the DNSChain API server (HTTP) will bind to.
+
api.tlsPort = mkOption {
+
The port the DNSChain API server (HTTPS) will bind to.
+
extraConfig = mkOption {
+
Additional options that will be appended to the configuration file.
+
services.dnsmasq.resolveDNSChainQueries = mkOption {
+
Resolve <literal>.bit</literal> top-level domains using DNSChain and namecoin.
+
services.pdns-recursor.resolveDNSChainQueries = mkOption {
+
Resolve <literal>.bit</literal> top-level domains using DNSChain and namecoin.
+
config = mkIf cfg.enable {
+
services.dnsmasq.servers = optionals cfgs.dnsmasq.resolveDNSChainQueries
+
[ "/.bit/127.0.0.1#${toString cfg.dns.port}"
+
"/.dns/127.0.0.1#${toString cfg.dns.port}"
+
services.pdns-recursor.forwardZones = mkIf cfgs.pdns-recursor.resolveDNSChainQueries
+
{ bit = "127.0.0.1:${toString cfg.dns.port}";
+
dns = "127.0.0.1:${toString cfg.dns.port}";
+
users.extraUsers = singleton {
+
description = "DNSChain daemon user";
+
uid = config.ids.uids.dnschain;
+
extraGroups = optional cfgs.namecoind.enable "namecoin";
systemd.services.dnschain = {
+
description = "DNSChain daemon";
+
after = optional cfgs.namecoind.enable "namecoind.target";
+
wantedBy = [ "multi-user.target" ];
+
Restart = "on-failure";
+
ExecStart = "${pkgs.dnschain}/bin/dnschain";
+
# Link configuration file into dnschain home directory
+
configPath=${dataDir}/.dnschain/dnschain.conf
+
mkdir -p ${dataDir}/.dnschain
+
if [ "$(realpath $configPath)" != "${configFile}" ]; then
+
ln -s ${configFile} $configPath