anchor.diff:  
     config = mkIf cfg.enable {
   
  -    users.extraUsers = singleton
  -      { name = "namecoin";
  -        uid = config.ids.uids.namecoin;
  -        description = "Namecoin daemon user";
  -        home = "/var/lib/namecoin";
  -        createHome = true;
  -      };
  -
  -    users.extraGroups = singleton
  -      { name = "namecoin";
  -        gid = config.ids.gids.namecoin;
  -      };
  +    services.dnschain.extraConfig = ''
  +      [namecoin]
  +      config = ${configFile}
  +    '';
  +
  +    users.extraUsers = singleton {
  +      name = "namecoin";
  +      uid  = config.ids.uids.namecoin;
  +      description = "Namecoin daemon user";
  +      home = dataDir;
  +      createHome = true;
  +    };
  +
  +    users.extraGroups = singleton {
  +      name = "namecoin";
  +      gid  = config.ids.gids.namecoin;
  +    };
   
       systemd.services.namecoind = {
  -        description = "Namecoind Daemon";
  -        after = [ "network.target" ];
  -        wantedBy = [ "multi-user.target" ];
  -        preStart = ''
  -          if [  "$(stat --printf '%u' ${cfg.userFile})" != "${toString config.ids.uids.namecoin}" \
  -             -o "$(stat --printf '%g' ${cfg.userFile})" != "${toString config.ids.gids.namecoin}" \
  -             -o "$(stat --printf '%a' ${cfg.userFile})" != "640" ]; then
  -             echo "ERROR: bad ownership or rights on ${cfg.userFile}" >&2
  -             exit 1
  -          fi
  -          if [  "$(stat --printf '%u' ${cfg.wallet})" != "${toString config.ids.uids.namecoin}" \
  -             -o "$(stat --printf '%g' ${cfg.wallet})" != "${toString config.ids.gids.namecoin}" \
  -             -o "$(stat --printf '%a' ${cfg.wallet})" != "640" ]; then
  -             echo "ERROR: bad ownership or rights on ${cfg.wallet}" >&2
  -             exit 1
  -          fi
  -        '';
  -        serviceConfig = {
  -          Type = "simple";
  -          User = "namecoin";
  -          EnvironmentFile = cfg.userFile;
  -          ExecStart = "${pkgs.altcoins.namecoind}/bin/namecoind -conf=${namecoinConf} -rpcuser=\${USER} -rpcpassword=\${PASSWORD} -printtoconsole";
  -          ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
  -          ExecStop = "${pkgs.coreutils}/bin/kill -KILL $MAINPID";
  -          StandardOutput = "null";
  -          Nice = "10";
  -        };
  +      description = "Namecoind daemon";
  +      after    = [ "network.target" ];
  +      wantedBy = [ "multi-user.target" ];
  +
  +      serviceConfig = {
  +        User  = "namecoin";
  +        Griup = "namecoin";
  +        ExecStart  = "${pkgs.altcoins.namecoind}/bin/namecoind -conf=${configFile} -datadir=${dataDir} -printtoconsole";
  +        ExecStop   = "${pkgs.coreutils}/bin/kill -KILL $MAINPID";
  +        ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
  +        Nice = "10";
  +        PrivateTmp = true;
  +        TimeoutStopSec     = "60s";
  +        TimeoutStartSec    = "2s";
  +        Restart            = "always";
  +        StartLimitInterval = "120s";
  +        StartLimitBurst    = "5";
  +      };
  +
  +      preStart = optionalString (cfg.wallet != "${dataDir}/wallet.dat")  ''
  +        # check wallet file permissions
  +        if [ "$(stat --printf '%u' ${cfg.wallet})" != "${toString config.ids.uids.namecoin}" \
  +           -o "$(stat --printf '%g' ${cfg.wallet})" != "${toString config.ids.gids.namecoin}" \
  +           -o "$(stat --printf '%a' ${cfg.wallet})" != "640" ]; then
  +           echo "ERROR: bad ownership or rights on ${cfg.wallet}" >&2
  +           exit 1
  +        fi
  +      '';
  +
       };
   
     };
  
positive.code:         '';
        };
  
        rpcCertificate = mkOption {
          type = types.nullOr types.path;
          default = null;
          example = "/etc/namecoin/server.cert";
          description = ''
            Certificate file for securing RPC connections.
          '';
        };
  
        rpcKey = mkOption {
          type = types.nullOr types.path;
          default = null;
          example = "/etc/namecoin/server.pem";
          description = ''
            Key file for securing RPC connections.
          '';
        };
  
      };
  
    };
  
negative.code: with lib;
  
  let
    cfg     = config.services.namecoind;
    dataDir = "/var/lib/namecoind";
    useSSL  = (cfg.rpc.certificate != null) && (cfg.rpc.key != null);
    useRPC  = (cfg.rpc.user != null) && (cfg.rpc.password != null);
  
    listToConf = option: list:
      concatMapStrings (value :"${option}=${value}\n") list;
  
    configFile = pkgs.writeText "namecoin.conf" (''
      server=1
      daemon=0
      txindex=1
      txprevcache=1
      walletpath=${cfg.wallet}
      gen=${if cfg.generate then "1" else "0"}
      ${listToConf "addnode" cfg.extraNodes}
      ${listToConf "connect" cfg.trustedNodes}
    '' + optionalString useRPC ''
      rpcbind=${cfg.rpc.address}
      rpcport=${toString cfg.rpc.port}
      rpcuser=${cfg.rpc.user}
      rpcpassword=${cfg.rpc.password}
      ${listToConf "rpcallowip" cfg.rpc.allowFrom}
    '' + optionalString useSSL ''
      rpcssl=1
      rpcsslcertificatechainfile=${cfg.rpc.certificate}
      rpcsslprivatekeyfile=${cfg.rpc.key}
      rpcsslciphers=TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH
    '');
  
  in
  
  