1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-01-28 20:05: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, ... }:
with lib;
let
# aliases
inherit (config.programs) himalaya;
tomlFormat = pkgs.formats.toml { };
# 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
# account's dir
@ -44,14 +46,14 @@ let
};
signatureConfig =
lib.optionalAttrs (account.signature.showSignature == "append") {
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;
};
imapConfig = lib.optionalAttrs imapEnabled (compactAttrs {
imapConfig = optionalAttrs imapEnabled (compactAttrs {
backend.type = "imap";
backend.host = account.imap.host;
backend.port = account.imap.port;
@ -62,17 +64,17 @@ let
builtins.concatStringsSep " " account.passwordCommand;
});
maildirConfig = lib.optionalAttrs maildirEnabled (compactAttrs {
maildirConfig = optionalAttrs maildirEnabled (compactAttrs {
backend.type = "maildir";
backend.root-dir = account.maildir.absPath;
});
notmuchConfig = lib.optionalAttrs notmuchEnabled (compactAttrs {
notmuchConfig = optionalAttrs notmuchEnabled (compactAttrs {
backend.type = "notmuch";
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.host = account.smtp.host;
message.send.backend.port = account.smtp.port;
@ -85,12 +87,12 @@ let
});
sendmailConfig =
lib.optionalAttrs (isNull account.smtp && !isNull account.msmtp) {
optionalAttrs (isNull account.smtp && !isNull account.msmtp) {
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
signatureConfig
imapConfig
@ -100,10 +102,10 @@ let
sendmailConfig
];
in lib.recursiveUpdate config account.himalaya.settings;
in recursiveUpdate config account.himalaya.settings;
in {
meta.maintainers = with lib.hm.maintainers; [ soywod toastal ];
meta.maintainers = with hm.maintainers; [ soywod toastal ];
imports = [
(mkRemovedOptionModule [ "services" "himalaya-watch" "enable" ] ''
@ -119,10 +121,10 @@ in {
options = {
programs.himalaya = {
enable = lib.mkEnableOption "the email client Himalaya CLI";
package = lib.mkPackageOption pkgs "himalaya" { };
settings = lib.mkOption {
type = lib.types.submodule { freeformType = tomlFormat.type; };
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.
@ -131,14 +133,14 @@ in {
};
};
accounts.email.accounts = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule {
accounts.email.accounts = mkOption {
type = types.attrsOf (types.submodule {
options.himalaya = {
enable = lib.mkEnableOption
enable = mkEnableOption
"the email client Himalaya CLI for this email account";
settings = lib.mkOption {
type = lib.types.submodule { freeformType = tomlFormat.type; };
settings = mkOption {
type = types.submodule { freeformType = tomlFormat.type; };
default = { };
description = ''
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 ];
xdg = {
configFile."himalaya/config.toml".source = let
enabledAccounts = lib.filterAttrs (_: account: account.himalaya.enable)
enabledAccounts = filterAttrs (_: account: account.himalaya.enable)
config.accounts.email.accounts;
accountsConfig = lib.mapAttrs mkAccountConfig enabledAccounts;
accountsConfig = mapAttrs mkAccountConfig enabledAccounts;
globalConfig = compactAttrs himalaya.settings;
allConfig = globalConfig // { accounts = accountsConfig; };
in tomlFormat.generate "himalaya.config.toml" allConfig;
desktopEntries.himalaya = lib.mkIf pkgs.stdenv.hostPlatform.isLinux {
desktopEntries.himalaya = mkIf pkgs.stdenv.hostPlatform.isLinux {
type = "Application";
name = "himalaya";
genericName = "Email Client";

View file

@ -1,32 +1,33 @@
[accounts."hm@example.com"]
backend = "imap"
default = true
display-name = "H. M. Test"
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"
inbox = "Inbox"
sent = "Sent"
trash = "Trash"
[accounts."hm@example.com".imap]
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"
[accounts."hm@example.com".message.send.backend]
host = "smtp.example.com"
login = "home.manager"
port = 465
[accounts."hm@example.com".smtp.passwd]
type = "smtp"
[accounts."hm@example.com".message.send.backend.auth]
cmd = "password-command"
type = "password"
[accounts."hm@example.com".message.send.backend.encryption]
type = "tls"