<commit_before>{ config, lib, pkgs, ... }:

with lib;

let
  cfgs = config.services;
  cfg  = cfgs.dnschain;

  dataDir  = "/var/lib/dnschain";
  username = "dnschain";

  configFile = pkgs.writeText "dnschain.conf" ''
    [log]
    level = info

    [dns]
    host = ${cfg.dns.address}
    port = ${toString cfg.dns.port}
    oldDNSMethod = NO_OLD_DNS
    externalIP = ${cfg.dns.address}

    [http]
    host = ${cfg.api.hostname}
    port = ${toString cfg.api.port}
    tlsPort = ${toString cfg.api.tlsPort}

    ${cfg.extraConfig}
  '';

in

{

  ###### interface

  options = {

    services.dnschain = {

      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";
        description = ''
          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.
        '';
      };

      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.
        '';
      };

      api.tlsPort = mkOption {<commit_msg>dnschain: allow different bind and external addresses<commit_after>{ config, lib, pkgs, ... }:

with lib;

let
  cfgs = config.services;
  cfg  = cfgs.dnschain;

  dataDir  = "/var/lib/dnschain";
  username = "dnschain";

  configFile = pkgs.writeText "dnschain.conf" ''
    [log]
    level = info

    [dns]
    host = ${cfg.dns.address}
    port = ${toString cfg.dns.port}
    oldDNSMethod = NO_OLD_DNS
    externalIP = ${cfg.dns.externalAddress}

    [http]
    host = ${cfg.api.hostname}
    port = ${toString cfg.api.port}
    tlsPort = ${toString cfg.api.tlsPort}

    ${cfg.extraConfig}
  '';

in

{

  ###### interface

  options = {

    services.dnschain = {

      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";
        description = ''
          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).
        '';
      };

      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.
        '';
      };

      api.tlsPort = mkOption {
{'fraction_non_alphanumeric': 0.11320274739252098, 'fraction_numerical': 0.009157975069956754, 'mean_word_length': 1.8492753623188405, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6193750', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1198, 'n_words': 347}