File tree 4 files changed +180
-0
lines changed
4 files changed +180
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ lib ,
3
+ pkgs ,
4
+ sources ,
5
+ } @args :
6
+ {
7
+ metadata = {
8
+ summary = ''
9
+ Mox is a modern, secure, and open-source email server that implements all modern email protocols.
10
+ It makes it easy for people and organizations to run their own email server in minutes using mox quickstart.
11
+ '' ;
12
+ subgrants = [
13
+ "Mox"
14
+ ] ;
15
+ } ;
16
+
17
+ # Mox Service
18
+ nixos . modules . services = {
19
+ mox = {
20
+ name = "mox" ;
21
+ module = ./module.nix ;
22
+ examples . mox = {
23
+ module = ./example.nix ;
24
+ description = "" ;
25
+ tests . basic = import ./test.nix args ;
26
+ } ;
27
+ links = {
28
+ install = {
29
+ text = "Mox Install Documentation" ;
30
+ url = "https://www.xmox.nl/install/" ;
31
+ } ;
32
+ repository = {
33
+ text = "Mox Github Repository" ;
34
+ url = "https://github.com/mjl-/mox" ;
35
+ } ;
36
+ } ;
37
+ } ;
38
+ } ;
39
+ }
Original file line number Diff line number Diff line change
1
+ { ... } :
2
+ {
3
+ services . mox . enable = true ;
4
+ services . mox . hostname = "mail" ;
5
+ services . mox . user = "[email protected] " ;
6
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ config ,
3
+ lib ,
4
+ pkgs ,
5
+ ...
6
+ } :
7
+
8
+ {
9
+ options = {
10
+ services . mox = {
11
+ enable = lib . mkEnableOption "Enable Mox Mail Server" ;
12
+ configFile = lib . mkOption {
13
+ type = lib . types . str ;
14
+ default = "/var/lib/mox/config/mox.conf" ;
15
+ description = "Path to the Mox configuration file" ;
16
+ } ;
17
+ hostname = lib . mkOption {
18
+ type = lib . types . str ;
19
+ default = "mail" ;
20
+ description = "Hostname for the Mox Mail Server" ;
21
+ } ;
22
+ user = lib . mkOption {
23
+ type = lib . types . str ;
24
+ description = "*Required* Email user as (user@domain) to be created." ;
25
+ } ;
26
+ } ;
27
+ } ;
28
+
29
+ config = lib . mkIf config . services . mox . enable {
30
+ # Ensure neccesary packages are installed
31
+ environment . systemPackages = with pkgs ; [
32
+ mox
33
+ ] ;
34
+
35
+ # Create a dedicated user/group for Mox
36
+ users . users . mox = {
37
+ isSystemUser = true ;
38
+ name = "mox" ;
39
+ group = "mox" ;
40
+ home = "/var/lib/mox" ;
41
+ createHome = true ;
42
+ description = "Mox Mail Server User" ;
43
+ } ;
44
+ users . groups . mox = {
45
+ name = "mox" ;
46
+ } ;
47
+
48
+ systemd . services . mox-setup = {
49
+ description = "Setup Mox Mail Server" ;
50
+ wantedBy = [ "multi-user.target" ] ;
51
+ before = [ "mox.service" ] ;
52
+ serviceConfig = {
53
+ Type = "oneshot" ;
54
+ RemainAfterExit = true ;
55
+ } ;
56
+ script = ''
57
+ mkdir -p /var/lib/mox
58
+ cd /var/lib/mox
59
+ ${ pkgs . mox } /bin/mox quickstart -hostname ${ config . services . mox . hostname } ${ config . services . mox . user }
60
+ chown -R mox:mox /var/lib/mox
61
+ '' ;
62
+ } ;
63
+
64
+ systemd . services . mox = {
65
+ wantedBy = [ "multi-user.target" ] ;
66
+ after = [ "network.target" "mox-setup.service" ] ;
67
+ requires = [ "mox-setup.service" ] ; # This ensures mox-setup must succeed
68
+ serviceConfig = {
69
+ WorkingDirectory = "/var/lib/mox" ;
70
+ ExecStart = "${ pkgs . mox } /bin/mox -config /var/lib/mox/config/mox.conf serve" ;
71
+ Restart = "always" ;
72
+ } ;
73
+ } ;
74
+ } ;
75
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ sources ,
3
+ pkgs ,
4
+ ...
5
+ } :
6
+ {
7
+ name = "mox" ;
8
+
9
+ nodes = {
10
+ machine =
11
+ { ... } :
12
+ {
13
+ imports = [
14
+ sources . modules . ngipkgs
15
+ # Sources module path depends on your folder structure
16
+ ./module.nix
17
+ ] ;
18
+
19
+ # Configure the mox service
20
+ services . mox = {
21
+ enable = true ;
22
+ hostname = "mail.example.com" ;
23
+
24
+ } ;
25
+
26
+ # Allow necessary ports through the firewall
27
+ networking . firewall . allowedTCPPorts = [ 25 143 587 993 ] ;
28
+ } ;
29
+ } ;
30
+
31
+ testScript =
32
+ { nodes , ... } :
33
+ ''
34
+ start_all()
35
+
36
+ # Wait for machine to be available
37
+ machine.wait_for_unit("multi-user.target")
38
+
39
+ # Verify the mox-setup service has run successfully
40
+ # machine.wait_for_unit("mox-setup.service")
41
+
42
+ # Verify the mox service is running
43
+ machine.wait_for_unit("mox.service")
44
+
45
+ # Verify config file exists
46
+ machine.succeed("test -f /var/lib/mox/config/mox.conf")
47
+
48
+ # Verify mox user was created
49
+ machine.succeed("getent passwd mox")
50
+
51
+ # Check if ports are listening (assuming default SMTP port)
52
+ machine.wait_until_succeeds("ss -tln | grep ':25 '")
53
+
54
+ # Test running the mox command
55
+ machine.succeed("mox version")
56
+
57
+ # Check logs for any errors
58
+ machine.succeed("journalctl -u mox.service --no-pager | grep -v 'error|failed'")
59
+ '' ;
60
+ }
You can’t perform that action at this time.
0 commit comments