Skip to content

Commit 6e1f2cd

Browse files
committed
Package Mox as a service
1 parent 430a558 commit 6e1f2cd

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

projects/Mox/example.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ ... }:
22
{
33
services.mox.enable = true;
4-
services.mox.hostname = "mail";
5-
services.mox.user = "admin@example.ke";
4+
services.mox.hostname = "localhost";
5+
services.mox.user = "admin@localhost";
66
}

projects/Mox/module.nix

+10-7
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,28 @@
4646
};
4747

4848
systemd.services.mox-setup = {
49-
description = "Setup Mox Mail Server";
49+
description = "Setup Mox Mail Server Configuration Files";
5050
wantedBy = [ "multi-user.target" ];
51+
requires = [ "network-online.target" ];
52+
after = [ "network-online.target" ];
5153
before = [ "mox.service" ];
5254
serviceConfig = {
5355
Type = "oneshot";
5456
RemainAfterExit = true;
57+
User = "mox";
58+
Group = "mox";
5559
};
5660
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+
mkdir -p /var/lib/mox
62+
cd /var/lib/mox
63+
${pkgs.mox}/bin/mox quickstart -hostname ${config.services.mox.hostname} ${config.services.mox.user}
6164
'';
6265
};
6366

6467
systemd.services.mox = {
6568
wantedBy = [ "multi-user.target" ];
66-
after = [ "network.target" "mox-setup.service" ];
67-
requires = [ "mox-setup.service" ]; # This ensures mox-setup must succeed
69+
after = [ "mox-setup.service" ];
70+
requires = [ "mox-setup.service" ];
6871
serviceConfig = {
6972
WorkingDirectory = "/var/lib/mox";
7073
ExecStart = "${pkgs.mox}/bin/mox -config /var/lib/mox/config/mox.conf serve";

projects/Mox/test.nix

+6-12
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,16 @@
99
nodes = {
1010
machine =
1111
{ ... }:
12-
{
12+
rec {
1313
imports = [
1414
sources.modules.ngipkgs
15-
# Sources module path depends on your folder structure
16-
./module.nix
15+
sources.modules.services.mox
16+
sources.examples.Mox.mox
1717
];
1818

19-
# Configure the mox service
20-
services.mox = {
21-
enable = true;
22-
hostname = "mail.example.com";
23-
24-
};
25-
2619
# Allow necessary ports through the firewall
27-
networking.firewall.allowedTCPPorts = [ 25 143 587 993 ];
20+
networking.firewall.allowedTCPPorts = [ 25 80 143 443 587 993 ];
21+
networking.firewall.allowedUDPPorts = [ 53 ];
2822
};
2923
};
3024

@@ -37,7 +31,7 @@
3731
machine.wait_for_unit("multi-user.target")
3832
3933
# Verify the mox-setup service has run successfully
40-
# machine.wait_for_unit("mox-setup.service")
34+
machine.wait_for_unit("mox-setup.service")
4135
4236
# Verify the mox service is running
4337
machine.wait_for_unit("mox.service")

0 commit comments

Comments
 (0)