···
1
+
{ config, lib, pkgs, ... }:
6
+
cfg = config.services.stalwart-mail;
7
+
configFormat = pkgs.formats.toml { };
8
+
configFile = configFormat.generate "stalwart-mail.toml" cfg.settings;
9
+
dataDir = "/var/lib/stalwart-mail";
12
+
options.services.stalwart-mail = {
13
+
enable = mkEnableOption (mdDoc "the Stalwart all-in-one email server");
14
+
package = mkPackageOptionMD pkgs "stalwart-mail" { };
16
+
settings = mkOption {
17
+
inherit (configFormat) type;
19
+
description = mdDoc ''
20
+
Configuration options for the Stalwart email server.
21
+
See <https://stalw.art/docs/> for available options.
23
+
By default, the module is configured to store everything locally.
28
+
config = mkIf cfg.enable {
29
+
# Default config: all local
30
+
services.stalwart-mail.settings = {
31
+
global.tracing.method = mkDefault "stdout";
32
+
global.tracing.level = mkDefault "info";
33
+
queue.path = mkDefault "${dataDir}/queue";
34
+
report.path = mkDefault "${dataDir}/reports";
35
+
store.db.path = mkDefault "${dataDir}/data/index.sqlite3";
36
+
store.blob.type = mkDefault "local";
37
+
store.blob.local.path = mkDefault "${dataDir}/data/blobs";
38
+
resolver.type = mkDefault "system";
41
+
systemd.services.stalwart-mail = {
42
+
wantedBy = [ "multi-user.target" ];
43
+
after = [ "local-fs.target" "network.target" ];
46
+
mkdir -p ${dataDir}/{queue,reports,data/blobs}
51
+
"${cfg.package}/bin/stalwart-mail --config=${configFile}";
53
+
# Base from template resources/systemd/stalwart-mail.service
55
+
LimitNOFILE = 65536;
56
+
KillMode = "process";
57
+
KillSignal = "SIGINT";
58
+
Restart = "on-failure";
60
+
StandardOutput = "syslog";
61
+
StandardError = "syslog";
62
+
SyslogIdentifier = "stalwart-mail";
65
+
User = "stalwart-mail";
66
+
StateDirectory = "stalwart-mail";
68
+
# Bind standard privileged ports
69
+
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
70
+
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
73
+
DeviceAllow = [ "" ];
74
+
LockPersonality = true;
75
+
MemoryDenyWriteExecute = true;
76
+
PrivateDevices = true;
77
+
PrivateUsers = false; # incompatible with CAP_NET_BIND_SERVICE
80
+
ProtectClock = true;
81
+
ProtectControlGroups = true;
83
+
ProtectHostname = true;
84
+
ProtectKernelLogs = true;
85
+
ProtectKernelModules = true;
86
+
ProtectKernelTunables = true;
87
+
ProtectProc = "invisible";
88
+
ProtectSystem = "strict";
89
+
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
90
+
RestrictNamespaces = true;
91
+
RestrictRealtime = true;
92
+
RestrictSUIDSGID = true;
93
+
SystemCallArchitectures = "native";
94
+
SystemCallFilter = [ "@system-service" "~@privileged" ];
99
+
# Make admin commands available in the shell
100
+
environment.systemPackages = [ cfg.package ];
104
+
maintainers = with maintainers; [ happysalada pacien ];