From 3e581053f4a1ccf22154f46bb04acea3fe1b29ab Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 31 Aug 2015 19:55:38 +0200 Subject: add extraConfig and overrideConfig this allows of preserving the original config while adding bonus features --- krebs/3modules/Reaktor.nix | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'krebs/3modules') diff --git a/krebs/3modules/Reaktor.nix b/krebs/3modules/Reaktor.nix index 2ca7a0ee3..407f1bce7 100644 --- a/krebs/3modules/Reaktor.nix +++ b/krebs/3modules/Reaktor.nix @@ -12,9 +12,17 @@ let isString optionalString 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; out = { @@ -40,7 +48,7 @@ let }; - extraConfig = mkOption { + overrideConfig = mkOption { default = null; type = types.nullOr types.str; description = '' @@ -48,6 +56,13 @@ let 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 { default = kpkgs.Reaktor; @@ -60,7 +75,6 @@ let imp = { # for reaktor get-config environment.systemPackages = [ cfg.ReaktorPkg ]; - users.extraUsers = singleton { name = "Reaktor"; # uid = config.ids.uids.Reaktor; @@ -84,12 +98,26 @@ let description = "Reaktor IRC Bot"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; - serviceConfig.User = "Reaktor"; environment = { 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 ""}"; }; }; -- cgit v1.2.3