1 { config, lib, pkgs, ... }:
6 cfg = config.services.errbot;
7 pluginEnv = plugins: pkgs.buildEnv {
8 name = "errbot-plugins";
11 mkConfigDir = instanceCfg: dataDir: pkgs.writeTextDir "config.py" ''
13 BACKEND = '${instanceCfg.backend}'
14 BOT_DATA_DIR = '${dataDir}'
15 BOT_EXTRA_PLUGIN_DIR = '${pluginEnv instanceCfg.plugins}'
17 BOT_LOG_LEVEL = logging.${instanceCfg.logLevel}
20 BOT_ADMINS = (${concatMapStringsSep "," (name: "'${name}'") instanceCfg.admins})
22 BOT_IDENTITY = ${builtins.toJSON instanceCfg.identity}
24 ${instanceCfg.extraConfig}
28 services.errbot.instances = mkOption {
30 description = lib.mdDoc "Errbot instance configs";
31 type = types.attrsOf (types.submodule {
34 type = types.nullOr types.path;
36 description = lib.mdDoc "Data directory for errbot instance.";
40 type = types.listOf types.package;
42 description = lib.mdDoc "List of errbot plugin derivations.";
48 description = lib.mdDoc "Errbot log level";
52 type = types.listOf types.str;
54 description = lib.mdDoc "List of identifiers of errbot admins.";
60 description = lib.mdDoc "Errbot backend name.";
65 description = lib.mdDoc "Errbot identity configuration";
68 extraConfig = mkOption {
71 description = lib.mdDoc "String to be appended to the config verbatim";
78 config = mkIf (cfg.instances != {}) {
79 users.users.errbot = {
83 users.groups.errbot = {};
85 systemd.services = mapAttrs' (name: instanceCfg: nameValuePair "errbot-${name}" (
87 dataDir = if instanceCfg.dataDir != null then instanceCfg.dataDir else
88 "/var/lib/errbot/${name}";
90 after = [ "network-online.target" ];
91 wantedBy = [ "multi-user.target" ];
94 chown -R errbot:errbot ${dataDir}
98 Restart = "on-failure";
99 ExecStart = "${pkgs.errbot}/bin/errbot -c ${mkConfigDir instanceCfg dataDir}/config.py";
100 PermissionsStartOnly = true;