nixpkgs/nixos/modules/services/misc/errbot.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
2.9 KiB
Nix
Raw Normal View History

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;
};
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 = {};
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;
description = lib.mdDoc "Data directory for errbot instance.";
2016-10-11 13:17:44 +00:00
};
plugins = mkOption {
type = types.listOf types.package;
default = [];
description = lib.mdDoc "List of errbot plugin derivations.";
2016-10-11 13:17:44 +00:00
};
logLevel = mkOption {
type = types.str;
default = "INFO";
description = lib.mdDoc "Errbot log level";
2016-10-11 13:17:44 +00:00
};
admins = mkOption {
type = types.listOf types.str;
default = [];
description = lib.mdDoc "List of identifiers of errbot admins.";
2016-10-11 13:17:44 +00:00
};
backend = mkOption {
type = types.str;
default = "XMPP";
description = lib.mdDoc "Errbot backend name.";
2016-10-11 13:17:44 +00:00
};
identity = mkOption {
type = types.attrs;
description = lib.mdDoc "Errbot identity configuration";
2016-10-11 13:17:44 +00:00
};
extraConfig = mkOption {
type = types.lines;
default = "";
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;
};
users.groups.errbot = {};
2016-10-11 13:17:44 +00:00
systemd.services = mapAttrs' (name: instanceCfg: nameValuePair "errbot-${name}" (
let
dataDir = if instanceCfg.dataDir != null then instanceCfg.dataDir else
2016-10-11 13:17:44 +00:00
"/var/lib/errbot/${name}";
in {
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";
ExecStart = "${pkgs.errbot}/bin/errbot -c ${mkConfigDir instanceCfg dataDir}/config.py";
2016-10-11 13:17:44 +00:00
PermissionsStartOnly = true;
};
})) cfg.instances;
};
}