From c962e8549e968fd15d4f15b4d184e86e1cd7ed04 Mon Sep 17 00:00:00 2001
From: makefu <github@syntax-fehler.de>
Date: Wed, 30 Dec 2015 11:29:28 +0100
Subject: [PATCH 1/5] k 3 Reaktor: add channels Option

---
 krebs/3modules/Reaktor.nix | 11 +++++++++--
 makefu/1systems/wry.nix    | 21 ++++++++++++++++-----
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/krebs/3modules/Reaktor.nix b/krebs/3modules/Reaktor.nix
index 607eb7cac..92400139c 100644
--- a/krebs/3modules/Reaktor.nix
+++ b/krebs/3modules/Reaktor.nix
@@ -70,12 +70,17 @@ let
           REAKTOR_HOST
           REAKTOR_PORT
           REAKTOR_STATEDIR
-          REAKTOR_CHANNELS
 
           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 = ''
@@ -112,7 +117,9 @@ let
         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;
+
         } // cfg.extraEnviron;
       serviceConfig= {
         ExecStartPre = pkgs.writeScript "Reaktor-init" ''
diff --git a/makefu/1systems/wry.nix b/makefu/1systems/wry.nix
index cd2b3f657..3bdf053db 100644
--- a/makefu/1systems/wry.nix
+++ b/makefu/1systems/wry.nix
@@ -18,8 +18,6 @@ in {
 
       ../2configs/iodined.nix
 
-      # Reaktor
-      ../2configs/Reaktor/simpleExtend.nix
 
       # other nginx
       ../2configs/nginx/euer.wiki.nix
@@ -29,9 +27,22 @@ in {
       # collectd
       ../2configs/collectd/collectd-base.nix
   ];
+
   krebs.build.host = config.krebs.hosts.wry;
 
-  krebs.Reaktor.enable = true;
+  krebs.Reaktor = {
+    nickname = "Reaktor|bot";
+    channels = [ "#krebs_test" ];
+    enable = true;
+    debug = true;
+    plugins = with pkgs.ReaktorPlugins;[
+                               titlebot
+                               # stockholm-issue
+                               nixos-version
+                               shack-correct
+                               sed-plugin
+                               random-emoji ];
+  };
 
   # bepasty to listen only on the correct interfaces
   krebs.bepasty.servers.internal.nginx.listen  = [ "${internal-ip}:80" ];
@@ -59,11 +70,11 @@ in {
   };
 
   networking = {
-  firewall = {
+    firewall = {
       allowPing = true;
       logRefusedConnections = false;
       allowedTCPPorts = [ 53 80 443 ];
-      allowedUDPPorts = [ 655 ];
+      allowedUDPPorts = [ 655 53 ];
     };
     interfaces.enp2s1.ip4 = [{
       address = external-ip;

From f0ce9a72a6595f521f68a156aa46b2372a391d38 Mon Sep 17 00:00:00 2001
From: makefu <github@syntax-fehler.de>
Date: Wed, 30 Dec 2015 11:52:22 +0100
Subject: [PATCH 2/5] k 5 Reaktor.plugins: fix sed-plugin

---
 krebs/5pkgs/Reaktor/plugins.nix | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/krebs/5pkgs/Reaktor/plugins.nix b/krebs/5pkgs/Reaktor/plugins.nix
index 5c7b89f5c..7490be4ca 100644
--- a/krebs/5pkgs/Reaktor/plugins.nix
+++ b/krebs/5pkgs/Reaktor/plugins.nix
@@ -14,6 +14,7 @@ rec {
   buildSimpleReaktorPlugin = name: { script
                         , path ? []
                         , env ? {}
+                        , append_rule ? false # append the rule instead of insert
                         , pattern ? ""
                         , ... } @ attrs:
     let
@@ -26,7 +27,7 @@ rec {
       });
       src_file = "${src_dir}/bin/${name}";
       config = ''
-        public_commands.insert(0,{
+        public_commands.${if append_rule then "append(" else "insert(0," }{
           'capname' : "${name}",
           'pattern' : ${if pattern == "" then
                           ''indirect_pattern.format("${name}")'' else
@@ -58,9 +59,10 @@ rec {
   };
 
   sed-plugin = buildSimpleReaktorPlugin "sed-plugin" {
-    path = [ pkgs.gnused ];
+    path = [ pkgs.gnused pkgs.python3 ];
     # only support s///gi the plugin needs to see every msg
     # TODO: this will eat up the last regex, fix Reaktor to support fallthru
+    append_rule = true;
     pattern = "^(?P<args>.*)$$";
     script = ./scripts/sed-plugin.py;
   };
@@ -105,7 +107,7 @@ rec {
     config = ''
       def titlebot_cmd(cmd):
         from os import environ
-        return {  'capname': cmd,
+        return {  'capname': None,
                   'env': { 'TITLEDB':
                     environ['state_dir']+'/suggestions.json' },
                   'pattern': '^\\.' + cmd + '\\s*(?:\\s+(?P<args>.*))?$$',

From f7894c29dbfb8404aeb9f4d387942fd638434a22 Mon Sep 17 00:00:00 2001
From: makefu <github@syntax-fehler.de>
Date: Wed, 30 Dec 2015 11:53:48 +0100
Subject: [PATCH 3/5] m 1 wry: update Reaktor config

---
 makefu/1systems/wry.nix | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/makefu/1systems/wry.nix b/makefu/1systems/wry.nix
index 3bdf053db..f022311c9 100644
--- a/makefu/1systems/wry.nix
+++ b/makefu/1systems/wry.nix
@@ -32,9 +32,8 @@ in {
 
   krebs.Reaktor = {
     nickname = "Reaktor|bot";
-    channels = [ "#krebs_test" ];
+    channels = [ "#krebs" "#shackspace" "#binaergewitter" ];
     enable = true;
-    debug = true;
     plugins = with pkgs.ReaktorPlugins;[
                                titlebot
                                # stockholm-issue

From ca9e1700ef0deac0b71d4c3e2a6d1ee0a0ccbc42 Mon Sep 17 00:00:00 2001
From: makefu <github@syntax-fehler.de>
Date: Wed, 30 Dec 2015 14:47:40 +0100
Subject: [PATCH 4/5] s 1 minimal-deploy: init test

---
 shared/1systems/test-minimal-deploy.nix | 13 +++++++++++++
 shared/2configs/buildbot-standalone.nix | 11 +++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 shared/1systems/test-minimal-deploy.nix

diff --git a/shared/1systems/test-minimal-deploy.nix b/shared/1systems/test-minimal-deploy.nix
new file mode 100644
index 000000000..ddd96f6b5
--- /dev/null
+++ b/shared/1systems/test-minimal-deploy.nix
@@ -0,0 +1,13 @@
+{ config, pkgs, lib, ... }:
+{
+  krebs = {
+    enable = true;
+    build.user = config.krebs.users.shared;
+    build.host = config.krebs.hosts.test-all-krebs-modules;
+  };
+  # just get the system running
+  boot.loader.grub.devices = ["/dev/sda"];
+  fileSystems."/" = {
+    device = "/dev/lol";
+  };
+}
diff --git a/shared/2configs/buildbot-standalone.nix b/shared/2configs/buildbot-standalone.nix
index c62f8920c..6ffd7fe8a 100644
--- a/shared/2configs/buildbot-standalone.nix
+++ b/shared/2configs/buildbot-standalone.nix
@@ -94,6 +94,17 @@ in {
                             --argstr current-host-name lol \
                             --strict --json"])
 
+  addShell(f,name="instantiate-test-minimal-deploy",env=env,
+            command=nixshell + \
+                      ["nix-instantiate --eval -A \
+                            users.shared.test-minimal-deploy.system \
+                            -I stockholm=. \
+                            -I secrets=. '<stockholm>' \
+                            --argstr current-date lol \
+                            --argstr current-user-name shared \
+                            --argstr current-host-name lol \
+                            --strict --json"])
+
   bu.append(util.BuilderConfig(name="fast-tests",
         slavenames=slavenames,
         factory=f))

From b9c4a5e4a0800dbfb6f4cb1d20bbfd2c1d228d11 Mon Sep 17 00:00:00 2001
From: tv <tv@krebsco.de>
Date: Wed, 30 Dec 2015 14:54:04 +0100
Subject: [PATCH 5/5] exim-retiolum: move assert to proper location

---
 krebs/3modules/exim-retiolum.nix | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/krebs/3modules/exim-retiolum.nix b/krebs/3modules/exim-retiolum.nix
index e1315d8c8..ea012c38c 100644
--- a/krebs/3modules/exim-retiolum.nix
+++ b/krebs/3modules/exim-retiolum.nix
@@ -1,14 +1,12 @@
 { config, pkgs, lib, ... }:
 
-with builtins;
 with lib;
 let
   cfg = config.krebs.exim-retiolum;
 
   out = {
     options.krebs.exim-retiolum = api;
-    config =
-      mkIf cfg.enable imp;
+    config = mkIf cfg.enable imp;
   };
 
   api = {
@@ -16,13 +14,13 @@ let
   };
 
   imp = {
-    services.exim =
-      # This configuration makes only sense for retiolum-enabled hosts.
-      # TODO modular configuration
-      assert config.krebs.retiolum.enable;
-      {
-        enable = true;
-        config = ''
+    services.exim = {
+      enable = true;
+      config =
+        # This configuration makes only sense for retiolum-enabled hosts.
+        # TODO modular configuration
+        assert config.krebs.retiolum.enable;
+        ''
           primary_hostname = ${retiolumHostname}
           domainlist local_domains    = @ : localhost
           domainlist relay_to_domains = *.retiolum
@@ -134,7 +132,7 @@ let
 
           begin authenticators
         '';
-      };
+    };
   };
 
   # TODO get the hostname from somewhere else.