2020-01-22 00:52:01 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.neomutt;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
neomuttAccounts =
|
|
|
|
filter (a: a.neomutt.enable) (attrValues config.accounts.email.accounts);
|
2020-01-22 00:52:01 +01:00
|
|
|
|
|
|
|
sidebarModule = types.submodule {
|
|
|
|
options = {
|
|
|
|
enable = mkEnableOption "sidebar support";
|
|
|
|
|
|
|
|
width = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 22;
|
|
|
|
description = "Width of the sidebar";
|
|
|
|
};
|
|
|
|
|
|
|
|
shortPath = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
By default sidebar shows the full path of the mailbox, but
|
|
|
|
with this enabled only the relative name is shown.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
format = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "%B%?F? [%F]?%* %?N?%N/?%S";
|
|
|
|
description = ''
|
|
|
|
Sidebar format. Check neomutt documentation for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-21 15:24:52 +01:00
|
|
|
sortOptions = [
|
|
|
|
"date"
|
|
|
|
"date-received"
|
|
|
|
"from"
|
|
|
|
"mailbox-order"
|
|
|
|
"score"
|
|
|
|
"size"
|
|
|
|
"spam"
|
|
|
|
"subject"
|
|
|
|
"threads"
|
|
|
|
"to"
|
|
|
|
];
|
|
|
|
|
2020-01-22 00:52:01 +01:00
|
|
|
bindModule = types.submodule {
|
|
|
|
options = {
|
|
|
|
map = mkOption {
|
|
|
|
type = types.enum [
|
|
|
|
"alias"
|
|
|
|
"attach"
|
|
|
|
"browser"
|
|
|
|
"compose"
|
|
|
|
"editor"
|
|
|
|
"generic"
|
|
|
|
"index"
|
|
|
|
"mix"
|
|
|
|
"pager"
|
|
|
|
"pgp"
|
|
|
|
"postpone"
|
|
|
|
"query"
|
|
|
|
"smime"
|
|
|
|
];
|
|
|
|
default = "index";
|
|
|
|
description = "Select the menu to bind the command to.";
|
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "<left>";
|
|
|
|
description = "The key to bind.";
|
|
|
|
};
|
|
|
|
|
|
|
|
action = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "<enter-command>toggle sidebar_visible<enter><refresh>";
|
|
|
|
description = "Specify the action to take.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
yesno = x: if x then "yes" else "no";
|
|
|
|
setOption = n: v: if v == null then "unset ${n}" else "set ${n}=${v}";
|
2020-02-02 00:39:17 +01:00
|
|
|
escape = replaceStrings [ "%" ] [ "%25" ];
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
accountFilename = account: config.xdg.configHome + "/neomutt/" + account.name;
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
genCommonFolderHooks = account:
|
|
|
|
with account; {
|
2020-01-22 00:52:01 +01:00
|
|
|
from = "'${address}'";
|
|
|
|
realname = "'${realName}'";
|
|
|
|
spoolfile = "'+${folders.inbox}'";
|
|
|
|
record = if folders.sent == null then null else "'+${folders.sent}'";
|
|
|
|
postponed = "'+${folders.drafts}'";
|
|
|
|
trash = "'+${folders.trash}'";
|
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
mtaSection = account:
|
|
|
|
with account;
|
|
|
|
let passCmd = concatStringsSep " " passwordCommand;
|
|
|
|
in if neomutt.sendMailCommand != null then {
|
|
|
|
sendmail = "'${neomutt.sendMailCommand}'";
|
|
|
|
} else
|
|
|
|
let
|
2020-01-22 00:52:01 +01:00
|
|
|
smtpProto = if smtp.tls.enable then "smtps" else "smtp";
|
2020-07-04 05:22:16 +02:00
|
|
|
smtpPort = if smtp.port != null then ":${toString smtp.port}" else "";
|
2020-07-03 21:14:25 +02:00
|
|
|
smtpBaseUrl =
|
|
|
|
"${smtpProto}://${escape userName}@${smtp.host}${smtpPort}";
|
2020-01-22 00:52:01 +01:00
|
|
|
in {
|
|
|
|
smtp_url = "'${smtpBaseUrl}'";
|
2021-01-11 12:54:34 +01:00
|
|
|
smtp_pass = ''"`${passCmd}`"'';
|
2020-01-22 00:52:01 +01:00
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
genMaildirAccountConfig = account:
|
|
|
|
with account;
|
2020-01-22 00:52:01 +01:00
|
|
|
let
|
2020-02-02 00:39:17 +01:00
|
|
|
folderHook = mapAttrsToList setOption (genCommonFolderHooks account // {
|
|
|
|
folder = "'${account.maildir.absPath}'";
|
2020-10-09 20:55:35 +02:00
|
|
|
});
|
2020-02-02 00:39:17 +01:00
|
|
|
in ''
|
|
|
|
${concatStringsSep "\n" folderHook}
|
|
|
|
'';
|
|
|
|
|
|
|
|
registerAccount = account:
|
|
|
|
with account; ''
|
2020-01-22 00:52:01 +01:00
|
|
|
# register account ${name}
|
|
|
|
mailboxes "${account.maildir.absPath}/${folders.inbox}"
|
|
|
|
folder-hook ${account.maildir.absPath}/ " \
|
|
|
|
source ${accountFilename account} "
|
|
|
|
'';
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
mraSection = account:
|
|
|
|
with account;
|
|
|
|
if account.maildir != null then
|
|
|
|
genMaildirAccountConfig account
|
|
|
|
else
|
|
|
|
throw "Only maildir is supported at the moment";
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
optionsStr = attrs: concatStringsSep "\n" (mapAttrsToList setOption attrs);
|
2020-01-22 00:52:01 +01:00
|
|
|
|
|
|
|
sidebarSection = ''
|
|
|
|
# Sidebar
|
|
|
|
set sidebar_visible = yes
|
|
|
|
set sidebar_short_path = ${yesno cfg.sidebar.shortPath}
|
|
|
|
set sidebar_width = ${toString cfg.sidebar.width}
|
|
|
|
set sidebar_format = '${cfg.sidebar.format}'
|
|
|
|
'';
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
bindSection = concatMapStringsSep "\n"
|
|
|
|
(bind: ''bind ${bind.map} ${bind.key} "${bind.action}"'') cfg.binds;
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
macroSection = concatMapStringsSep "\n"
|
|
|
|
(bind: ''macro ${bind.map} ${bind.key} "${bind.action}"'') cfg.macros;
|
2020-01-22 00:52:01 +01:00
|
|
|
|
|
|
|
mailCheckSection = ''
|
|
|
|
set mail_check_stats
|
|
|
|
set mail_check_stats_interval = ${toString cfg.checkStatsInterval}
|
|
|
|
'';
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
notmuchSection = account:
|
|
|
|
with account; ''
|
|
|
|
# notmuch section
|
|
|
|
set nm_default_uri = "notmuch://${config.accounts.email.maildirBasePath}"
|
|
|
|
virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox"
|
|
|
|
'';
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
accountStr = account:
|
|
|
|
with account;
|
|
|
|
''
|
|
|
|
# Generated by Home Manager.
|
|
|
|
set ssl_force_tls = yes
|
|
|
|
set certificate_file=${config.accounts.email.certificatesFile}
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
# GPG section
|
|
|
|
set crypt_use_gpgme = yes
|
|
|
|
set crypt_autosign = ${yesno (gpg.signByDefault or false)}
|
|
|
|
set pgp_use_gpg_agent = yes
|
|
|
|
set mbox_type = ${if maildir != null then "Maildir" else "mbox"}
|
|
|
|
set sort = "${cfg.sort}"
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
# MTA section
|
|
|
|
${optionsStr (mtaSection account)}
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
${optionalString (cfg.checkStatsInterval != null) mailCheckSection}
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
${optionalString cfg.sidebar.enable sidebarSection}
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
# MRA section
|
|
|
|
${mraSection account}
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
# Extra configuration
|
|
|
|
${account.neomutt.extraConfig}
|
|
|
|
'' + optionalString (account.signature.showSignature != "none") ''
|
|
|
|
set signature = ${pkgs.writeText "signature.txt" account.signature.text}
|
|
|
|
'' + optionalString account.notmuch.enable (notmuchSection account);
|
2020-01-22 00:52:01 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2020-01-22 00:52:01 +01:00
|
|
|
options = {
|
|
|
|
programs.neomutt = {
|
|
|
|
enable = mkEnableOption "the NeoMutt mail client";
|
|
|
|
|
|
|
|
sidebar = mkOption {
|
|
|
|
type = sidebarModule;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2020-01-22 00:52:01 +01:00
|
|
|
description = "Options related to the sidebar.";
|
|
|
|
};
|
|
|
|
|
|
|
|
binds = mkOption {
|
|
|
|
type = types.listOf bindModule;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2020-01-22 00:52:01 +01:00
|
|
|
description = "List of keybindings.";
|
|
|
|
};
|
|
|
|
|
|
|
|
macros = mkOption {
|
|
|
|
type = types.listOf bindModule;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2020-01-22 00:52:01 +01:00
|
|
|
description = "List of macros.";
|
|
|
|
};
|
|
|
|
|
|
|
|
sort = mkOption {
|
2020-02-21 15:24:52 +01:00
|
|
|
# allow users to choose any option from sortOptions, or any option prefixed with "reverse-"
|
|
|
|
type = types.enum
|
|
|
|
(sortOptions ++ (map (option: "reverse-" + option) sortOptions));
|
2020-01-22 00:52:01 +01:00
|
|
|
default = "threads";
|
|
|
|
description = "Sorting method on messages.";
|
|
|
|
};
|
|
|
|
|
|
|
|
vimKeys = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Enable vim-like bindings.";
|
|
|
|
};
|
|
|
|
|
|
|
|
checkStatsInterval = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 60;
|
|
|
|
description = "Enable and set the interval of automatic mail check.";
|
|
|
|
};
|
|
|
|
|
|
|
|
editor = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$EDITOR";
|
|
|
|
description = "Select the editor used for writing mail.";
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2020-01-22 00:52:01 +01:00
|
|
|
description = "Extra configuration appended to the end.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra configuration appended to the end.";
|
|
|
|
};
|
|
|
|
};
|
2020-06-16 00:45:20 +02:00
|
|
|
|
|
|
|
accounts.email.accounts = mkOption {
|
|
|
|
type = with types; attrsOf (submodule (import ./neomutt-accounts.nix));
|
|
|
|
};
|
2020-01-22 00:52:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ pkgs.neomutt ];
|
|
|
|
home.file = let
|
|
|
|
rcFile = account: {
|
|
|
|
"${accountFilename account}".text = accountStr account;
|
|
|
|
};
|
2020-02-02 00:39:17 +01:00
|
|
|
in foldl' (a: b: a // b) { } (map rcFile neomuttAccounts);
|
|
|
|
|
|
|
|
xdg.configFile."neomutt/neomuttrc" = mkIf (neomuttAccounts != [ ]) {
|
2021-03-29 06:44:47 +02:00
|
|
|
text = let
|
|
|
|
# Find the primary account, if it has neomutt enabled;
|
|
|
|
# otherwise use the first neomutt account as primary.
|
|
|
|
primary =
|
|
|
|
head (filter (a: a.primary) neomuttAccounts ++ neomuttAccounts);
|
2020-02-02 00:39:17 +01:00
|
|
|
in ''
|
|
|
|
# Generated by Home Manager.
|
|
|
|
set header_cache = "${config.xdg.cacheHome}/neomutt/headers/"
|
|
|
|
set message_cachedir = "${config.xdg.cacheHome}/neomutt/messages/"
|
|
|
|
set editor = "${cfg.editor}"
|
|
|
|
set implicit_autoview = yes
|
|
|
|
|
|
|
|
alternative_order text/enriched text/plain text
|
|
|
|
|
|
|
|
set delete = yes
|
|
|
|
|
|
|
|
# Binds
|
|
|
|
${bindSection}
|
|
|
|
|
|
|
|
# Macros
|
|
|
|
${macroSection}
|
|
|
|
|
|
|
|
${optionalString cfg.vimKeys
|
|
|
|
"source ${pkgs.neomutt}/share/doc/neomutt/vim-keys/vim-keys.rc"}
|
|
|
|
|
|
|
|
# Extra configuration
|
|
|
|
${optionsStr cfg.settings}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
2021-03-29 06:44:47 +02:00
|
|
|
|
|
|
|
# Register accounts
|
|
|
|
${concatMapStringsSep "\n" registerAccount neomuttAccounts}
|
|
|
|
|
|
|
|
# Source primary account
|
|
|
|
source ${accountFilename primary}
|
|
|
|
'';
|
2020-01-22 00:52:01 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|