nixos/services.stalwart-mail: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-24 22:05:36 +02:00
parent 3d0cdfa3c5
commit 6d0e431080

View File

@ -1,29 +1,26 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.stalwart-mail;
configFormat = pkgs.formats.toml { };
configFile = configFormat.generate "stalwart-mail.toml" cfg.settings;
dataDir = "/var/lib/stalwart-mail";
useLegacyStorage = versionOlder config.system.stateVersion "24.11";
useLegacyStorage = lib.versionOlder config.system.stateVersion "24.11";
parsePorts = listeners: let
parseAddresses = listeners: lib.flatten(lib.mapAttrsToList (name: value: value.bind) listeners);
splitAddress = addr: strings.splitString ":" addr;
extractPort = addr: strings.toInt(builtins.foldl' (a: b: b) "" (splitAddress addr));
splitAddress = addr: lib.splitString ":" addr;
extractPort = addr: lib.toInt(builtins.foldl' (a: b: b) "" (splitAddress addr));
in
builtins.map(address: extractPort address) (parseAddresses listeners);
in {
options.services.stalwart-mail = {
enable = mkEnableOption "the Stalwart all-in-one email server";
enable = lib.mkEnableOption "the Stalwart all-in-one email server";
package = mkPackageOption pkgs "stalwart-mail" { };
package = lib.mkPackageOption pkgs "stalwart-mail" { };
openFirewall = mkOption {
type = types.bool;
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to open TCP firewall ports, which are specified in
@ -31,7 +28,7 @@ in {
'';
};
settings = mkOption {
settings = lib.mkOption {
inherit (configFormat) type;
default = { };
description = ''
@ -43,36 +40,36 @@ in {
};
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
# Default config: all local
services.stalwart-mail.settings = {
tracer.stdout = {
type = mkDefault "stdout";
level = mkDefault "info";
ansi = mkDefault false; # no colour markers to journald
enable = mkDefault true;
type = lib.mkDefault "stdout";
level = lib.mkDefault "info";
ansi = lib.mkDefault false; # no colour markers to journald
enable = lib.mkDefault true;
};
store = if useLegacyStorage then {
# structured data in SQLite, blobs on filesystem
db.type = mkDefault "sqlite";
db.path = mkDefault "${dataDir}/data/index.sqlite3";
fs.type = mkDefault "fs";
fs.path = mkDefault "${dataDir}/data/blobs";
db.type = lib.mkDefault "sqlite";
db.path = lib.mkDefault "${dataDir}/data/index.sqlite3";
fs.type = lib.mkDefault "fs";
fs.path = lib.mkDefault "${dataDir}/data/blobs";
} else {
# everything in RocksDB
db.type = mkDefault "rocksdb";
db.path = mkDefault "${dataDir}/db";
db.compression = mkDefault "lz4";
db.type = lib.mkDefault "rocksdb";
db.path = lib.mkDefault "${dataDir}/db";
db.compression = lib.mkDefault "lz4";
};
storage.data = mkDefault "db";
storage.fts = mkDefault "db";
storage.lookup = mkDefault "db";
storage.blob = mkDefault (if useLegacyStorage then "fs" else "db");
directory.internal.type = mkDefault "internal";
directory.internal.store = mkDefault "db";
storage.directory = mkDefault "internal";
resolver.type = mkDefault "system";
storage.data = lib.mkDefault "db";
storage.fts = lib.mkDefault "db";
storage.lookup = lib.mkDefault "db";
storage.blob = lib.mkDefault (if useLegacyStorage then "fs" else "db");
directory.internal.type = lib.mkDefault "internal";
directory.internal.store = lib.mkDefault "db";
storage.directory = lib.mkDefault "internal";
resolver.type = lib.mkDefault "system";
resolver.public-suffix = lib.mkDefault [
"file://${pkgs.publicsuffix-list}/share/publicsuffix/public_suffix_list.dat"
];
@ -155,13 +152,13 @@ in {
# Make admin commands available in the shell
environment.systemPackages = [ cfg.package ];
networking.firewall = mkIf (cfg.openFirewall
networking.firewall = lib.mkIf (cfg.openFirewall
&& (builtins.hasAttr "listener" cfg.settings.server)) {
allowedTCPPorts = parsePorts cfg.settings.server.listener;
};
};
meta = {
maintainers = with maintainers; [ happysalada pacien onny ];
maintainers = with lib.maintainers; [ happysalada pacien onny ];
};
}