2015-12-26 04:55:13 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2015-08-31 12:22:21 +00:00
|
|
|
|
2015-12-26 04:55:13 +00:00
|
|
|
with lib;
|
2015-08-31 12:22:21 +00:00
|
|
|
let
|
|
|
|
|
2015-08-31 17:55:38 +00:00
|
|
|
ReaktorConfig = pkgs.writeText "config.py" ''
|
|
|
|
${if (isString cfg.overrideConfig ) then ''
|
|
|
|
# Overriden Config
|
|
|
|
${cfg.overrideConfig}
|
|
|
|
'' else ""}
|
|
|
|
## Extra Config
|
2015-12-26 10:41:41 +00:00
|
|
|
${concatStringsSep "\n" (map (plug: plug.config) cfg.plugins)}
|
2015-08-31 17:55:38 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2015-08-31 12:22:21 +00:00
|
|
|
cfg = config.krebs.Reaktor;
|
|
|
|
|
|
|
|
out = {
|
|
|
|
options.krebs.Reaktor = api;
|
|
|
|
config = mkIf cfg.enable imp;
|
|
|
|
};
|
|
|
|
|
|
|
|
api = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Start Reaktor at system boot
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nickname = mkOption {
|
|
|
|
default = config.krebs.build.host.name + "|r";
|
2015-09-04 20:56:06 +00:00
|
|
|
type = types.string;
|
2015-08-31 12:22:21 +00:00
|
|
|
description = ''
|
|
|
|
The nick name of the irc bot.
|
|
|
|
Defaults to {hostname}|r
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-08-31 17:55:38 +00:00
|
|
|
overrideConfig = mkOption {
|
2015-08-31 12:22:21 +00:00
|
|
|
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 10:41:41 +00:00
|
|
|
plugins = mkOption {
|
|
|
|
default = [pkgs.ReaktorPlugins.nixos-version];
|
|
|
|
};
|
2015-08-31 17:55:38 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
2015-09-04 21:01:41 +00:00
|
|
|
type = types.string;
|
2015-08-31 17:55:38 +00:00
|
|
|
description = ''
|
|
|
|
configuration appended to the default or overridden configuration
|
|
|
|
'';
|
|
|
|
};
|
2015-12-26 09:44:56 +00:00
|
|
|
|
|
|
|
workdir = mkOption {
|
|
|
|
default = "/var/lib/Reaktor";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Reaktor working directory
|
|
|
|
'';
|
|
|
|
};
|
2015-09-27 19:50:40 +00:00
|
|
|
extraEnviron = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.attrsOf types.str;
|
2015-08-31 12:22:21 +00:00
|
|
|
description = ''
|
2015-09-27 19:50:40 +00:00
|
|
|
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
|
2015-08-31 12:22:21 +00:00
|
|
|
'';
|
|
|
|
};
|
2015-12-30 10:29:28 +00:00
|
|
|
channels = mkOption {
|
|
|
|
default = [ "#krebs" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
Channels the Reaktor should connect to at startup.
|
|
|
|
'';
|
|
|
|
};
|
2015-09-04 20:56:06 +00:00
|
|
|
debug = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Reaktor debug output
|
|
|
|
'';
|
|
|
|
};
|
2015-08-31 12:22:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
imp = {
|
|
|
|
# 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";
|
2015-12-26 09:44:56 +00:00
|
|
|
home = cfg.workdir;
|
2015-08-31 12:22:21 +00:00
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
#users.extraGroups = singleton {
|
|
|
|
# name = "Reaktor";
|
|
|
|
# gid = config.ids.gids.Reaktor;
|
|
|
|
#};
|
|
|
|
|
|
|
|
systemd.services.Reaktor = {
|
|
|
|
path = with pkgs; [
|
|
|
|
utillinux #flock for tell_on-join
|
2015-09-27 19:50:40 +00:00
|
|
|
git # for nag
|
2015-08-31 12:22:21 +00:00
|
|
|
python # for caps
|
|
|
|
];
|
|
|
|
description = "Reaktor IRC Bot";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = {
|
|
|
|
GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
2015-08-31 17:55:38 +00:00
|
|
|
REAKTOR_NICKNAME = cfg.nickname;
|
2015-09-04 20:56:06 +00:00
|
|
|
REAKTOR_DEBUG = (if cfg.debug then "True" else "False");
|
2015-12-30 10:29:28 +00:00
|
|
|
REAKTOR_CHANNELS = lib.concatStringsSep "," cfg.channels;
|
2015-12-26 09:44:56 +00:00
|
|
|
state_dir = cfg.workdir;
|
2015-12-30 10:29:28 +00:00
|
|
|
|
2015-09-27 19:50:40 +00:00
|
|
|
} // cfg.extraEnviron;
|
2015-08-31 17:55:38 +00:00
|
|
|
serviceConfig= {
|
|
|
|
ExecStartPre = pkgs.writeScript "Reaktor-init" ''
|
|
|
|
#! /bin/sh
|
|
|
|
${if (isString cfg.overrideConfig) then
|
|
|
|
''cp ${ReaktorConfig} /tmp/config.py''
|
|
|
|
else
|
2015-09-27 19:50:40 +00:00
|
|
|
''(${pkgs.Reaktor}/bin/reaktor get-config;cat "${ReaktorConfig}" ) > /tmp/config.py''
|
2015-08-31 17:55:38 +00:00
|
|
|
}
|
|
|
|
'';
|
2015-09-27 19:50:40 +00:00
|
|
|
ExecStart = "${pkgs.Reaktor}/bin/reaktor run /tmp/config.py";
|
2015-08-31 17:55:38 +00:00
|
|
|
PrivateTmp = "true";
|
|
|
|
User = "Reaktor";
|
2015-10-17 09:17:54 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec= "30" ;
|
2015-08-31 12:22:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
out
|