summary refs log tree commit diff
path: root/nixos/modules/services/mail/spamassassin.nix
diff options
context:
space:
mode:
authorPhilipp Kern <pkern@google.com>2021-01-10 12:15:38 +0100
committerPhilipp Kern <pkern@google.com>2021-02-11 10:12:16 +0100
commit8854b8251177e242d2869e3effe6ae47e5f229d1 (patch)
tree6f4dd7f0b576bcdc4592f481d050be29f60f0d88 /nixos/modules/services/mail/spamassassin.nix
parentc86b339491d0c42540650d86e4ba840cdb686b50 (diff)
downloadnixpkgs-8854b8251177e242d2869e3effe6ae47e5f229d1.tar
nixpkgs-8854b8251177e242d2869e3effe6ae47e5f229d1.tar.gz
nixpkgs-8854b8251177e242d2869e3effe6ae47e5f229d1.tar.bz2
nixpkgs-8854b8251177e242d2869e3effe6ae47e5f229d1.tar.lz
nixpkgs-8854b8251177e242d2869e3effe6ae47e5f229d1.tar.xz
nixpkgs-8854b8251177e242d2869e3effe6ae47e5f229d1.tar.zst
nixpkgs-8854b8251177e242d2869e3effe6ae47e5f229d1.zip
nixos/spamassassin: Handle return codes correctly
For sa-update we care about two successful codes:

 * 1 -> no updates available: exit successfully
 * 0 -> updates have been installed: run sa-compile and pass
   through its return code
Diffstat (limited to 'nixos/modules/services/mail/spamassassin.nix')
-rw-r--r--nixos/modules/services/mail/spamassassin.nix17
1 files changed, 12 insertions, 5 deletions
diff --git a/nixos/modules/services/mail/spamassassin.nix b/nixos/modules/services/mail/spamassassin.nix
index 9bd415ef17e..ac878222b26 100644
--- a/nixos/modules/services/mail/spamassassin.nix
+++ b/nixos/modules/services/mail/spamassassin.nix
@@ -136,19 +136,26 @@ in
         Group = "spamd";
         StateDirectory = "spamassassin";
         ExecStartPost = "+${pkgs.systemd}/bin/systemctl -q --no-block try-reload-or-restart spamd.service";
-        SuccessExitStatus = "1";
       };
 
       script = ''
         set +e
-        ${pkgs.spamassassin}/bin/sa-update --verbose --gpghomedir=%S/spamassassin/sa-update-keys/
+        ${pkgs.spamassassin}/bin/sa-update --verbose --gpghomedir=/var/lib/spamassassin/sa-update-keys/
         rc=$?
         set -e
 
-        if [[ $rc -eq 0 ]]; then
-          # An update was available and installed.
-          ${pkgs.spamassassin}/bin/sa-compile
+        if [[ $rc -gt 1 ]]; then
+          # sa-update failed.
+          exit $rc
         fi
+
+        if [[ $rc -eq 1 ]]; then
+          # No update was available, exit successfully.
+          exit 0
+        fi
+
+        # An update was available and installed. Compile the rules.
+        ${pkgs.spamassassin}/bin/sa-compile
       '';
     };