{ config, lib, pkgs, this, ... }: let cfg = config.nixfiles.modules.profiles.email; in { options.nixfiles.modules.profiles.email.enable = lib.mkEnableOption "Local Email management" // { default = this.isHeadful; }; config = lib.mkIf cfg.enable { nixfiles.modules.gnupg.enable = true; hm = { accounts.email = { maildirBasePath = "${config.my.home}/doc/mail"; accounts = let mkAccount = attrs: lib.mkMerge [ { mbsync = { enable = true; create = "both"; expunge = "both"; patterns = [ "*" ]; }; msmtp.enable = true; mu.enable = true; thunderbird = { enable = true; settings = id: { "mail.identity.id_${id}.compose_html" = false; "mail.identity.id_${id}.reply_on_top" = 0; }; }; } attrs ]; getPassword = { path, line ? 0, }: assert (builtins.isInt line); lib.concatStringsSep " " ( [ (lib.getExe config.hm.programs.password-store.package) "show" path ] ++ lib.optionals (line > 0) [ "|" (lib.getExe pkgs.gnused) "-e" "'${toString line}!d'" ] ); in { shire = mkAccount rec { address = lib.my.email; aliases = [ address "frodo@rohan.net" "azahi@shire.net" ]; realName = lib.my.fullname; signature = { showSignature = "append"; text = '' Firstname Lastname | Азат Багавиев frodo@gondor.net | frodo@rohan.net https://azahi.cc/ ''; }; gpg = { inherit (lib.my.pgp) key; signByDefault = false; encryptByDefault = false; }; primary = true; imap = { host = "shire.net"; port = 993; tls.enable = true; }; smtp = { host = "shire.net"; port = 465; tls.enable = true; }; userName = "azahi@shire.net"; passwordCommand = getPassword { path = "email/shire.net/azahi"; }; }; yandex = mkAccount rec { address = "username@ya.ru"; aliases = [ address "username@yandex.ru" ]; realName = "Firstname Lastname"; flavor = "yandex.com"; userName = "username@yandex.ru"; passwordCommand = getPassword { path = "email/yandex.ru/username"; line = 2; }; }; }; }; programs = { mbsync.enable = true; msmtp.enable = true; mu.enable = true; }; }; }; }