WIP: neomutt #31

Closed
simon wants to merge 3 commits from neomutt into master
2 changed files with 216 additions and 0 deletions

View File

@ -2,6 +2,7 @@
imports = [
./alacritty.nix
./anki
./email.nix
./games.nix
./ghci.nix
./git.nix

View File

@ -0,0 +1,215 @@
{ config, lib, pkgs, ... }:
let
virtualMailboxes = {
#"One Month" = "date:30days..today";
"FabLab" = "body:fablab";
"Git" = "from:{.*@github.com or .*@gitlab.com or no-reply+gitea@sbruder.de}'";
};
mkVirtualMailbox = name: searchTerm: ''
virtual-mailboxes "${name}" "notmuch://?query=${searchTerm}"
'';
mutt-solarized-dark = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/altercation/mutt-colors-solarized/b1520c6bf1ab49538439514c9393ff69df8591b4/mutt-colors-solarized-dark-16.muttrc";
sha256 = "0lji8lds9xqj3j5qpn5554rk8gqx72mc6dc57j3j3kb20xvnq5cx";
meta.license = lib.licenses.mit;
};
in
{
accounts.email = {
maildirBasePath = "${config.xdg.dataHome}/mail";
accounts = {
personal = rec {
primary = true;
realName = "Simon Bruder";
address = "simon@sbruder.de";
aliases = [ ]; # FIXME!?
userName = address;
passwordCommand = "pass sbruder.de/account | head -n 1";
imap = {
host = "home.sbruder.de";
tls.useStartTls = true;
};
smtp = {
host = "home.sbruder.de";
tls.useStartTls = true;
};
gpg = {
key = config.programs.gpg.settings.default-key;
signByDefault = true;
encryptByDefault = true;
};
msmtp.enable = true;
mbsync = {
enable = true;
#flatten = ".";
create = "both";
expunge = "both";
};
neomutt.enable = true;
notmuch.enable = true;
};
};
};
# I am not using the home-manger neomutt module, since it includes many
# opinionated, not-overridable defaults that I do not want
home.packages = with pkgs; [ neomutt ];
xdg.configFile."neomutt/neomuttrc".text =
let
# adapted from home-manager
stringifyValue = value:
if lib.isBool value
then (if value then "yes" else "no")
else "'${toString value}'";
stringifySetOption = option: value:
if value == null
then "unset ${option}"
else "set ${option}=${stringifyValue value}";
stringifyOptions = options: lib.concatStringsSep
"\n"
(lib.mapAttrsToList stringifySetOption options);
stringifyBinds = binds: lib.concatMapStringsSep
"\n"
(bind:
let map' =
if (lib.isList bind.map)
then (lib.concatStringsSep "," bind.map)
else bind.map;
in
''bind ${map'} ${bind.key} "${bind.action}"'')
binds;
stringifySources = files: lib.concatMapStringsSep
"\n"
(file: "source ${file}")
files;
neomuttAccounts = lib.filter (a: a.neomutt.enable) (lib.attrValues config.accounts.email.accounts);
settings = {
# FIXME: comment all non-obvious
header_cache = "${config.xdg.cacheHome}/neomutt/headers/";
message_cachedir = "${config.xdg.cacheHome}/neomutt/messages/";
# General
implicit_autoview = true; # automatically view with program from mailcap
delete = true; # do not ask before deleting
mail_check_stats = true;
# Sidebar
sidebar_visible = true;
sidebar_folder_indent = true;
sidebar_format = "%D%?F? [%F]?%* %?N?%N/?%S";
sidebar_short_path = true;
sidebar_width = 22;
sidebar_delim_chars = "/";
# Editor
edit_headers = true;
reverse_name = true;
include = true;
# GPG
crypt_use_gpgme = true;
crypt_autosign = true;
pgp_use_gpg_agent = true;
mbox_type = "Maildir";
sort = "threads";
sendmail = "msmtpq --read-envelope-from --read-recipients";
# Defaults for all accounts
folder = config.accounts.email.maildirBasePath;
spoolfile = "notmuch://?query=tag:inbox";
#from = config.accounts.email.accounts.personal.address;
#postponed = "+Drafts";
#realname = "Simon Bruder";
#record = "+Sent";
#trash = "+Trash";
signature = pkgs.writeText "signature" ''
Simon Bruder
🔑 (GPG): 47E7 559E 037A 3565 2DBB F8AA 8D3C 82F9 F309 F8EC
📧 (E-Mail): simon@sbruder.de
📱 (mobile): +49 152 56561414
'';
# notmuch
nm_default_uri = "notmuch:///home/simon/.local/share/mail";
mailcap_path = pkgs.writeText "mutt-mailcap" ''
text/html; ${config.xdg.mimeApps.defaultApplications."text/html"} %s
text/html; ${pkgs.w3m}/bin/w3m -I %{charset} -T text/html -dump; copiousoutput;
application/pdf; zathura %s
image/*; mpv %s
'';
pgp_default_key = config.programs.gpg.settings.default-key;
nm_query_type = "threads";
};
binds = [
{ map = "index"; key = "\\\\"; action = "vfolder-from-query"; }
{ map = [ "index" "pager" ]; key = "J"; action = "sidebar-next"; }
{ map = [ "index" "pager" ]; key = "K"; action = "sidebar-prev"; }
{ map = [ "index" "pager" ]; key = "S"; action = "sidebar-open"; }
];
sources = [
mutt-solarized-dark
];
in
''
alternative_order text/enriched text/plain text
${stringifyBinds binds}
# Macros
#{macroSection}
#"source ${pkgs.neomutt}/share/doc/neomutt/vim-keys/vim-keys.rc"
${stringifyOptions settings}
${stringifySources sources}
${mkVirtualMailbox "Inbox" "tag:inbox"}
${lib.concatStringsSep
"\n"
(lib.mapAttrsToList mkVirtualMailbox virtualMailboxes)}
#mailboxes ="==================="
'' + lib.concatMapStringsSep "\n"
(account: with account; ''
# Account ${name}
# FIXME
named-mailboxes "== ${name} ==" +${name}/${folders.inbox}
mailboxes =${name}/${folders.inbox}
mailboxes =${name}/${folders.sent}
mailboxes =${name}/${folders.drafts}
mailboxes =${name}/${folders.trash}
'')
neomuttAccounts;
programs.mbsync.enable = true;
programs.msmtp.enable = true;
programs.notmuch = {
enable = true;
hooks = {
preNew = ''
mbsync --all
'';
};
};
}