From baae94abb6a9a03914216f0f373b7b0f6b0207bd Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Sat, 19 Sep 2026 01:40:50 +0530 Subject: chore: removed all raw string configurations options in favor of files Moved all configurations which were previously raw strings chunks, for options that the home-manager options didn't provide, into files for that specific configuration and reading there contents instead (with string replacement for passing information from the rest of the configuration). --- modules/communication/neomutt/.neomuttrc | 7 ++++ modules/communication/neomutt/account/.muttrc | 2 + modules/communication/neomutt/account/default.nix | 2 +- .../neomutt/account/flavors/gmail.nix | 45 ---------------------- .../neomutt/account/flavors/gmail/.muttrc | 2 + .../neomutt/account/flavors/gmail/default.nix | 42 ++++++++++++++++++++ .../communication/neomutt/account/sync-channel.nix | 13 ++++--- modules/communication/neomutt/default.nix | 24 +++--------- modules/communication/neomutt/mailcap | 6 +++ 9 files changed, 74 insertions(+), 69 deletions(-) create mode 100644 modules/communication/neomutt/account/.muttrc delete mode 100644 modules/communication/neomutt/account/flavors/gmail.nix create mode 100644 modules/communication/neomutt/account/flavors/gmail/.muttrc create mode 100644 modules/communication/neomutt/account/flavors/gmail/default.nix create mode 100644 modules/communication/neomutt/mailcap (limited to 'modules/communication') diff --git a/modules/communication/neomutt/.neomuttrc b/modules/communication/neomutt/.neomuttrc index 3ed08f9..2f7ef00 100644 --- a/modules/communication/neomutt/.neomuttrc +++ b/modules/communication/neomutt/.neomuttrc @@ -1,3 +1,10 @@ +# Read messages in Neovim. `-` makes Neovim read the message from +# stdin and -R prevents accidental edits to message content. +set pager = "@@PAGER@@ -R -n +'setlocal nolist | silent! 1,2g/^$/delete _ | nohlsearch | setlocal nomodified nomodifiable' -" +# Return directly to the index when Neovim exits and do not prepend +# NeoMutt’s pager status line to the message passed to Neovim. +set noprompt_after +set pager_format = "" # Base16 OneDark Dark terminal colors for neomutt # Each column in the index receives a distinct color to keep the UI organized. diff --git a/modules/communication/neomutt/account/.muttrc b/modules/communication/neomutt/account/.muttrc new file mode 100644 index 0000000..2f8c9f2 --- /dev/null +++ b/modules/communication/neomutt/account/.muttrc @@ -0,0 +1,2 @@ +macro index,pager gs "set my_wait_key=$wait_key wait_key=noneomutt-sync @@QUICK_CHANNEL@@set wait_key=$my_wait_key" +macro index,pager gS "set my_wait_key=$wait_key wait_key=noneomutt-sync @@FULL_CHANNEL@@set wait_key=$my_wait_key" diff --git a/modules/communication/neomutt/account/default.nix b/modules/communication/neomutt/account/default.nix index 5c0f8bf..e2d92eb 100644 --- a/modules/communication/neomutt/account/default.nix +++ b/modules/communication/neomutt/account/default.nix @@ -9,8 +9,8 @@ type = lib.types.attrsOf ( lib.types.submodule { imports = [ + ./flavors/gmail ./options.nix - ./flavors/gmail.nix ./sync-channel.nix ]; } diff --git a/modules/communication/neomutt/account/flavors/gmail.nix b/modules/communication/neomutt/account/flavors/gmail.nix deleted file mode 100644 index 9cb51b2..0000000 --- a/modules/communication/neomutt/account/flavors/gmail.nix +++ /dev/null @@ -1,45 +0,0 @@ -# Gmail-specific defaults for folder names, mbsync patterns, and mailboxes -{ - config, - lib, - name, - ... -}: -{ - config = lib.mkIf (config.flavor == "gmail.com") { - folders = { - inbox = lib.mkDefault "Inbox"; - drafts = lib.mkDefault "[Gmail]/Drafts"; - sent = lib.mkDefault "[Gmail]/Sent Mail"; - trash = lib.mkDefault "[Gmail]/Trash"; - }; - - mbsync = { - create = lib.mkDefault "maildir"; - patterns = lib.mkDefault [ - "INBOX" - "[Gmail]/Drafts" - "[Gmail]/Sent Mail" - "[Gmail]/Spam" - ]; - extraConfig.channel = { - Sync = lib.mkDefault "All"; - CopyArrivalDate = lib.mkDefault "yes"; - Expunge = lib.mkDefault "Both"; - SyncState = lib.mkDefault "*"; - }; - }; - - neomutt.extraConfig = lib.mkBefore '' - mailboxes =Inbox ="[Gmail]/Drafts" ="[Gmail]/Sent Mail" ="[Gmail]/Spam" ="[Gmail]/Trash" - unset record - ''; - - notmuch.neomutt.virtualMailboxes = lib.mkDefault [ - { - name = "All Mail"; - query = "folder:${name}/Inbox or folder:\"${name}/[Gmail]/Sent Mail\""; - } - ]; - }; -} diff --git a/modules/communication/neomutt/account/flavors/gmail/.muttrc b/modules/communication/neomutt/account/flavors/gmail/.muttrc new file mode 100644 index 0000000..c87bba0 --- /dev/null +++ b/modules/communication/neomutt/account/flavors/gmail/.muttrc @@ -0,0 +1,2 @@ +mailboxes =Inbox ="[Gmail]/Drafts" ="[Gmail]/Sent Mail" ="[Gmail]/Spam" ="[Gmail]/Trash" +unset record diff --git a/modules/communication/neomutt/account/flavors/gmail/default.nix b/modules/communication/neomutt/account/flavors/gmail/default.nix new file mode 100644 index 0000000..66d7db3 --- /dev/null +++ b/modules/communication/neomutt/account/flavors/gmail/default.nix @@ -0,0 +1,42 @@ +# Gmail-specific defaults for folder names, mbsync patterns, and mailboxes +{ + config, + lib, + name, + ... +}: +{ + config = lib.mkIf (config.flavor == "gmail.com") { + folders = { + inbox = lib.mkDefault "Inbox"; + drafts = lib.mkDefault "[Gmail]/Drafts"; + sent = lib.mkDefault "[Gmail]/Sent Mail"; + trash = lib.mkDefault "[Gmail]/Trash"; + }; + + mbsync = { + create = lib.mkDefault "maildir"; + patterns = lib.mkDefault [ + "INBOX" + "[Gmail]/Drafts" + "[Gmail]/Sent Mail" + "[Gmail]/Spam" + ]; + extraConfig.channel = { + Sync = lib.mkDefault "All"; + CopyArrivalDate = lib.mkDefault "yes"; + Expunge = lib.mkDefault "Both"; + SyncState = lib.mkDefault "*"; + }; + }; + + neomutt.extraConfig = lib.mkBefore (builtins.readFile ./.muttrc); + + notmuch.neomutt.virtualMailboxes = lib.mkDefault [ + { + name = "All Mail"; + query = "folder:${name}/Inbox or folder:\"${name}/[Gmail]/Sent Mail\""; + } + ]; + }; +} diff --git a/modules/communication/neomutt/account/sync-channel.nix b/modules/communication/neomutt/account/sync-channel.nix index 7e538f2..6f3bd54 100644 --- a/modules/communication/neomutt/account/sync-channel.nix +++ b/modules/communication/neomutt/account/sync-channel.nix @@ -3,7 +3,7 @@ lib, name, ... -}@inputs: +}: let mbsyncNamesFromName = (import ../lib.nix { inherit lib; }).mbsyncNamesFromName; @@ -14,9 +14,12 @@ in let mbsyncNames = mbsyncNamesFromName name; in - '' - macro index,pager gs "set my_wait_key=$wait_key wait_key=noneomutt-sync ${mbsyncNames.channels.quick}set wait_key=$my_wait_key" - macro index,pager gS "set my_wait_key=$wait_key wait_key=noneomutt-sync ${mbsyncNames.channels.full}set wait_key=$my_wait_key" - ''; + builtins.replaceStrings + [ "@@QUICK_CHANNEL@@" "@@FULL_CHANNEL@@" ] + [ + mbsyncNames.channels.quick + mbsyncNames.channels.full + ] + (builtins.readFile ./.muttrc); }; } diff --git a/modules/communication/neomutt/default.nix b/modules/communication/neomutt/default.nix index 84e6c61..b9f22e0 100644 --- a/modules/communication/neomutt/default.nix +++ b/modules/communication/neomutt/default.nix @@ -79,14 +79,9 @@ in xdg.mimeApps.defaultApplications = { "x-scheme-handler/mailto" = "neomutt.desktop"; }; - xdg.configFile."neomutt/mailcap".text = '' - text/html; ${lib.getExe config.web.chawan.package} '%s'; nametemplate=%s.html - image/*; xdg-open '%s' & - application/pdf; xdg-open '%s'; nametemplate=%s.pdf - video/*; xdg-open '%s' & - audio/*; xdg-open '%s' & - application/*; xdg-open '%s' & - ''; + xdg.configFile."neomutt/mailcap".text = + builtins.replaceStrings [ "@@HTML_VIEWER@@" ] [ (lib.getExe config.web.chawan.package) ] + (builtins.readFile ./mailcap); programs.neomutt = { enable = true; package = pkgs.symlinkJoin { @@ -107,16 +102,9 @@ in vimKeys = false; unmailboxes = true; checkStatsInterval = 20; - extraConfig = '' - # Read messages in Neovim. `-` makes Neovim read the message from - # stdin and -R prevents accidental edits to message content. - set pager = "${lib.getExe config.development.nixvim.package} -R -n +'setlocal nolist | silent! 1,2g/^$/delete _ | nohlsearch | setlocal nomodified nomodifiable' -" - # Return directly to the index when Neovim exits and do not prepend - # NeoMutt’s pager status line to the message passed to Neovim. - set noprompt_after - set pager_format = "" - '' - + builtins.readFile ./.neomuttrc; + extraConfig = + builtins.replaceStrings [ "@@PAGER@@" ] [ (lib.getExe config.development.nixvim.package) ] + (builtins.readFile ./.neomuttrc); }; }; } diff --git a/modules/communication/neomutt/mailcap b/modules/communication/neomutt/mailcap new file mode 100644 index 0000000..3af2794 --- /dev/null +++ b/modules/communication/neomutt/mailcap @@ -0,0 +1,6 @@ +text/html; @@HTML_VIEWER@@ '%s'; nametemplate=%s.html +image/*; xdg-open '%s' & +application/pdf; xdg-open '%s'; nametemplate=%s.pdf +video/*; xdg-open '%s' & +audio/*; xdg-open '%s' & +application/*; xdg-open '%s' & -- cgit v1.2.3