2015-12-26 04:55:13 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2015-08-31 12:22:21 +00:00
|
|
|
|
2016-10-20 18:54:38 +00:00
|
|
|
with import <stockholm/lib>;
|
2015-08-31 12:22:21 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.krebs.Reaktor;
|
2017-07-28 21:06:40 +00:00
|
|
|
homedir = "/var/lib/Reaktor";
|
2017-01-21 20:55:59 +00:00
|
|
|
|
2015-08-31 12:22:21 +00:00
|
|
|
out = {
|
|
|
|
options.krebs.Reaktor = api;
|
2018-12-03 16:39:34 +00:00
|
|
|
config = mkIf (cfg != {}) imp;
|
2015-08-31 12:22:21 +00:00
|
|
|
};
|
|
|
|
|
2017-01-21 20:55:59 +00:00
|
|
|
api = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = with types; attrsOf (submodule ({ options = {
|
2015-08-31 12:22:21 +00:00
|
|
|
|
2017-01-21 20:55:59 +00:00
|
|
|
nickname = mkOption {
|
|
|
|
default = config.krebs.build.host.name + "|r";
|
|
|
|
type = types.string;
|
|
|
|
description = ''
|
|
|
|
The nick name of the irc bot.
|
|
|
|
Defaults to {hostname}|r
|
|
|
|
'';
|
|
|
|
};
|
2015-08-31 12:22:21 +00:00
|
|
|
|
2017-01-21 20:55:59 +00:00
|
|
|
overrideConfig = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = ''
|
|
|
|
configuration to be used instead of default ones.
|
|
|
|
Reaktor default cfg can be retrieved via `reaktor get-config`
|
|
|
|
'';
|
|
|
|
};
|
2015-12-26 09:44:56 +00:00
|
|
|
|
2017-01-21 20:55:59 +00:00
|
|
|
plugins = mkOption {
|
|
|
|
default = [pkgs.ReaktorPlugins.nixos-version];
|
|
|
|
};
|
|
|
|
|
2017-07-28 21:06:40 +00:00
|
|
|
workdir = mkOption {
|
|
|
|
default = "/var/lib/Reaktor";
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
path to be used as workdir (home dir is still /var/lib/Reaktor)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-21 20:55:59 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.string;
|
|
|
|
description = ''
|
|
|
|
configuration appended to the default or overridden configuration
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraEnviron = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description = ''
|
|
|
|
Environment to be provided to the service, can be:
|
|
|
|
REAKTOR_HOST
|
|
|
|
REAKTOR_PORT
|
|
|
|
REAKTOR_STATEDIR
|
|
|
|
|
|
|
|
debug and nickname can be set separately via the Reaktor api
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
channels = mkOption {
|
|
|
|
default = [ "#krebs" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
Channels the Reaktor should connect to at startup.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
debug = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Reaktor debug output
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};}));
|
2015-08-31 12:22:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
imp = {
|
2017-01-21 20:55:59 +00:00
|
|
|
# TODO get user per configured bot
|
|
|
|
# TODO get home from api
|
2015-08-31 12:22:21 +00:00
|
|
|
# for reaktor get-config
|
2015-12-26 04:55:13 +00:00
|
|
|
users.extraUsers = singleton rec {
|
2015-08-31 12:22:21 +00:00
|
|
|
name = "Reaktor";
|
2015-12-26 04:55:13 +00:00
|
|
|
uid = genid name;
|
2015-08-31 12:22:21 +00:00
|
|
|
description = "Reaktor user";
|
2017-07-28 21:06:40 +00:00
|
|
|
home = homedir;
|
2015-08-31 12:22:21 +00:00
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
#users.extraGroups = singleton {
|
|
|
|
# name = "Reaktor";
|
|
|
|
# gid = config.ids.gids.Reaktor;
|
|
|
|
#};
|
|
|
|
|
2017-01-21 20:55:59 +00:00
|
|
|
systemd.services = mapAttrs' (name: botcfg:
|
|
|
|
let
|
|
|
|
ReaktorConfig = pkgs.writeText "config.py" ''
|
|
|
|
${if (isString botcfg.overrideConfig ) then ''
|
|
|
|
# Overriden Config
|
|
|
|
${botcfg.overrideConfig}
|
|
|
|
'' else ""}
|
|
|
|
## Extra Config
|
|
|
|
${concatStringsSep "\n" (map (plug: plug.config) botcfg.plugins)}
|
|
|
|
${botcfg.extraConfig}
|
2015-08-31 17:55:38 +00:00
|
|
|
'';
|
2017-01-21 20:55:59 +00:00
|
|
|
in nameValuePair "Reaktor-${name}" {
|
|
|
|
path = with pkgs; [
|
|
|
|
git # for nag
|
2019-01-27 19:15:40 +00:00
|
|
|
jq # for tell
|
2017-01-21 20:55:59 +00:00
|
|
|
python # for caps
|
2019-01-27 19:15:40 +00:00
|
|
|
utillinux # flock for tell
|
|
|
|
];
|
2017-01-21 20:55:59 +00:00
|
|
|
description = "Reaktor IRC Bot";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = {
|
|
|
|
GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
2018-09-18 16:55:14 +00:00
|
|
|
PYTHONPATH = "${pkgs.Reaktor}/lib/python3.6/site-packages";
|
2017-01-21 20:55:59 +00:00
|
|
|
REAKTOR_NICKNAME = botcfg.nickname;
|
|
|
|
REAKTOR_DEBUG = (if botcfg.debug then "True" else "False");
|
|
|
|
REAKTOR_CHANNELS = lib.concatStringsSep "," botcfg.channels;
|
2017-07-28 21:06:40 +00:00
|
|
|
state_dir = botcfg.workdir;
|
2017-01-21 20:55:59 +00:00
|
|
|
|
|
|
|
} // botcfg.extraEnviron;
|
|
|
|
serviceConfig= {
|
|
|
|
ExecStartPre = pkgs.writeScript "Reaktor-init" ''
|
|
|
|
#! /bin/sh
|
|
|
|
${if (isString botcfg.overrideConfig) then
|
|
|
|
''cp ${ReaktorConfig} /tmp/reaktor-${name}-config.py''
|
|
|
|
else
|
|
|
|
''(${pkgs.Reaktor}/bin/reaktor get-config;cat "${ReaktorConfig}" ) > /tmp/reaktor-${name}-config.py''
|
|
|
|
}
|
2017-07-28 21:06:40 +00:00
|
|
|
mkdir -p ${botcfg.workdir}
|
2017-01-21 20:55:59 +00:00
|
|
|
'';
|
|
|
|
ExecStart = "${pkgs.Reaktor}/bin/reaktor run /tmp/reaktor-${name}-config.py";
|
|
|
|
PrivateTmp = "true";
|
|
|
|
User = "Reaktor";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec= "30" ;
|
2015-08-31 12:22:21 +00:00
|
|
|
};
|
2017-01-21 20:55:59 +00:00
|
|
|
}
|
|
|
|
) cfg;
|
|
|
|
|
2015-08-31 12:22:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
out
|