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

with lib;

let

  cfg = config.services.prosody;

  sslOpts = { ... }: {

    options = {

      # TODO: require attribute
      key = mkOption {
        type = types.str;
        description = "Path to the key file";
      };

      # TODO: require attribute
      cert = mkOption {
        type = types.str;
        description = "Path to the certificate file";
      };
    };
  };

  moduleOpts = {

    roster = mkOption {
      default = true;
      description = "Allow users to have a roster";
    };

    saslauth = mkOption {
      default = true;
      description = "Authentication for clients and servers. Recommended if you want to log in.";
    };

    tls = mkOption {
      default = true;
      description = "Add support for secure TLS on c2s/s2s connections";
    };

    dialback = mkOption {
      default = true;
      description = "s2s dialback support";
    };

    disco = mkOption {
      default = true;
      description = "Service discovery";
    };

    legacyauth = mkOption {
      default = true;
      description = "Legacy authentication. Only used by some old clients and bots";
    };

    version = mkOption {
      default = true;
      description = "Replies to server version requests";
    };

    uptime = mkOption {
      default = true;
      description = "Report how long server has been running";
    };

    time = mkOption {
      default = true;
      description = "Let others know the time here on this server";
    };

    ping = mkOption {
      default = true;
      description = "Replies to XMPP pings with pongs";
    };

    console = mkOption {
      default = false;
      description = "telnet to port 5582";
    };

    bosh = mkOption {
      default = false;
      description = "Enable BOSH clients, aka 'Jabber over HTTP'";
    };

    httpserver = mkOption {
      default = false;
      description = "Serve static files from a directory over HTTP";
    };

    websocket = mkOption {
      default = false;
      description = "Enable WebSocket support";
    };

  };

  createSSLOptsStr = o:
    if o ? key && o ? cert then
      ''ssl = { key = "${o.key}"; certificate = "${o.cert}"; };''
    else "";

  vHostOpts = { ... }: {

    options = {

      # TODO: require attribute
      domain = mkOption {
        type = types.str;
        description = "Domain name";
      };

      enabled = mkOption {
        default = false;
        description = "Whether to enable the virtual host";
      };

      ssl = mkOption {
        description = "Paths to SSL files";
        default = null;
        options = [ sslOpts ];
      };

      extraConfig = mkOption {
        default = '''';
        description = "Additional virtual host specific configuration";
      };

    };

  };

in

{

  ###### interface

  options = {

    services.prosody = {

      enable = mkOption {
        default = false;
        description = "Whether to enable the prosody server";
      };

      allowRegistration = mkOption {
        default = false;
        description = "Allow account creation";
      };

      modules = moduleOpts;

      extraModules = mkOption {
        description = "Enable custom modules";
        default = [];
      };

      virtualHosts = mkOption {

        description = "Define the virtual hosts";

        type = with types; loaOf (submodule vHostOpts);

        example = {
          myhost = {
            domain = "my-xmpp-example-host.org";
            enabled = true;
          };
        };

        default = {
          localhost = {
            domain = "localhost";
            enabled = true;
          };
        };

      };

      ssl = mkOption {
        description = "Paths to SSL files";
        default = null;
        options = [ sslOpts ];
      };

      admins = mkOption {
        description = "List of administrators of the current host";
        example = [ "<EMAIL>" "<EMAIL>" ];
        default = [];
      };

      extraConfig = mkOption {
        type = types.lines;
        default = '''';
        description = "Additional prosody configuration";
      };

    };
  };


  ###### implementation
<commit_msg>prosody service: add types<commit_after>{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.prosody;

  sslOpts = { ... }: {

    options = {

      # TODO: require attribute
      key = mkOption {
        type = types.path;
        description = "Path to the key file";
      };

      # TODO: require attribute
      cert = mkOption {
        type = types.path;
        description = "Path to the certificate file";
      };
    };
  };

  moduleOpts = {

    roster = mkOption {
      type = types.bool;
      default = true;
      description = "Allow users to have a roster";
    };

    saslauth = mkOption {
      type = types.bool;
      default = true;
      description = "Authentication for clients and servers. Recommended if you want to log in.";
    };

    tls = mkOption {
      type = types.bool;
      default = true;
      description = "Add support for secure TLS on c2s/s2s connections";
    };

    dialback = mkOption {
      type = types.bool;
      default = true;
      description = "s2s dialback support";
    };

    disco = mkOption {
      type = types.bool;
      default = true;
      description = "Service discovery";
    };

    legacyauth = mkOption {
      type = types.bool;
      default = true;
      description = "Legacy authentication. Only used by some old clients and bots";
    };

    version = mkOption {
      type = types.bool;
      default = true;
      description = "Replies to server version requests";
    };

    uptime = mkOption {
      type = types.bool;
      default = true;
      description = "Report how long server has been running";
    };

    time = mkOption {
      type = types.bool;
      default = true;
      description = "Let others know the time here on this server";
    };

    ping = mkOption {
      type = types.bool;
      default = true;
      description = "Replies to XMPP pings with pongs";
    };

    console = mkOption {
      type = types.bool;
      default = false;
      description = "telnet to port 5582";
    };

    bosh = mkOption {
      type = types.bool;
      default = false;
      description = "Enable BOSH clients, aka 'Jabber over HTTP'";
    };

    httpserver = mkOption {
      type = types.bool;
      default = false;
      description = "Serve static files from a directory over HTTP";
    };

    websocket = mkOption {
      type = types.bool;
      default = false;
      description = "Enable WebSocket support";
    };

  };

  createSSLOptsStr = o:
    if o ? key && o ? cert then
      ''ssl = { key = "${o.key}"; certificate = "${o.cert}"; };''
    else "";

  vHostOpts = { ... }: {

    options = {

      # TODO: require attribute
      domain = mkOption {
        type = types.str;
        description = "Domain name";
      };

      enabled = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable the virtual host";
      };

      ssl = mkOption {
        type = types.nullOr (types.submodule sslOpts);
        default = null;
        description = "Paths to SSL files";
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        description = "Additional virtual host specific configuration";
      };

    };

  };

in

{

  ###### interface

  options = {

    services.prosody = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable the prosody server";
      };

      allowRegistration = mkOption {
        type = types.bool;
        default = false;
        description = "Allow account creation";
      };

      modules = moduleOpts;

      extraModules = mkOption {
        type = types.listOf types.str;
        default = [];
        description = "Enable custom modules";
      };

      virtualHosts = mkOption {

        description = "Define the virtual hosts";

        type = with types; loaOf (submodule vHostOpts);

        example = {
          myhost = {
            domain = "my-xmpp-example-host.org";
            enabled = true;
          };
        };

        default = {
          localhost = {
            domain = "localhost";
            enabled = true;
          };
        };

      };

      ssl = mkOption {
        type = types.nullOr (types.submodule sslOpts);
        default = null;
        description = "Paths to SSL files";
      };

      admins = mkOption {
        type = types.listOf types.str;
        default = [];
        example = [ "<EMAIL>" "<EMAIL>" ];
        description = "List of administrators of the current host";
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        description = "Additional prosody configuration";
      };

    };
  };


  ###### implementation

{'fraction_non_alphanumeric': 0.11023006477551932, 'fraction_numerical': 0.0015635470180924726, 'mean_word_length': 1.7435661764705883, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '4883068', 'n_tokens_mistral': 2565, 'n_tokens_neox': 2446, 'n_words': 743}