nixos/maddy: add package option

This commit is contained in:
Nguyễn Gia Phong 2025-04-06 20:04:21 +09:00
parent 250b695f41
commit baf2d3e27f
No known key found for this signature in database
GPG key ID: 84B69CE6F3F6B767

View file

@ -143,6 +143,8 @@ in
enable = lib.mkEnableOption "Maddy, a free an open source mail server"; enable = lib.mkEnableOption "Maddy, a free an open source mail server";
package = lib.mkPackageOption pkgs "maddy" { };
user = lib.mkOption { user = lib.mkOption {
default = "maddy"; default = "maddy";
type = with lib.types; uniq str; type = with lib.types; uniq str;
@ -386,7 +388,7 @@ in
systemd = { systemd = {
packages = [ pkgs.maddy ]; packages = [ cfg.package ];
services = { services = {
maddy = { maddy = {
serviceConfig = { serviceConfig = {
@ -402,16 +404,16 @@ in
script = '' script = ''
${lib.optionalString (cfg.ensureAccounts != [ ]) '' ${lib.optionalString (cfg.ensureAccounts != [ ]) ''
${lib.concatMapStrings (account: '' ${lib.concatMapStrings (account: ''
if ! ${pkgs.maddy}/bin/maddyctl imap-acct list | grep "${account}"; then if ! ${cfg.package}/bin/maddyctl imap-acct list | grep "${account}"; then
${pkgs.maddy}/bin/maddyctl imap-acct create ${account} ${cfg.package}/bin/maddyctl imap-acct create ${account}
fi fi
'') cfg.ensureAccounts} '') cfg.ensureAccounts}
''} ''}
${lib.optionalString (cfg.ensureCredentials != { }) '' ${lib.optionalString (cfg.ensureCredentials != { }) ''
${lib.concatStringsSep "\n" ( ${lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: cfg: '' lib.mapAttrsToList (name: credentials: ''
if ! ${pkgs.maddy}/bin/maddyctl creds list | grep "${name}"; then if ! ${cfg.package}/bin/maddyctl creds list | grep "${name}"; then
${pkgs.maddy}/bin/maddyctl creds create --password $(cat ${lib.escapeShellArg cfg.passwordFile}) ${name} ${cfg.package}/bin/maddyctl creds create --password $(cat ${lib.escapeShellArg credentials.passwordFile}) ${name}
fi fi
'') cfg.ensureCredentials '') cfg.ensureCredentials
)} )}
@ -486,7 +488,7 @@ in
}; };
environment.systemPackages = [ environment.systemPackages = [
pkgs.maddy cfg.package
]; ];
}; };
} }