From 0981b6c089b483b4ecddceeffe89ed3f38561fb2 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Sun, 27 Sep 2026 04:16:50 +0530 Subject: feat(communication/neomutt): the first sync after opening neomutt is quick --- modules/communication/neomutt/default.nix | 18 ++++++++++++++++-- .../communication/neomutt/neomutt-sync-daemon.sh | 22 +++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'modules/communication/neomutt') diff --git a/modules/communication/neomutt/default.nix b/modules/communication/neomutt/default.nix index 6c11b03..e8915d9 100644 --- a/modules/communication/neomutt/default.nix +++ b/modules/communication/neomutt/default.nix @@ -15,6 +15,10 @@ let lib.filterAttrs (name: account: account.enable) cfg.accounts ); + quickSyncChannels = lib.mapAttrsToList (name: account: (mbsyncNamesFromName name).channels.quick) ( + lib.filterAttrs (name: account: account.enable) cfg.accounts + ); + neomuttSyncScript = pkgs.writeShellApplication { name = "neomutt-sync"; runtimeInputs = [ @@ -39,7 +43,17 @@ let config.programs.mbsync.package config.programs.notmuch.package ]; - text = builtins.readFile ./neomutt-sync-daemon.sh; + text = + builtins.replaceStrings + [ + "@@QUICK_CHANNELS@@" + "@@FULL_CHANNELS@@" + ] + [ + (lib.concatStringsSep "," quickSyncChannels) + (lib.concatStringsSep "," fullSyncChannels) + ] + (builtins.readFile ./neomutt-sync-daemon.sh); }; neomuttLauncher = pkgs.writeShellApplication { @@ -136,7 +150,7 @@ in }; Service = { Type = "simple"; - ExecStart = "${lib.getExe neomuttSyncDaemon} ${lib.concatStringsSep " " fullSyncChannels}"; + ExecStart = lib.getExe neomuttSyncDaemon; }; }; }) diff --git a/modules/communication/neomutt/neomutt-sync-daemon.sh b/modules/communication/neomutt/neomutt-sync-daemon.sh index d148567..301eb98 100644 --- a/modules/communication/neomutt/neomutt-sync-daemon.sh +++ b/modules/communication/neomutt/neomutt-sync-daemon.sh @@ -1,16 +1,17 @@ #!/usr/bin/env bash -# systemd daemon: full-sync the -full channels every 10 minutes while -# neomutt is open. Started/stopped by the wrapped neomutt launcher. +# systemd daemon: sync quick channels on first run, then full channels every 10 minutes +# while neomutt is open. Started/stopped by the wrapped neomutt launcher. set -uo pipefail INTERVAL="$((10 * 60))" MBSYNCRC="${MBSYNCRC:-$HOME/.config/mbsync/.mbsyncrc}" -if [[ $# -eq 0 ]]; then - echo "Usage: $0 [channel...]" >&2 - exit 2 -fi +QUICK_CHANNELS_STR="@@QUICK_CHANNELS@@" +FULL_CHANNELS_STR="@@FULL_CHANNELS@@" + +IFS=',' read -ra QUICK_CHANNELS <<<"$QUICK_CHANNELS_STR" +IFS=',' read -ra FULL_CHANNELS <<<"$FULL_CHANNELS_STR" sync_once() { echo "Syncing: $*" @@ -26,8 +27,15 @@ sync_once() { notmuch new --quiet } +first_run=true + while true; do - sync_once "$@" + if [[ $first_run == true ]]; then + sync_once "${QUICK_CHANNELS[@]}" + first_run=false + else + sync_once "${FULL_CHANNELS[@]}" + fi # Safety net: the launcher stops this service when neomutt exits; if that # didn't happen (hard kill), bail out once neomutt is gone. -- cgit v1.2.3