2016-10-11 14:17:44 +01: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 14:17:44 +01: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 = {};
|
|
|
|
description = "Errbot instance configs";
|
|
|
|
type = types.attrsOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = "Data directory for errbot instance.";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
|
|
|
description = "List of errbot plugin derivations.";
|
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "INFO";
|
|
|
|
description = "Errbot log level";
|
|
|
|
};
|
|
|
|
|
|
|
|
admins = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "List of identifiers of errbot admins.";
|
|
|
|
};
|
|
|
|
|
|
|
|
backend = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "XMPP";
|
|
|
|
description = "Errbot backend name.";
|
|
|
|
};
|
|
|
|
|
|
|
|
identity = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
description = "Errbot identity configuration";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "String to be appended to the config verbatim";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.instances != {}) {
|
2019-10-12 21:25:28 +01:00
|
|
|
users.users.errbot = {
|
|
|
|
group = "errbot";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.errbot = {};
|
2016-10-11 14:17:44 +01:00
|
|
|
|
|
|
|
systemd.services = mapAttrs' (name: instanceCfg: nameValuePair "errbot-${name}" (
|
|
|
|
let
|
2019-04-24 04:48:22 +01:00
|
|
|
dataDir = if instanceCfg.dataDir != null then instanceCfg.dataDir else
|
2016-10-11 14:17:44 +01:00
|
|
|
"/var/lib/errbot/${name}";
|
|
|
|
in {
|
2017-05-16 17:56:16 +01:00
|
|
|
after = [ "network-online.target" ];
|
2016-10-11 14:17:44 +01: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 14:17:44 +01:00
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
})) cfg.instances;
|
|
|
|
};
|
|
|
|
}
|