Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Mox as a service #677

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

themadbit
Copy link
Contributor

@themadbit themadbit commented Mar 27, 2025

  • Exposed Mox as a service to resolve issue(s).
  • Initial tests are running, and a local rebuild of NixOS with the module included runs just fine.
    i.e:

image

However, it fails to start/survive reboot with:

[themadbit@nixos:~]$ systemctl status mox
○ mox.service
     Loaded: loaded (/etc/systemd/system/mox.service; enabled; preset: ignored)
     Active: inactive (dead)

Mar 27 14:40:30 nixos systemd[1]: Dependency failed for mox.service.
Mar 27 14:40:30 nixos systemd[1]: mox.service: Job mox.service/start failed with result 'dependency'.

So, I'll leave this as a draft PR as I investigate further. Putting it out here in case you've had a similar headache and know the painkiller 😅

@themadbit themadbit changed the title Add Mox Project Package Mox as a service Mar 27, 2025
@themadbit
Copy link
Contributor Author

Update: I've run the test interactively for debugging and got access to the VM. The VM might not have a running nameserver, and I'd like to know if there's a way I can get one running as part of the machine configs before running the test(s). @eljamm, any pointers for further debugging?

ss of log:
image

@eljamm
Copy link
Contributor

eljamm commented Apr 3, 2025

Turns out that it was just a matter of modifying the service order since the dns configuration is not over by the time the mox-setup service tries to start. With the following patch, the setup completes, the server runs and the NixOS Test succeeds:

fix-mox-service-order.patch

---
 projects/Mox/module.nix | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/projects/Mox/module.nix b/projects/Mox/module.nix
index 43bb8d7..91d38d7 100644
--- a/projects/Mox/module.nix
+++ b/projects/Mox/module.nix
@@ -48,23 +48,26 @@
     systemd.services.mox-setup = {
       description = "Setup Mox Mail Server";
       wantedBy = [ "multi-user.target" ];
+      requires = [ "network-online.target" ];
+      after = [ "network-online.target" ];
       before = [ "mox.service" ];
       serviceConfig = {
         Type = "oneshot";
         RemainAfterExit = true;
+        User = "mox";
+        Group = "mox";
       };
       script = ''
         mkdir -p /var/lib/mox
         cd /var/lib/mox
         ${pkgs.mox}/bin/mox quickstart -hostname ${config.services.mox.hostname} ${config.services.mox.user}
-        chown -R mox:mox /var/lib/mox
       '';
     };

     systemd.services.mox = {
       wantedBy = [ "multi-user.target" ];
-      after = [ "network.target" "mox-setup.service" ];
-      requires = [ "mox-setup.service" ]; # This ensures mox-setup must succeed
+      after = [ "mox-setup.service" ];
+      requires = [ "mox-setup.service" ];
       serviceConfig = {
         WorkingDirectory = "/var/lib/mox";
         ExecStart = "${pkgs.mox}/bin/mox -config /var/lib/mox/config/mox.conf serve";
--
2.47.2

@themadbit
Copy link
Contributor Author

lol. Been on it since I left the office hour
I also figured out a way to get it working. But it is a very brute force way (but at least I got to learn lots of networking configs).

I added services.dnsmasq and enabled dnssec and had the mox-setup unit wait for that to be up and running.

@eljamm
Copy link
Contributor

eljamm commented Apr 3, 2025

I added services.dnsmasq and enabled dnssec and had the mox-setup unit wait for that to be up and running.

That sounds like it could be useful for a separate example config that uses DNSSEC, for those interested in that

@themadbit themadbit force-pushed the expose-mox branch 2 times, most recently from 530c09e to 077a483 Compare April 3, 2025 19:16
@themadbit
Copy link
Contributor Author

themadbit commented Apr 3, 2025

That sounds like it could be useful for a separate example config that uses DNSSEC, for those interested in that

Yess. I've stashed changes using dnsmasq to have a running service first, and then I can build upon it slowly. Ultimately a user should be able to specify all their desired config(s) which means supporting sconf. Nonetheless, the current implementation, if successfully built, a user with a working and configured domain can have Mox running and set up working emails.

@eljamm
Copy link
Contributor

eljamm commented Apr 4, 2025

I think the test fails in CI because it's not running with .driver or .driverInteractive as those give the VM an internet connection (which is required here for dns, I guess). To reproduce this, one can run:

nix build .#checks.x86_64-linux.projects/Mox/nixos/tests/basic

which will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

NGI Project: Mox
2 participants