Commit 7e626703 authored by Michal Sojka's avatar Michal Sojka
Browse files

nixos/nullmailer: Always adjust ownership of spool directories

When switching between different NixOS configurations (with and
without nullmailer and other services), it can happen that the UID of
the nullmailer user changes. When it happens, the nullmailer service
happily starts, but the user cannot send any email, because the
sendmail wrapper doesn't have permission to write them to the queue.

This commit prevents that. Instead of creating the directories by the
nullmailer user, which doesn't have permissions to change ownership,
we now create them by the systemd-tmpfiles, which has sufficient
permissions to adjust ownership.
parent a63021a3
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -212,6 +212,9 @@ with lib;

    systemd.tmpfiles.rules = [
      "d /var/spool/nullmailer - ${cfg.user} - - -"
      "d /var/spool/nullmailer/failed 750 ${cfg.user} - - -"
      "d /var/spool/nullmailer/queue 750 ${cfg.user} - - -"
      "d /var/spool/nullmailer/tmp 750 ${cfg.user} - - -"
    ];

    systemd.services.nullmailer = {
@@ -220,7 +223,6 @@ with lib;
      after = [ "network.target" ];

      preStart = ''
        mkdir -p /var/spool/nullmailer/{queue,tmp,failed}
        rm -f /var/spool/nullmailer/trigger && mkfifo -m 660 /var/spool/nullmailer/trigger
      '';