2015-09-10 17:10:06 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2017-01-18 18:47:29 +00:00
|
|
|
cfgs = config.services;
|
|
|
|
cfg = cfgs.dnschain;
|
2015-09-10 17:10:06 +01:00
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
dataDir = "/var/lib/dnschain";
|
|
|
|
username = "dnschain";
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "dnschain.conf" ''
|
2015-09-10 17:10:06 +01:00
|
|
|
[log]
|
2017-01-18 18:47:29 +00:00
|
|
|
level = info
|
2015-09-10 17:10:06 +01:00
|
|
|
|
|
|
|
[dns]
|
2017-01-18 18:47:29 +00:00
|
|
|
host = ${cfg.dns.address}
|
|
|
|
port = ${toString cfg.dns.port}
|
2015-09-10 17:10:06 +01:00
|
|
|
oldDNSMethod = NO_OLD_DNS
|
2017-06-03 10:59:34 +01:00
|
|
|
externalIP = ${cfg.dns.externalAddress}
|
2015-09-10 17:10:06 +01:00
|
|
|
|
|
|
|
[http]
|
2017-01-18 18:47:29 +00:00
|
|
|
host = ${cfg.api.hostname}
|
|
|
|
port = ${toString cfg.api.port}
|
|
|
|
tlsPort = ${toString cfg.api.tlsPort}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
2015-09-10 17:10:06 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.dnschain = {
|
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
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 {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2015-09-10 17:10:06 +01:00
|
|
|
description = ''
|
2017-06-03 10:59:34 +01:00
|
|
|
The IP address the DNSChain resolver will bind to.
|
|
|
|
Leave this unchanged if you do not wish to directly expose the resolver.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dns.externalAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.dns.address;
|
|
|
|
description = ''
|
|
|
|
The IP address used by clients to reach the resolver and the value of
|
|
|
|
the <literal>namecoin.dns</literal> record. Set this in case the bind address
|
|
|
|
is not the actual IP address (e.g. the machine is behind a NAT).
|
2015-09-10 17:10:06 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
dns.port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5333;
|
|
|
|
description = ''
|
|
|
|
The port the DNSChain resolver will bind to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
api.hostname = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
description = ''
|
|
|
|
The hostname (or IP address) the DNSChain API server will bind to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
api.port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8080;
|
|
|
|
description = ''
|
|
|
|
The port the DNSChain API server (HTTP) will bind to.
|
|
|
|
'';
|
|
|
|
};
|
2015-09-10 17:10:06 +01:00
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
api.tlsPort = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 4433;
|
2015-09-10 17:10:06 +01:00
|
|
|
description = ''
|
2017-01-18 18:47:29 +00:00
|
|
|
The port the DNSChain API server (HTTPS) will bind to.
|
2015-09-10 17:10:06 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
[log]
|
|
|
|
level = debug
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Additional options that will be appended to the configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
services.dnsmasq.resolveDNSChainQueries = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Resolve <literal>.bit</literal> top-level domains using DNSChain and namecoin.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.pdns-recursor.resolveDNSChainQueries = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Resolve <literal>.bit</literal> top-level domains using DNSChain and namecoin.
|
|
|
|
'';
|
2015-09-10 17:10:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
config = mkIf cfg.enable {
|
2015-09-10 17:10:06 +01:00
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
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}"
|
|
|
|
];
|
2015-09-10 17:10:06 +01:00
|
|
|
|
2017-01-18 18:47:29 +00:00
|
|
|
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}";
|
2015-09-10 17:10:06 +01:00
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users = singleton {
|
2017-01-18 18:47:29 +00:00
|
|
|
name = username;
|
|
|
|
description = "DNSChain daemon user";
|
|
|
|
home = dataDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.dnschain;
|
|
|
|
extraGroups = optional cfgs.namecoind.enable "namecoin";
|
|
|
|
};
|
|
|
|
|
2015-09-10 17:10:06 +01:00
|
|
|
systemd.services.dnschain = {
|
2017-01-18 18:47:29 +00:00
|
|
|
description = "DNSChain daemon";
|
|
|
|
after = optional cfgs.namecoind.enable "namecoind.target";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "dnschain";
|
|
|
|
Restart = "on-failure";
|
2017-10-31 21:03:38 +00:00
|
|
|
ExecStart = "${pkgs.nodePackages.dnschain}/bin/dnschain";
|
2017-01-18 18:47:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
# Link configuration file into dnschain home directory
|
|
|
|
configPath=${dataDir}/.dnschain/dnschain.conf
|
|
|
|
mkdir -p ${dataDir}/.dnschain
|
|
|
|
if [ "$(realpath $configPath)" != "${configFile}" ]; then
|
|
|
|
rm -f $configPath
|
|
|
|
ln -s ${configFile} $configPath
|
|
|
|
fi
|
|
|
|
'';
|
2015-09-10 17:10:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|