Skip to content

Commit 077a483

Browse files
committed
Package Mox as a service
1 parent 828d4ad commit 077a483

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

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-5
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@
99
nodes = {
1010
machine =
1111
{ ... }:
12-
{
12+
rec {
1313
imports = [
1414
sources.modules.ngipkgs
1515
# Sources module path depends on your folder structure
1616
./module.nix
1717
];
1818

19+
# Allow necessary ports through the firewall
20+
networking.firewall.allowedTCPPorts = [ 25 80 143 443 587 993 ];
21+
networking.firewall.allowedUDPPorts = [ 53 ];
22+
1923
# Configure the mox service
2024
services.mox = {
2125
enable = true;
2226
hostname = "mail.example.com";
2327
2428
};
25-
26-
# Allow necessary ports through the firewall
27-
networking.firewall.allowedTCPPorts = [ 25 143 587 993 ];
2829
};
2930
};
3031

@@ -37,7 +38,7 @@
3738
machine.wait_for_unit("multi-user.target")
3839
3940
# Verify the mox-setup service has run successfully
40-
# machine.wait_for_unit("mox-setup.service")
41+
machine.wait_for_unit("mox-setup.service")
4142
4243
# Verify the mox service is running
4344
machine.wait_for_unit("mox.service")

0 commit comments

Comments
 (0)