126 lines
4.1 KiB
Nix
126 lines
4.1 KiB
Nix
{
|
|
pkgs,
|
|
lib,
|
|
config,
|
|
dots,
|
|
home-dir,
|
|
xdg-config-dir,
|
|
...
|
|
}:
|
|
|
|
{
|
|
options.custom.email = with lib; {
|
|
enable = mkEnableOption "Enable email";
|
|
davmail = mkEnableOption "Enable DavMail";
|
|
mbsync = mkEnableOption "Enable Mbsync";
|
|
neomutt = mkEnableOption "Enable NeoMutt";
|
|
notmuch = mkEnableOption "Enable notmuch";
|
|
mu = mkEnableOption "Enable mu (maildir-utils)";
|
|
mailcap = mkEnableOption "Enable mailcap";
|
|
};
|
|
|
|
config = lib.mkIf config.custom.email.enable {
|
|
# DavMail service (Exchange gateway)
|
|
services.davmail = {
|
|
enable = config.custom.email.davmail;
|
|
configFile =
|
|
if pkgs.stdenv.isDarwin then
|
|
"${dots}/config/davmail/davmail.darwin.properties"
|
|
else
|
|
"${dots}/config/davmail/davmail.linux.properties";
|
|
};
|
|
|
|
# Mbsync service (mail sync)
|
|
services.mbsync = {
|
|
enable = config.custom.email.mbsync;
|
|
configFile = "${dots}/config/mbsync/mbsyncrc";
|
|
frequency = "*:0/3";
|
|
extraPackages =
|
|
with pkgs;
|
|
[ sops ]
|
|
++ lib.optionals config.custom.email.notmuch [ notmuch ]
|
|
++ lib.optionals config.custom.email.mu [ mu ];
|
|
postExec =
|
|
let
|
|
notmuchCmd = lib.optionalString config.custom.email.notmuch "${pkgs.notmuch}/bin/notmuch new";
|
|
muCmd = lib.optionalString config.custom.email.mu ''
|
|
# Initialize mu if not already done
|
|
if [ ! -d "${home-dir}/.cache/mu" ] && [ ! -d "${home-dir}/.mu" ]; then
|
|
${pkgs.mu}/bin/mu init --maildir=${home-dir}/mail --my-address=rayandrew@uchicago.edu --my-address=raydreww@gmail.com
|
|
fi
|
|
${pkgs.mu}/bin/mu index
|
|
'';
|
|
in
|
|
lib.mkIf (config.custom.email.notmuch || config.custom.email.mu) ''
|
|
${notmuchCmd}
|
|
${muCmd}
|
|
'';
|
|
environment = {
|
|
SOPS_AGE_KEY_FILE = "${xdg-config-dir}/sops/age/keys.txt";
|
|
}
|
|
// lib.optionalAttrs config.custom.email.notmuch {
|
|
NOTMUCH_CONFIG = "${xdg-config-dir}/notmuch/config";
|
|
};
|
|
};
|
|
|
|
# Install mail-related packages
|
|
home.packages =
|
|
with pkgs;
|
|
[
|
|
isync # mbsync
|
|
msmtp
|
|
sops # for password decryption
|
|
age # for sops age backend
|
|
]
|
|
++ lib.optionals config.custom.email.neomutt [
|
|
# Wrapper script for neomutt with truecolor support
|
|
(writeShellScriptBin "neomutt" ''
|
|
exec env TERM=xterm-direct ${neomutt}/bin/neomutt "$@"
|
|
'')
|
|
]
|
|
++ lib.optionals config.custom.email.notmuch [
|
|
notmuch
|
|
]
|
|
++ lib.optionals config.custom.email.mu [
|
|
mu
|
|
]
|
|
++ lib.optionals config.custom.email.mailcap [
|
|
mailcap
|
|
w3m # HTML rendering
|
|
zathura # PDF viewer
|
|
chafa # terminal image viewer
|
|
bat # text viewer with syntax highlighting
|
|
mblaze # mshow for email viewing
|
|
ripmime # extract MIME parts from emails
|
|
];
|
|
|
|
# Symlink config files
|
|
xdg.configFile = {
|
|
"msmtp".source = config.lib.file.mkOutOfStoreSymlink "${dots}/config/msmtp";
|
|
"neomutt".source = config.lib.file.mkOutOfStoreSymlink "${dots}/config/neomutt";
|
|
"isyncrc".source = config.lib.file.mkOutOfStoreSymlink "${dots}/config/mbsync/mbsyncrc";
|
|
}
|
|
// lib.optionalAttrs config.custom.email.notmuch {
|
|
"notmuch/config".source = config.lib.file.mkOutOfStoreSymlink "${dots}/config/notmuch/config";
|
|
};
|
|
|
|
# mailcap symlink
|
|
home.file = lib.mkIf config.custom.email.mailcap {
|
|
".mailcap".source = config.lib.file.mkOutOfStoreSymlink "${dots}/config/home/.mailcap";
|
|
};
|
|
|
|
# Create mail directories
|
|
home.activation.createMailDirs = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
|
mkdir -p ${home-dir}/mail/personal/Inbox
|
|
mkdir -p ${home-dir}/mail/uchicago/Inbox
|
|
mkdir -p ${home-dir}/.cache/neomutt/headers
|
|
mkdir -p ${home-dir}/.cache/neomutt/messages
|
|
mkdir -p ${home-dir}/.local/state
|
|
'';
|
|
|
|
# Set NOTMUCH_CONFIG environment variable
|
|
custom.environment.variables = lib.mkIf config.custom.email.notmuch {
|
|
NOTMUCH_CONFIG = "${xdg-config-dir}/notmuch/config";
|
|
};
|
|
};
|
|
}
|