1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-09 02:06:53 +00:00
home-manager/modules/programs/himalaya.nix

181 lines
5.8 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
2025-01-24 06:17:50 +01:00
with lib;
let
# aliases
inherit (config.programs) himalaya;
tomlFormat = pkgs.formats.toml { };
# attrs util that removes entries containing a null value
2025-01-24 06:17:50 +01:00
compactAttrs = filterAttrs (_: val: !isNull val);
# needed for notmuch config, because the DB is here, and not in each
# account's dir
maildirBasePath = config.accounts.email.maildirBasePath;
# make encryption config based on the given home-manager email
# account TLS config
mkEncryptionConfig = tls:
if tls.useStartTls then
"start-tls"
else if tls.enable then
"tls"
else
"none";
# make a himalaya account config based on the given home-manager
# email account config
mkAccountConfig = _: account:
let
notmuchEnabled = account.notmuch.enable;
imapEnabled = !isNull account.imap && !notmuchEnabled;
maildirEnabled = !isNull account.maildir && !imapEnabled
&& !notmuchEnabled;
globalConfig = {
email = account.address;
display-name = account.realName;
default = account.primary;
folder.aliases = {
inbox = account.folders.inbox;
sent = account.folders.sent;
drafts = account.folders.drafts;
trash = account.folders.trash;
};
};
signatureConfig =
2025-01-24 06:17:50 +01:00
optionalAttrs (account.signature.showSignature == "append") {
# TODO: signature cannot be attached yet
# https://github.com/pimalaya/himalaya/issues/534
signature = account.signature.text;
signature-delim = account.signature.delimiter;
};
2025-01-24 06:17:50 +01:00
imapConfig = optionalAttrs imapEnabled (compactAttrs {
backend.type = "imap";
backend.host = account.imap.host;
backend.port = account.imap.port;
backend.encryption.type = mkEncryptionConfig account.imap.tls;
backend.login = account.userName;
backend.auth.type = "password";
backend.auth.cmd =
builtins.concatStringsSep " " account.passwordCommand;
});
2025-01-24 06:17:50 +01:00
maildirConfig = optionalAttrs maildirEnabled (compactAttrs {
backend.type = "maildir";
backend.root-dir = account.maildir.absPath;
});
2025-01-24 06:17:50 +01:00
notmuchConfig = optionalAttrs notmuchEnabled (compactAttrs {
backend.type = "notmuch";
backend.db-path = maildirBasePath;
});
2025-01-24 06:17:50 +01:00
smtpConfig = optionalAttrs (!isNull account.smtp) (compactAttrs {
message.send.backend.type = "smtp";
message.send.backend.host = account.smtp.host;
message.send.backend.port = account.smtp.port;
message.send.backend.encryption.type =
mkEncryptionConfig account.smtp.tls;
message.send.backend.login = account.userName;
message.send.backend.auth.type = "password";
message.send.backend.auth.cmd =
builtins.concatStringsSep " " account.passwordCommand;
});
sendmailConfig =
2025-01-24 06:17:50 +01:00
optionalAttrs (isNull account.smtp && !isNull account.msmtp) {
message.send.backend.type = "sendmail";
2025-01-24 06:17:50 +01:00
message.send.backend.cmd = getExe pkgs.msmtp;
};
2025-01-24 06:17:50 +01:00
config = attrsets.mergeAttrsList [
globalConfig
signatureConfig
imapConfig
maildirConfig
notmuchConfig
smtpConfig
sendmailConfig
];
2025-01-24 06:17:50 +01:00
in recursiveUpdate config account.himalaya.settings;
in {
2025-01-24 06:17:50 +01:00
meta.maintainers = with hm.maintainers; [ soywod toastal ];
imports = [
(mkRemovedOptionModule [ "services" "himalaya-watch" "enable" ] ''
services.himalaya-watch has been removed.
The watch feature moved away from Himalaya scope, and resides
now in its own project called Mirador. Once the v1 released, the
service will land back in nixpkgs and home-manager.
See <https://github.com/pimalaya/mirador>.
'')
];
options = {
programs.himalaya = {
2025-01-24 06:17:50 +01:00
enable = mkEnableOption "the email client Himalaya CLI";
package = mkPackageOption pkgs "himalaya" { };
settings = mkOption {
type = types.submodule { freeformType = tomlFormat.type; };
default = { };
description = ''
Himalaya CLI global configuration.
See <https://github.com/pimalaya/himalaya/blob/master/config.sample.toml> for supported values.
'';
};
};
2025-01-24 06:17:50 +01:00
accounts.email.accounts = mkOption {
type = types.attrsOf (types.submodule {
options.himalaya = {
2025-01-24 06:17:50 +01:00
enable = mkEnableOption
"the email client Himalaya CLI for this email account";
2025-01-24 06:17:50 +01:00
settings = mkOption {
type = types.submodule { freeformType = tomlFormat.type; };
default = { };
description = ''
Himalaya CLI configuration for this email account.
See <https://github.com/pimalaya/himalaya/blob/master/config.sample.toml> for supported values.
'';
};
};
});
};
};
2025-01-24 06:17:50 +01:00
config = mkIf himalaya.enable {
home.packages = [ himalaya.package ];
2024-04-20 09:49:20 +02:00
xdg = {
configFile."himalaya/config.toml".source = let
2025-01-24 06:17:50 +01:00
enabledAccounts = filterAttrs (_: account: account.himalaya.enable)
2024-04-20 09:49:20 +02:00
config.accounts.email.accounts;
2025-01-24 06:17:50 +01:00
accountsConfig = mapAttrs mkAccountConfig enabledAccounts;
2024-04-20 09:49:20 +02:00
globalConfig = compactAttrs himalaya.settings;
allConfig = globalConfig // { accounts = accountsConfig; };
in tomlFormat.generate "himalaya.config.toml" allConfig;
2024-04-20 09:49:20 +02:00
2025-01-24 06:17:50 +01:00
desktopEntries.himalaya = mkIf pkgs.stdenv.hostPlatform.isLinux {
2024-04-20 09:49:20 +02:00
type = "Application";
name = "himalaya";
genericName = "Email Client";
comment = "CLI to manage emails";
terminal = true;
exec = "himalaya %u";
categories = [ "Network" ];
mimeType = [ "x-scheme-handler/mailto" "message/rfc822" ];
settings = { Keywords = "email"; };
};
};
};
}