1 { config, lib, pkgs, ... }:
3 cfg = config.services.errbot;
4 pluginEnv = plugins: pkgs.buildEnv {
5 name = "errbot-plugins";
8 mkConfigDir = instanceCfg: dataDir: pkgs.writeTextDir "config.py" ''
10 BACKEND = '${instanceCfg.backend}'
11 BOT_DATA_DIR = '${dataDir}'
12 BOT_EXTRA_PLUGIN_DIR = '${pluginEnv instanceCfg.plugins}'
14 BOT_LOG_LEVEL = logging.${instanceCfg.logLevel}
17 BOT_ADMINS = (${lib.concatMapStringsSep "," (name: "'${name}'") instanceCfg.admins})
19 BOT_IDENTITY = ${builtins.toJSON instanceCfg.identity}
21 ${instanceCfg.extraConfig}
25 services.errbot.instances = lib.mkOption {
27 description = "Errbot instance configs";
28 type = lib.types.attrsOf (lib.types.submodule {
30 dataDir = lib.mkOption {
31 type = lib.types.nullOr lib.types.path;
33 description = "Data directory for errbot instance.";
36 plugins = lib.mkOption {
37 type = lib.types.listOf lib.types.package;
39 description = "List of errbot plugin derivations.";
42 logLevel = lib.mkOption {
45 description = "Errbot log level";
48 admins = lib.mkOption {
49 type = lib.types.listOf lib.types.str;
51 description = "List of identifiers of errbot admins.";
54 backend = lib.mkOption {
57 description = "Errbot backend name.";
60 identity = lib.mkOption {
61 type = lib.types.attrs;
62 description = "Errbot identity configuration";
65 extraConfig = lib.mkOption {
66 type = lib.types.lines;
68 description = "String to be appended to the config verbatim";
75 config = lib.mkIf (cfg.instances != {}) {
76 users.users.errbot = {
80 users.groups.errbot = {};
82 systemd.services = lib.mapAttrs' (name: instanceCfg: lib.nameValuePair "errbot-${name}" (
84 dataDir = if instanceCfg.dataDir != null then instanceCfg.dataDir else
85 "/var/lib/errbot/${name}";
87 after = [ "network-online.target" ];
88 wantedBy = [ "multi-user.target" ];
91 chown -R errbot:errbot ${dataDir}
95 Restart = "on-failure";
96 ExecStart = "${pkgs.errbot}/bin/errbot -c ${mkConfigDir instanceCfg dataDir}/config.py";
97 PermissionsStartOnly = true;