From 342d5376215714d60c80c6822f4e7706310138e0 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 18 Jan 2021 00:16:08 +0100 Subject: [PATCH 1/3] WIP: Add neomutt --- users/simon/modules/default.nix | 1 + users/simon/modules/email.nix | 141 ++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 users/simon/modules/email.nix diff --git a/users/simon/modules/default.nix b/users/simon/modules/default.nix index e7c44d3..033b06d 100644 --- a/users/simon/modules/default.nix +++ b/users/simon/modules/default.nix @@ -2,6 +2,7 @@ imports = [ ./alacritty.nix ./anki + ./email.nix ./games.nix ./ghci.nix ./git.nix diff --git a/users/simon/modules/email.nix b/users/simon/modules/email.nix new file mode 100644 index 0000000..cbabb91 --- /dev/null +++ b/users/simon/modules/email.nix @@ -0,0 +1,141 @@ +{ config, lib, pkgs, ... }: +let + virtualMailboxes = { + "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; + }; + + signature = { + showSignature = "append"; + text = '' + Simon Bruder + + 🔑 (GPG): 47E7 559E 037A 3565 2DBB F8AA 8D3C 82F9 F309 F8EC + 📧 (E-Mail): simon@sbruder.de + 📱 (mobile): +49 152 56561414 + ''; + }; + + gpg = { + key = config.programs.gpg.settings.default-key; + signByDefault = true; + encryptByDefault = true; + }; + + msmtp.enable = true; + mbsync = { + enable = true; + #flatten = "."; + create = "both"; + expunge = "both"; + }; + #mu.enable = true; + neomutt = { + enable = true; + extraConfig = let account = config.accounts.email.accounts.personal; in + '' + # revert home-manager setting + unmailboxes "${account.maildir.absPath}/${account.folders.inbox}" + unvirtual-mailboxes "My INBOX" + ''; + }; + notmuch.enable = true; + }; + }; + }; + + programs.neomutt = { + enable = true; + + sidebar = { + enable = true; + format = "%B%?F? [%F]?%* %?N?%N/?%S"; + }; + + binds = [ + { map = "index"; key = "\\\\"; action = "vfolder-from-query"; } + ]; + + extraConfig = '' + source ${mutt-solarized-dark} + + ${mkVirtualMailbox "Inbox" "tag:inbox"} + ${lib.concatStringsSep + "\n" + (lib.attrValues + (lib.mapAttrs mkVirtualMailbox virtualMailboxes))} + ''; + + # somehow makes not work (?) + #vimKeys = true; + settings = { + wait_key = "yes"; + timeout = "3"; + quit = "yes"; + mail_check_stats = "yes"; + + edit_headers = "yes"; + reverse_name = "yes"; + include = "yes"; + + mailcap_path = toString (pkgs.writeText "mutt-mailcap" '' + text/html; firefox %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"; + }; + }; + + programs.mbsync.enable = true; + programs.msmtp.enable = true; + #programs.mu.enable = true; + programs.notmuch = { + enable = true; + hooks = { + preNew = '' + mbsync --all + ''; + }; + }; +} -- 2.42.0 From 9f7355f97ca3cbcaea208680737657ecc8d696af Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 18 Jan 2021 21:42:44 +0100 Subject: [PATCH 2/3] dreckiger commit --- users/simon/modules/email.nix | 196 +++++++++++++++++++++++----------- 1 file changed, 135 insertions(+), 61 deletions(-) diff --git a/users/simon/modules/email.nix b/users/simon/modules/email.nix index cbabb91..4c138a3 100644 --- a/users/simon/modules/email.nix +++ b/users/simon/modules/email.nix @@ -1,6 +1,7 @@ { 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}'"; }; @@ -41,17 +42,6 @@ in tls.useStartTls = true; }; - signature = { - showSignature = "append"; - text = '' - Simon Bruder - - 🔑 (GPG): 47E7 559E 037A 3565 2DBB F8AA 8D3C 82F9 F309 F8EC - 📧 (E-Mail): simon@sbruder.de - 📱 (mobile): +49 152 56561414 - ''; - }; - gpg = { key = config.programs.gpg.settings.default-key; signByDefault = true; @@ -65,71 +55,155 @@ in create = "both"; expunge = "both"; }; - #mu.enable = true; - neomutt = { - enable = true; - extraConfig = let account = config.accounts.email.accounts.personal; in - '' - # revert home-manager setting - unmailboxes "${account.maildir.absPath}/${account.folders.inbox}" - unvirtual-mailboxes "My INBOX" - ''; - }; + neomutt.enable = true; notmuch.enable = true; }; }; }; - programs.neomutt = { - 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); - sidebar = { - enable = true; - format = "%B%?F? [%F]?%* %?N?%N/?%S"; - }; + 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; - binds = [ - { map = "index"; key = "\\\\"; action = "vfolder-from-query"; } - ]; + stringifySources = files: lib.concatMapStringsSep + "\n" + (file: "source ${file}") + files; - extraConfig = '' - source ${mutt-solarized-dark} + 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; firefox %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.attrValues - (lib.mapAttrs mkVirtualMailbox virtualMailboxes))} - ''; - - # somehow makes not work (?) - #vimKeys = true; - settings = { - wait_key = "yes"; - timeout = "3"; - quit = "yes"; - mail_check_stats = "yes"; - - edit_headers = "yes"; - reverse_name = "yes"; - include = "yes"; - - mailcap_path = toString (pkgs.writeText "mutt-mailcap" '' - text/html; firefox %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"; - }; - }; + (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.mu.enable = true; programs.notmuch = { enable = true; hooks = { -- 2.42.0 From b826fe24eaeaf753b6c32958397a55ec006f398a Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 22 Jan 2022 10:22:34 +0100 Subject: [PATCH 3/3] generic browser --- users/simon/modules/email.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/simon/modules/email.nix b/users/simon/modules/email.nix index 4c138a3..aa8d72d 100644 --- a/users/simon/modules/email.nix +++ b/users/simon/modules/email.nix @@ -150,7 +150,7 @@ in nm_default_uri = "notmuch:///home/simon/.local/share/mail"; mailcap_path = pkgs.writeText "mutt-mailcap" '' - text/html; firefox %s + 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 -- 2.42.0