1import ./make-test-python.nix {
2 name = "postfix";
3
4 machine = { pkgs, ... }: {
5 imports = [ common/user-account.nix ];
6 services.postfix = {
7 enable = true;
8 enableSubmissions = true;
9 submissionsOptions = {
10 smtpd_tls_security_level = "none";
11 };
12 };
13
14 environment.systemPackages = let
15 checkConfig = pkgs.writeScriptBin "check-config" ''
16 #!${pkgs.python3.interpreter}
17 import sys
18
19 state = 1
20 success = False
21
22 with open("/etc/postfix/master.cf") as masterCf:
23 for line in masterCf:
24 if state == 1 and line.startswith("submissions"):
25 state = 2
26 elif state == 2 and line.startswith(" ") and "smtpd_tls_security_level=encrypt" in line:
27 success = True
28 elif state == 2 and not line.startswith(" "):
29 state == 3
30 if not success:
31 sys.exit(1)
32 '';
33
34 in [ checkConfig ];
35 };
36
37 testScript = ''
38 machine.wait_for_unit("postfix.service")
39 machine.succeed("check-config")
40 '';
41}