k 3 Reaktor: allow multiple Reaktor configurations

This commit is contained in:
lassulus 2017-01-21 21:55:59 +01:00
parent c7f0bc2800
commit 0ff2496de4

View file

@ -3,29 +3,18 @@
with import <stockholm/lib>;
let
ReaktorConfig = pkgs.writeText "config.py" ''
${if (isString cfg.overrideConfig ) then ''
# Overriden Config
${cfg.overrideConfig}
'' else ""}
## Extra Config
${concatStringsSep "\n" (map (plug: plug.config) cfg.plugins)}
${cfg.extraConfig}
'';
cfg = config.krebs.Reaktor;
workdir = "/var/lib/Reaktor";
out = {
options.krebs.Reaktor = api;
config = lib.mkIf cfg.enable imp;
config = imp;
};
api = {
enable = mkOption {
default = false;
description = ''
Start Reaktor at system boot
'';
};
api = mkOption {
default = {};
type = with types; attrsOf (submodule ({ options = {
nickname = mkOption {
default = config.krebs.build.host.name + "|r";
@ -44,9 +33,11 @@ let
Reaktor default cfg can be retrieved via `reaktor get-config`
'';
};
plugins = mkOption {
default = [pkgs.ReaktorPlugins.nixos-version];
};
extraConfig = mkOption {
default = "";
type = types.string;
@ -55,13 +46,6 @@ let
'';
};
workdir = mkOption {
default = "/var/lib/Reaktor";
type = types.str;
description = ''
Reaktor working directory
'';
};
extraEnviron = mkOption {
default = {};
type = types.attrsOf types.str;
@ -74,6 +58,7 @@ let
debug and nickname can be set separately via the Reaktor api
'';
};
channels = mkOption {
default = [ "#krebs" ];
type = types.listOf types.str;
@ -81,21 +66,25 @@ let
Channels the Reaktor should connect to at startup.
'';
};
debug = mkOption {
default = false;
description = ''
Reaktor debug output
'';
};
};}));
};
imp = {
# TODO get user per configured bot
# TODO get home from api
# for reaktor get-config
users.extraUsers = singleton rec {
name = "Reaktor";
uid = genid name;
description = "Reaktor user";
home = cfg.workdir;
home = workdir;
createHome = true;
};
@ -104,7 +93,18 @@ let
# gid = config.ids.gids.Reaktor;
#};
systemd.services.Reaktor = {
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}
'';
in nameValuePair "Reaktor-${name}" {
path = with pkgs; [
utillinux #flock for tell_on-join
git # for nag
@ -115,28 +115,30 @@ let
wantedBy = [ "multi-user.target" ];
environment = {
GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
REAKTOR_NICKNAME = cfg.nickname;
REAKTOR_DEBUG = (if cfg.debug then "True" else "False");
REAKTOR_CHANNELS = lib.concatStringsSep "," cfg.channels;
state_dir = cfg.workdir;
REAKTOR_NICKNAME = botcfg.nickname;
REAKTOR_DEBUG = (if botcfg.debug then "True" else "False");
REAKTOR_CHANNELS = lib.concatStringsSep "," botcfg.channels;
state_dir = workdir;
} // cfg.extraEnviron;
} // botcfg.extraEnviron;
serviceConfig= {
ExecStartPre = pkgs.writeScript "Reaktor-init" ''
#! /bin/sh
${if (isString cfg.overrideConfig) then
''cp ${ReaktorConfig} /tmp/config.py''
${if (isString botcfg.overrideConfig) then
''cp ${ReaktorConfig} /tmp/reaktor-${name}-config.py''
else
''(${pkgs.Reaktor}/bin/reaktor get-config;cat "${ReaktorConfig}" ) > /tmp/config.py''
''(${pkgs.Reaktor}/bin/reaktor get-config;cat "${ReaktorConfig}" ) > /tmp/reaktor-${name}-config.py''
}
'';
ExecStart = "${pkgs.Reaktor}/bin/reaktor run /tmp/config.py";
ExecStart = "${pkgs.Reaktor}/bin/reaktor run /tmp/reaktor-${name}-config.py";
PrivateTmp = "true";
User = "Reaktor";
Restart = "always";
RestartSec= "30" ;
};
};
}
) cfg;
};
in