summary refs log tree commit diff
path: root/nixos/modules/services/mail/rspamd.nix
diff options
context:
space:
mode:
authorAlexander V. Nikolaev <avn@avnik.info>2016-01-12 11:06:46 +0200
committerAlexander V. Nikolaev <avn@avnik.info>2016-01-16 15:11:36 +0200
commit14926f08a3d16cc5bb3a2da17ae68a253a4bda64 (patch)
tree043049f1ec649799b41c5bbc949c4e16d1175018 /nixos/modules/services/mail/rspamd.nix
parent480083922c0218c253353df362ba0f2bd02585b2 (diff)
downloadnixpkgs-14926f08a3d16cc5bb3a2da17ae68a253a4bda64.tar
nixpkgs-14926f08a3d16cc5bb3a2da17ae68a253a4bda64.tar.gz
nixpkgs-14926f08a3d16cc5bb3a2da17ae68a253a4bda64.tar.bz2
nixpkgs-14926f08a3d16cc5bb3a2da17ae68a253a4bda64.tar.lz
nixpkgs-14926f08a3d16cc5bb3a2da17ae68a253a4bda64.tar.xz
nixpkgs-14926f08a3d16cc5bb3a2da17ae68a253a4bda64.tar.zst
nixpkgs-14926f08a3d16cc5bb3a2da17ae68a253a4bda64.zip
nixos: Add module for rspamd
Diffstat (limited to 'nixos/modules/services/mail/rspamd.nix')
-rw-r--r--nixos/modules/services/mail/rspamd.nix90
1 files changed, 90 insertions, 0 deletions
diff --git a/nixos/modules/services/mail/rspamd.nix b/nixos/modules/services/mail/rspamd.nix
new file mode 100644
index 00000000000..a083f829324
--- /dev/null
+++ b/nixos/modules/services/mail/rspamd.nix
@@ -0,0 +1,90 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+  cfg = config.services.rspamd;
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    services.rspamd = {
+
+      enable = mkOption {
+        default = false;
+        description = "Whether to run the rspamd daemon.";
+      };
+
+      debug = mkOption {
+        default = false;
+        description = "Whether to run the rspamd daemon in debug mode.";
+      };
+
+      user = mkOption {
+        type = types.string;
+        default = "rspamd";
+        description = ''
+          User to use when no root privileges are required.
+        '';
+       };
+
+      group = mkOption {
+        type = types.string;
+        default = "rspamd";
+        description = ''
+          Group to use when no root privileges are required.
+        '';
+       };
+    };
+
+  };
+
+
+  ###### implementation
+
+  config = mkIf cfg.enable {
+
+    # Allow users to run 'rspamc' and 'rspamadm'.
+    environment.systemPackages = [ pkgs.rspamd ];
+
+    users.extraUsers = singleton {
+      name = cfg.user;
+      description = "rspamd daemon";
+      uid = config.ids.uids.rspamd;
+      group = cfg.group;
+    };
+
+    users.extraGroups = singleton {
+      name = cfg.group;
+      gid = config.ids.gids.spamd;
+    };
+
+    systemd.services.rspamd = {
+      description = "Rspamd Service";
+
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network.target" ];
+
+      serviceConfig = {
+        ExecStart = "${pkgs.rspamd}/bin/rspamd ${optionalString cfg.debug "-d"} --user=${cfg.user} --group=${cfg.group} --pid=/run/rspamd.pid -f";
+        RuntimeDirectory = "/var/lib/rspamd";
+        PermissionsStartOnly = true;
+        Restart = "always";
+      };
+
+      preStart = ''
+        ${pkgs.coreutils}/bin/mkdir -p /var/{lib,log}/rspamd
+        ${pkgs.coreutils}/bin/chown ${cfg.user}:${cfg.group} /var/lib/rspamd
+      '';
+
+    };
+
+  };
+
+}