2016-10-11 13:17:44 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.errbot;
|
|
|
|
pluginEnv = plugins: pkgs.buildEnv {
|
|
|
|
name = "errbot-plugins";
|
|
|
|
paths = plugins;
|
|
|
|
};
|
2016-11-08 16:43:33 +00:00
|
|
|
mkConfigDir = instanceCfg: dataDir: pkgs.writeTextDir "config.py" ''
|
2016-10-11 13:17:44 +00:00
|
|
|
import logging
|
|
|
|
BACKEND = '${instanceCfg.backend}'
|
|
|
|
BOT_DATA_DIR = '${dataDir}'
|
|
|
|
BOT_EXTRA_PLUGIN_DIR = '${pluginEnv instanceCfg.plugins}'
|
|
|
|
|
|
|
|
BOT_LOG_LEVEL = logging.${instanceCfg.logLevel}
|
|
|
|
BOT_LOG_FILE = False
|
|
|
|
|
|
|
|
BOT_ADMINS = (${concatMapStringsSep "," (name: "'${name}'") instanceCfg.admins})
|
|
|
|
|
|
|
|
BOT_IDENTITY = ${builtins.toJSON instanceCfg.identity}
|
|
|
|
|
|
|
|
${instanceCfg.extraConfig}
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.errbot.instances = mkOption {
|
|
|
|
default = {};
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Errbot instance configs";
|
2016-10-11 13:17:44 +00:00
|
|
|
type = types.attrsOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Data directory for errbot instance.";
|
2016-10-11 13:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "List of errbot plugin derivations.";
|
2016-10-11 13:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "INFO";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Errbot log level";
|
2016-10-11 13:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
admins = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "List of identifiers of errbot admins.";
|
2016-10-11 13:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
backend = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "XMPP";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Errbot backend name.";
|
2016-10-11 13:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
identity = mkOption {
|
|
|
|
type = types.attrs;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Errbot identity configuration";
|
2016-10-11 13:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "String to be appended to the config verbatim";
|
2016-10-11 13:17:44 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.instances != {}) {
|
2019-10-12 20:25:28 +00:00
|
|
|
users.users.errbot = {
|
|
|
|
group = "errbot";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups.errbot = {};
|
2016-10-11 13:17:44 +00:00
|
|
|
|
|
|
|
systemd.services = mapAttrs' (name: instanceCfg: nameValuePair "errbot-${name}" (
|
|
|
|
let
|
2019-04-24 03:48:22 +00:00
|
|
|
dataDir = if instanceCfg.dataDir != null then instanceCfg.dataDir else
|
2016-10-11 13:17:44 +00:00
|
|
|
"/var/lib/errbot/${name}";
|
|
|
|
in {
|
2017-05-16 16:56:16 +00:00
|
|
|
after = [ "network-online.target" ];
|
2016-10-11 13:17:44 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${dataDir}
|
|
|
|
chown -R errbot:errbot ${dataDir}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = "errbot";
|
|
|
|
Restart = "on-failure";
|
2016-11-08 16:43:33 +00:00
|
|
|
ExecStart = "${pkgs.errbot}/bin/errbot -c ${mkConfigDir instanceCfg dataDir}/config.py";
|
2016-10-11 13:17:44 +00:00
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
})) cfg.instances;
|
|
|
|
};
|
|
|
|
}
|