about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2019-03-27 16:11:15 +0100
committerGitHub <noreply@github.com>2019-03-27 16:11:15 +0100
commit3fc3096da84d07386d45edc9b0a7af023b0d053c (patch)
tree0d64c0f0f847130a0b95f333b3a3ac3aa439836d
parent7abf9be865ecad20345766556d604ee0eed734ae (diff)
parentc99ea1c2039b57c20bf058184ee77d06f4d78d10 (diff)
downloadnixlib-3fc3096da84d07386d45edc9b0a7af023b0d053c.tar
nixlib-3fc3096da84d07386d45edc9b0a7af023b0d053c.tar.gz
nixlib-3fc3096da84d07386d45edc9b0a7af023b0d053c.tar.bz2
nixlib-3fc3096da84d07386d45edc9b0a7af023b0d053c.tar.lz
nixlib-3fc3096da84d07386d45edc9b0a7af023b0d053c.tar.xz
nixlib-3fc3096da84d07386d45edc9b0a7af023b0d053c.tar.zst
nixlib-3fc3096da84d07386d45edc9b0a7af023b0d053c.zip
Merge pull request #58432 from aanderse/mailcatcher
nixos/mailcatcher: init module for existing package
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/mail/mailcatcher.nix60
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/mailcatcher.nix26
4 files changed, 88 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index dc571602581b..fad7f336c995 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -349,6 +349,7 @@
   ./services/mail/exim.nix
   ./services/mail/freepops.nix
   ./services/mail/mail.nix
+  ./services/mail/mailcatcher.nix
   ./services/mail/mailhog.nix
   ./services/mail/mlmmj.nix
   ./services/mail/offlineimap.nix
diff --git a/nixos/modules/services/mail/mailcatcher.nix b/nixos/modules/services/mail/mailcatcher.nix
new file mode 100644
index 000000000000..2c6aadadce9d
--- /dev/null
+++ b/nixos/modules/services/mail/mailcatcher.nix
@@ -0,0 +1,60 @@
+{ config, pkgs, lib, ... }:
+
+let
+  cfg = config.services.mailcatcher;
+
+  inherit (lib) mkEnableOption mkIf mkOption types;
+in
+{
+  # interface
+
+  options = {
+
+    services.mailcatcher = {
+      enable = mkEnableOption "Enable MailCatcher.";
+
+      http.ip = mkOption {
+        type = types.str;
+        default = "127.0.0.1";
+        description = "The ip address of the http server.";
+      };
+
+      http.port = mkOption {
+        type = types.port;
+        default = 1080;
+        description = "The port address of the http server.";
+      };
+
+      smtp.ip = mkOption {
+        type = types.str;
+        default = "127.0.0.1";
+        description = "The ip address of the smtp server.";
+      };
+
+      smtp.port = mkOption {
+        type = types.port;
+        default = 1025;
+        description = "The port address of the smtp server.";
+      };
+    };
+
+  };
+
+  # implementation
+
+  config = mkIf cfg.enable {
+    environment.systemPackages = [ pkgs.mailcatcher ];
+
+    systemd.services.mailcatcher = {
+      description = "MailCatcher Service";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+
+      serviceConfig = {
+        DynamicUser = true;
+        Restart = "always";
+        ExecStart = "${pkgs.mailcatcher}/bin/mailcatcher --foreground --no-quit --http-ip ${cfg.http.ip} --http-port ${toString cfg.http.port} --smtp-ip ${cfg.smtp.ip} --smtp-port ${toString cfg.smtp.port}";
+      };
+    };
+  };
+}
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index a5acf78a8839..49bbe24fdc0e 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -131,6 +131,7 @@ in
   #lightdm = handleTest ./lightdm.nix {};
   login = handleTest ./login.nix {};
   #logstash = handleTest ./logstash.nix {};
+  mailcatcher = handleTest ./mailcatcher.nix {};
   mathics = handleTest ./mathics.nix {};
   matrix-synapse = handleTest ./matrix-synapse.nix {};
   memcached = handleTest ./memcached.nix {};
diff --git a/nixos/tests/mailcatcher.nix b/nixos/tests/mailcatcher.nix
new file mode 100644
index 000000000000..1bed13b23f66
--- /dev/null
+++ b/nixos/tests/mailcatcher.nix
@@ -0,0 +1,26 @@
+import ./make-test.nix ({ lib, ... }:
+
+{
+  name = "mailcatcher";
+  meta.maintainers = [ lib.maintainers.aanderse ];
+
+  machine =
+    { pkgs, ... }:
+    {
+      services.mailcatcher.enable = true;
+
+      networking.defaultMailServer.directDelivery = true;
+      networking.defaultMailServer.hostName = "localhost:1025";
+
+      environment.systemPackages = [ pkgs.mailutils ];
+    };
+
+  testScript = ''
+    startAll;
+
+    $machine->waitForUnit('mailcatcher.service');
+    $machine->waitForOpenPort('1025');
+    $machine->succeed('echo "this is the body of the email" | mail -s "subject" root@example.org');
+    $machine->succeed('curl http://localhost:1080/messages/1.json') =~ /this is the body of the email/ or die;
+  '';
+})