{ lib, config, pkgs, ... }: with lib; let cfg = config.modules.email; in { options.modules.email = { enable = mkEnableOption "Enable email accounts configuration"; accountConfigs = mkOption { type = types.attrsOf types.attrs; default = false; description = "List of account variables used to create accounts"; }; primary = mkOption { type = types.str; default = false; description = "name of primary account"; }; }; config = mkIf cfg.enable { accounts.email = let defaultSetting = { mbsync = { enable = true; create = "maildir"; expunge = "both"; }; aerc = { enable = true; extraAccounts ={ source = "notmuch://~/mail"; maildir-store = "~/mail"; default = "Inbox"; postpone = "Drafts"; copy-to = "Sent"; use-envelope-from = true; }; }; notmuch = { enable = true; }; }; accountsList = lib.mapAttrs ( name: value: lib.recursiveUpdate defaultSetting value.config ) cfg.accountConfigs; in { maildirBasePath = "mail"; accounts = lib.recursiveUpdate accountsList { "${cfg.primary}".primary = true; }; }; # programs.notmuch = { # enable = true; # new.tags = [ "new" ]; # hooks.postNew = '' # ${pkgs.afew}/bin/afew -t -n # ${pkgs.afew}/bin/afew -w -n # ''; # }; programs.afew = { enable = true; extraConfig = '' [FolderNameFilter] folder_explicit_list = archives folder_transforms = archives:archive maildir_separator = / [MailMover] [SpamFilter] [KillThreadsFilter] [ArchiveSentMailsFilter] sent_tag = sent [InboxFilter] ''; }; programs.aerc = { enable = true; extraConfig = { general = { unsafe-accounts-conf = true; }; ui = { column-subject = '' {{if .ThreadPrefix}}{{.Style (printf "%s " .ThreadPrefix) "thread"}}{{- end }}{{.Subject}} ''; column-flags = '' {{.Flags | join " "}} ''; index-columns = '' flags:5,name<20%,subject,date>= ''; thread-prefix-tip = "╼ "; thread-prefix-indent = ""; thread-prefix-stem = "│"; thread-prefix-limb = "─"; thread-prefix-folded = "+"; thread-prefix-unfolded = ""; thread-prefix-first-child = "┬"; thread-prefix-has-siblings = "├"; thread-prefix-orphan = "┬╼ "; thread-prefix-dummy = "┬"; thread-prefix-lone = " "; thread-prefix-last-sibling = "╰"; completion-popovers = true; icon-attachment = "󰁦"; icon-replied = ""; icon-forwarded = ""; icon-new = ""; icon-old = ""; icon-unencrypted = ""; icon-encrypted = ""; icon-signed = "󰏫"; icon-signed-encrypted = ""; icon-invalid = "󰏯"; icon-unknown = "󰷭"; threading-enabled = true; }; statusline = { status-columns='' left<*,right>* ''; column-left = '' {{.Style (printf " %s " (toUpper .Account)) "statusline_account" }}\ {{.Style (printf "  %s | 󰉉 %s " .Folder (humanReadable .Size)) "statusline_folder"}}\ {{ if .ContentInfo }}{{.Style (printf " %s " .ContentInfo) "statusline_contentinfo"}}{{- end }} ''; column-center = '' {{.Style .PendingKeys "statusline_center"}} ''; }; filters = { "text/plain" = " wrap -w 100 | colorize"; "text/html" = "! html"; "text/calendar" = "calendar"; "message/delivery-status" = "colorize"; "message/rfc822" = "colorize"; ".headers" = "colorize"; }; }; stylesets = { default = (builtins.readFile ./files/default.theme); }; }; programs.mbsync = { enable = true; }; services.mbsync = { enable = true; postExec = "${pkgs.notmuch}/bin/notmuch new"; package = config.programs.mbsync.package; }; }; }