1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-01-30 04:45:02 +01:00

himalaya: fix tests

This commit is contained in:
Clément DOUIN 2025-01-24 06:17:50 +01:00
parent e9068facd7
commit 15f7f9bc4e
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
2 changed files with 45 additions and 42 deletions

View file

@ -1,12 +1,14 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
# aliases # aliases
inherit (config.programs) himalaya; inherit (config.programs) himalaya;
tomlFormat = pkgs.formats.toml { }; tomlFormat = pkgs.formats.toml { };
# attrs util that removes entries containing a null value # attrs util that removes entries containing a null value
compactAttrs = lib.filterAttrs (_: val: !isNull val); compactAttrs = filterAttrs (_: val: !isNull val);
# needed for notmuch config, because the DB is here, and not in each # needed for notmuch config, because the DB is here, and not in each
# account's dir # account's dir
@ -44,14 +46,14 @@ let
}; };
signatureConfig = signatureConfig =
lib.optionalAttrs (account.signature.showSignature == "append") { optionalAttrs (account.signature.showSignature == "append") {
# TODO: signature cannot be attached yet # TODO: signature cannot be attached yet
# https://github.com/pimalaya/himalaya/issues/534 # https://github.com/pimalaya/himalaya/issues/534
signature = account.signature.text; signature = account.signature.text;
signature-delim = account.signature.delimiter; signature-delim = account.signature.delimiter;
}; };
imapConfig = lib.optionalAttrs imapEnabled (compactAttrs { imapConfig = optionalAttrs imapEnabled (compactAttrs {
backend.type = "imap"; backend.type = "imap";
backend.host = account.imap.host; backend.host = account.imap.host;
backend.port = account.imap.port; backend.port = account.imap.port;
@ -62,17 +64,17 @@ let
builtins.concatStringsSep " " account.passwordCommand; builtins.concatStringsSep " " account.passwordCommand;
}); });
maildirConfig = lib.optionalAttrs maildirEnabled (compactAttrs { maildirConfig = optionalAttrs maildirEnabled (compactAttrs {
backend.type = "maildir"; backend.type = "maildir";
backend.root-dir = account.maildir.absPath; backend.root-dir = account.maildir.absPath;
}); });
notmuchConfig = lib.optionalAttrs notmuchEnabled (compactAttrs { notmuchConfig = optionalAttrs notmuchEnabled (compactAttrs {
backend.type = "notmuch"; backend.type = "notmuch";
backend.db-path = maildirBasePath; backend.db-path = maildirBasePath;
}); });
smtpConfig = lib.optionalAttrs (!isNull account.smtp) (compactAttrs { smtpConfig = optionalAttrs (!isNull account.smtp) (compactAttrs {
message.send.backend.type = "smtp"; message.send.backend.type = "smtp";
message.send.backend.host = account.smtp.host; message.send.backend.host = account.smtp.host;
message.send.backend.port = account.smtp.port; message.send.backend.port = account.smtp.port;
@ -85,12 +87,12 @@ let
}); });
sendmailConfig = sendmailConfig =
lib.optionalAttrs (isNull account.smtp && !isNull account.msmtp) { optionalAttrs (isNull account.smtp && !isNull account.msmtp) {
message.send.backend.type = "sendmail"; message.send.backend.type = "sendmail";
message.send.backend.cmd = lib.getExe pkgs.msmtp; message.send.backend.cmd = getExe pkgs.msmtp;
}; };
config = lib.attrsets.mergeAttrsList [ config = attrsets.mergeAttrsList [
globalConfig globalConfig
signatureConfig signatureConfig
imapConfig imapConfig
@ -100,10 +102,10 @@ let
sendmailConfig sendmailConfig
]; ];
in lib.recursiveUpdate config account.himalaya.settings; in recursiveUpdate config account.himalaya.settings;
in { in {
meta.maintainers = with lib.hm.maintainers; [ soywod toastal ]; meta.maintainers = with hm.maintainers; [ soywod toastal ];
imports = [ imports = [
(mkRemovedOptionModule [ "services" "himalaya-watch" "enable" ] '' (mkRemovedOptionModule [ "services" "himalaya-watch" "enable" ] ''
@ -119,10 +121,10 @@ in {
options = { options = {
programs.himalaya = { programs.himalaya = {
enable = lib.mkEnableOption "the email client Himalaya CLI"; enable = mkEnableOption "the email client Himalaya CLI";
package = lib.mkPackageOption pkgs "himalaya" { }; package = mkPackageOption pkgs "himalaya" { };
settings = lib.mkOption { settings = mkOption {
type = lib.types.submodule { freeformType = tomlFormat.type; }; type = types.submodule { freeformType = tomlFormat.type; };
default = { }; default = { };
description = '' description = ''
Himalaya CLI global configuration. Himalaya CLI global configuration.
@ -131,14 +133,14 @@ in {
}; };
}; };
accounts.email.accounts = lib.mkOption { accounts.email.accounts = mkOption {
type = lib.types.attrsOf (lib.types.submodule { type = types.attrsOf (types.submodule {
options.himalaya = { options.himalaya = {
enable = lib.mkEnableOption enable = mkEnableOption
"the email client Himalaya CLI for this email account"; "the email client Himalaya CLI for this email account";
settings = lib.mkOption { settings = mkOption {
type = lib.types.submodule { freeformType = tomlFormat.type; }; type = types.submodule { freeformType = tomlFormat.type; };
default = { }; default = { };
description = '' description = ''
Himalaya CLI configuration for this email account. Himalaya CLI configuration for this email account.
@ -150,19 +152,19 @@ in {
}; };
}; };
config = lib.mkIf himalaya.enable { config = mkIf himalaya.enable {
home.packages = [ himalaya.package ]; home.packages = [ himalaya.package ];
xdg = { xdg = {
configFile."himalaya/config.toml".source = let configFile."himalaya/config.toml".source = let
enabledAccounts = lib.filterAttrs (_: account: account.himalaya.enable) enabledAccounts = filterAttrs (_: account: account.himalaya.enable)
config.accounts.email.accounts; config.accounts.email.accounts;
accountsConfig = lib.mapAttrs mkAccountConfig enabledAccounts; accountsConfig = mapAttrs mkAccountConfig enabledAccounts;
globalConfig = compactAttrs himalaya.settings; globalConfig = compactAttrs himalaya.settings;
allConfig = globalConfig // { accounts = accountsConfig; }; allConfig = globalConfig // { accounts = accountsConfig; };
in tomlFormat.generate "himalaya.config.toml" allConfig; in tomlFormat.generate "himalaya.config.toml" allConfig;
desktopEntries.himalaya = lib.mkIf pkgs.stdenv.hostPlatform.isLinux { desktopEntries.himalaya = mkIf pkgs.stdenv.hostPlatform.isLinux {
type = "Application"; type = "Application";
name = "himalaya"; name = "himalaya";
genericName = "Email Client"; genericName = "Email Client";

View file

@ -1,32 +1,33 @@
[accounts."hm@example.com"] [accounts."hm@example.com"]
backend = "imap"
default = true default = true
display-name = "H. M. Test" display-name = "H. M. Test"
email = "hm@example.com" email = "hm@example.com"
[accounts."hm@example.com".backend]
host = "imap.example.com"
login = "home.manager"
port = 993
type = "imap"
[accounts."hm@example.com".backend.auth]
cmd = "password-command"
type = "password"
[accounts."hm@example.com".folder.alias] [accounts."hm@example.com".backend.encryption]
type = "tls"
[accounts."hm@example.com".folder.aliases]
drafts = "Drafts" drafts = "Drafts"
inbox = "Inbox" inbox = "Inbox"
sent = "Sent" sent = "Sent"
trash = "Trash" trash = "Trash"
[accounts."hm@example.com".imap] [accounts."hm@example.com".message.send.backend]
encryption = "tls"
host = "imap.example.com"
login = "home.manager"
port = 993
[accounts."hm@example.com".imap.passwd]
cmd = "password-command"
[accounts."hm@example.com".message.send]
backend = "smtp"
[accounts."hm@example.com".smtp]
encryption = "tls"
host = "smtp.example.com" host = "smtp.example.com"
login = "home.manager" login = "home.manager"
port = 465 port = 465
type = "smtp"
[accounts."hm@example.com".smtp.passwd] [accounts."hm@example.com".message.send.backend.auth]
cmd = "password-command" cmd = "password-command"
type = "password"
[accounts."hm@example.com".message.send.backend.encryption]
type = "tls"