add extraConfig and overrideConfig

this allows of preserving the original config while adding bonus features
This commit is contained in:
makefu 2015-08-31 19:55:38 +02:00
parent ba2cb6c3a8
commit 3e581053f4

View File

@ -12,9 +12,17 @@ let
isString isString
optionalString optionalString
concatStrings concatStrings
escapeShellArg
; ;
ReaktorConfig = mkIf ( isString cfg.extraConfig ) pkgs.writeText "config.py" cfg.extraConfig; ReaktorConfig = pkgs.writeText "config.py" ''
${if (isString cfg.overrideConfig ) then ''
# Overriden Config
${cfg.overrideConfig}
'' else ""}
## Extra Config
${cfg.extraConfig}
'';
cfg = config.krebs.Reaktor; cfg = config.krebs.Reaktor;
out = { out = {
@ -40,7 +48,7 @@ let
}; };
extraConfig = mkOption { overrideConfig = mkOption {
default = null; default = null;
type = types.nullOr types.str; type = types.nullOr types.str;
description = '' description = ''
@ -48,6 +56,13 @@ let
Reaktor default cfg can be retrieved via `reaktor get-config` Reaktor default cfg can be retrieved via `reaktor get-config`
''; '';
}; };
extraConfig = mkOption {
default = "";
type = types.str;
description = ''
configuration appended to the default or overridden configuration
'';
};
ReaktorPkg = mkOption { ReaktorPkg = mkOption {
default = kpkgs.Reaktor; default = kpkgs.Reaktor;
@ -60,7 +75,6 @@ let
imp = { imp = {
# for reaktor get-config # for reaktor get-config
environment.systemPackages = [ cfg.ReaktorPkg ]; environment.systemPackages = [ cfg.ReaktorPkg ];
users.extraUsers = singleton { users.extraUsers = singleton {
name = "Reaktor"; name = "Reaktor";
# uid = config.ids.uids.Reaktor; # uid = config.ids.uids.Reaktor;
@ -84,12 +98,26 @@ let
description = "Reaktor IRC Bot"; description = "Reaktor IRC Bot";
after = [ "network.target" ]; after = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig.User = "Reaktor";
environment = { environment = {
GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
IRC_NICKNAME = cfg.nickname; REAKTOR_NICKNAME = cfg.nickname;
};
serviceConfig= {
ExecStartPre = pkgs.writeScript "Reaktor-init" ''
#! /bin/sh
${if (isString cfg.overrideConfig) then
''cp ${ReaktorConfig} /tmp/config.py''
else
''(${cfg.ReaktorPkg}/bin/reaktor get-config;cat "${ReaktorConfig}" ) > /tmp/config.py''
}
'';
ExecStart = "${cfg.ReaktorPkg}/bin/reaktor run /tmp/config.py";
PrivateTmp = "true";
User = "Reaktor";
Restart = "on-abort";
#StartLimitInterval = "5m";
#StartLimitBurst = "1";
}; };
serviceConfig.ExecStart = "${cfg.ReaktorPkg}/bin/reaktor run ${if (isString cfg.extraConfig) then cfg.ReaktorConfig else ""}";
}; };
}; };