summaryrefslogtreecommitdiffstats
path: root/nixos/tests/nullmailer.nix
blob: 19e941226429d0d24fb307e8b2eeb46a18ad9177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ lib, ... }:
{
  name = "nullmailer";

  meta = {
    maintainers = with lib.maintainers; [ h7x4 ];
  };

  nodes = {
    mail =
      { config, ... }:
      {
        imports = [ ./common/user-account.nix ];

        virtualisation.vlans = [ 1 ];

        networking = {
          useNetworkd = true;
          useDHCP = false;
          firewall.allowedTCPPorts = [ 25 ];
          domain = "example.com";
          hosts."10.0.0.2" = [ "machine.example.com" ];
        };

        systemd.network.networks."01-eth1" = {
          name = "eth1";
          networkConfig.Address = "10.0.0.1/24";
        };

        services.postfix = {
          enable = true;

          localRecipients = [ "alice" ];

          settings = {
            main = {
              myhostname = config.networking.hostName;
              mydomain = config.networking.domain;
              mynetworks = [ "0.0.0.0/0" ];
              mydestination = [ "$mydomain" ];

              smtpd_recipient_restrictions = "permit_mynetworks, reject";
            };
          };
        };
      };

    machine =
      { config, ... }:
      {
        virtualisation.vlans = [ 1 ];

        networking = {
          useNetworkd = true;
          useDHCP = false;
          domain = "example.com";
          hosts."10.0.0.1" = [ "mail.example.com" ];
        };

        systemd.network.networks."01-eth1" = {
          name = "eth1";
          networkConfig.Address = "10.0.0.2/24";
        };

        services.nullmailer = {
          enable = true;
          config = {
            me = "${config.networking.fqdn}";
            remotes = "mail.example.com smtp --port=25";
          };
        };
      };
  };

  testScript = ''
    start_all()

    machine.wait_for_open_port(25, "mail.example.com")
    machine.wait_for_unit("nullmailer.service")
    machine.succeed('printf "To: alice@example.com\r\n\r\nthis is the body of the email" | sendmail -t -i -f sender@example.com')

    mail.wait_for_console_text("delivered to maildir")
    print(mail.succeed("grep 'this is the body of the email' /var/spool/mail/alice/new/*"))
  '';
}