@@ -0,0 +1,110 @@
1+{ config, lib, pkgs, ... }:
6+ cfg = config.services;
8+ dnschainConf = pkgs.writeText "dnschain.conf" ''
15+ oldDNSMethod = NO_OLD_DNS
16+ # TODO: check what that address is acutally used for
17+ externalIP = 127.0.0.1
33+ services.dnschain = {
39+ Whether to run dnschain. That implies running
40+ namecoind as well, so make sure to configure
48+ resolveDnschainQueries = mkOption {
52+ Resolve <literal>.bit</literal> top-level domains
53+ with dnschain and namecoind.
62+ ###### implementation
64+ config = mkIf cfg.dnschain.enable {
66+ services.namecoind.enable = true;
68+ services.dnsmasq.servers = optionals cfg.dnsmasq.resolveDnschainQueries [ "/.bit/127.0.0.1#5333" ];
70+ users.extraUsers = singleton
72+ uid = config.ids.uids.dnschain;
73+ extraGroups = [ "namecoin" ];
74+ description = "Dnschain daemon user";
75+ home = "/var/lib/dnschain";
79+ systemd.services.dnschain = {
80+ description = "Dnschain Daemon";
81+ after = [ "namecoind.target" ];
82+ wantedBy = [ "multi-user.target" ];
83+ path = [ pkgs.openssl ];
85+ # Link configuration file into dnschain HOME directory
86+ if [ "$(${pkgs.coreutils}/bin/realpath /var/lib/dnschain/.dnschain.conf)" != "${dnschainConf}" ]; then
87+ rm -rf /var/lib/dnschain/.dnschain.conf
88+ ln -s ${dnschainConf} /var/lib/dnschain/.dnschain.conf
91+ # Create empty namecoin.conf so that dnschain is not
92+ # searching for /etc/namecoin/namecoin.conf
93+ if [ ! -e /var/lib/dnschain/.namecoin/namecoin.conf ]; then
94+ mkdir -p /var/lib/dnschain/.namecoin
95+ touch /var/lib/dnschain/.namecoin/namecoin.conf
101+ EnvironmentFile = config.services.namecoind.userFile;
102+ ExecStart = "${pkgs.dnschain}/bin/dnschain --rpcuser=\${USER} --rpcpassword=\${PASSWORD} --rpcport=8336";
103+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
104+ ExecStop = "${pkgs.coreutils}/bin/kill -KILL $MAINPID";