2021-06-27 00:29:42 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.programs.himalaya;
|
|
|
|
|
|
|
|
enabledAccounts =
|
|
|
|
lib.filterAttrs (_: a: a.himalaya.enable) (config.accounts.email.accounts);
|
|
|
|
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
|
|
|
|
himalayaConfig = let
|
|
|
|
toHimalayaConfig = account:
|
|
|
|
{
|
|
|
|
email = account.address;
|
2022-10-16 10:25:31 +02:00
|
|
|
display-name = account.realName;
|
2021-06-27 00:29:42 +02:00
|
|
|
default = account.primary;
|
|
|
|
|
2022-05-30 21:04:13 +02:00
|
|
|
mailboxes = {
|
|
|
|
inbox = account.folders.inbox;
|
|
|
|
sent = account.folders.sent;
|
|
|
|
draft = account.folders.drafts;
|
|
|
|
# NOTE: himalaya does not support configuring the name of the trash folder
|
|
|
|
};
|
2022-10-16 10:25:31 +02:00
|
|
|
} // (lib.optionalAttrs (account.signature.showSignature == "append") {
|
|
|
|
# FIXME: signature cannot be attached
|
|
|
|
signature = account.signature.text;
|
|
|
|
signature-delim = account.signature.delimiter;
|
|
|
|
}) // (if account.himalaya.backend == null then {
|
|
|
|
backend = "none";
|
|
|
|
} else if account.himalaya.backend == "imap" then {
|
2021-06-27 00:29:42 +02:00
|
|
|
# FIXME: does not support disabling TLS altogether
|
|
|
|
# NOTE: does not accept sequence of strings for password commands
|
2022-10-16 10:25:31 +02:00
|
|
|
backend = account.himalaya.backend;
|
2021-06-27 00:29:42 +02:00
|
|
|
imap-login = account.userName;
|
|
|
|
imap-passwd-cmd = lib.escapeShellArgs account.passwordCommand;
|
|
|
|
imap-host = account.imap.host;
|
|
|
|
imap-port = account.imap.port;
|
|
|
|
imap-starttls = account.imap.tls.useStartTls;
|
2022-10-16 10:25:31 +02:00
|
|
|
} else if account.himalaya.backend == "maildir" then {
|
|
|
|
backend = account.himalaya.backend;
|
|
|
|
maildir-root-dir = account.maildirBasePath;
|
|
|
|
} else
|
|
|
|
throw "Unsupported backend: ${account.himalaya.backend}")
|
|
|
|
// (if account.himalaya.sender == null then {
|
|
|
|
sender = "none";
|
|
|
|
} else if account.himalaya.sender == "smtp" then {
|
|
|
|
sender = account.himalaya.sender;
|
2021-06-27 00:29:42 +02:00
|
|
|
smtp-login = account.userName;
|
|
|
|
smtp-passwd-cmd = lib.escapeShellArgs account.passwordCommand;
|
|
|
|
smtp-host = account.smtp.host;
|
|
|
|
smtp-port = account.smtp.port;
|
2022-02-21 22:32:32 +01:00
|
|
|
smtp-starttls = account.smtp.tls.useStartTls;
|
2022-10-16 10:25:31 +02:00
|
|
|
} else if account.himalaya.sender == "sendmail" then {
|
|
|
|
sender = account.himalaya.sender;
|
|
|
|
} else
|
|
|
|
throw "Unsupported sender: ${account.himalaya.sender}")
|
|
|
|
// account.himalaya.settings;
|
2021-06-27 00:29:42 +02:00
|
|
|
in {
|
|
|
|
# NOTE: will not start without this configured, but each account overrides it
|
2022-10-16 10:25:31 +02:00
|
|
|
display-name = "";
|
2021-06-27 00:29:42 +02:00
|
|
|
} // cfg.settings // (lib.mapAttrs (_: toHimalayaConfig) enabledAccounts);
|
|
|
|
in {
|
2022-10-16 10:25:31 +02:00
|
|
|
meta.maintainers = with lib.hm.maintainers; [ toastal ];
|
2021-06-27 00:29:42 +02:00
|
|
|
|
|
|
|
options = with lib; {
|
|
|
|
programs.himalaya = {
|
|
|
|
enable = mkEnableOption "himalaya mail client";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.himalaya;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.himalaya";
|
2021-06-27 00:29:42 +02:00
|
|
|
description = ''
|
|
|
|
Package providing the <command>himalaya</command> mail client.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = tomlFormat.type;
|
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = lib.literalExpression ''
|
2021-06-27 00:29:42 +02:00
|
|
|
{
|
2022-10-16 10:25:31 +02:00
|
|
|
email-listing-page-size = 50;
|
|
|
|
watch-cmds = [ "mbsync -a" ]
|
2021-06-27 00:29:42 +02:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Global <command>himalaya</command> configuration values.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
accounts.email.accounts = mkOption {
|
|
|
|
type = with types;
|
|
|
|
attrsOf (submodule {
|
|
|
|
options.himalaya = {
|
|
|
|
enable = mkEnableOption ''
|
|
|
|
the himalaya mail client for this account
|
|
|
|
'';
|
|
|
|
|
2022-10-16 10:25:31 +02:00
|
|
|
backend = mkOption {
|
|
|
|
# TODO: “notmuch” (requires compile flag for himalaya, libnotmuch)
|
|
|
|
type = types.nullOr (types.enum [ "imap" "maildir" ]);
|
|
|
|
description = ''
|
|
|
|
The method for which <command>himalaya</command> will fetch, store,
|
|
|
|
etc. mail.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sender = mkOption {
|
|
|
|
type = types.nullOr (types.enum [ "smtp" "sendmail" ]);
|
|
|
|
description = ''
|
|
|
|
The method for which <command>himalaya</command> will send mail.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-06-27 00:29:42 +02:00
|
|
|
settings = mkOption {
|
|
|
|
type = tomlFormat.type;
|
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = lib.literalExpression ''
|
2021-06-27 00:29:42 +02:00
|
|
|
{
|
|
|
|
default-page-size = 50;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra settings to add to this <command>himalaya</command>
|
|
|
|
account configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
xdg.configFile."himalaya/config.toml".source =
|
|
|
|
tomlFormat.generate "himalaya-config.toml" himalayaConfig;
|
|
|
|
};
|
|
|
|
}
|