2024-04-20 13:42:06 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
./himalaya.nix
|
|
|
|
./aerc.nix
|
|
|
|
./system.nix
|
|
|
|
];
|
2022-10-30 17:57:14 +00:00
|
|
|
|
|
|
|
options = {
|
2022-12-22 00:31:25 +00:00
|
|
|
mail.enable = lib.mkEnableOption "Mail service.";
|
2022-12-21 21:18:03 +00:00
|
|
|
mail.user = lib.mkOption {
|
2022-10-30 17:57:14 +00:00
|
|
|
type = lib.types.str;
|
|
|
|
description = "User name for the email address.";
|
|
|
|
default = config.user;
|
|
|
|
};
|
2022-12-21 21:18:03 +00:00
|
|
|
mail.server = lib.mkOption {
|
2023-03-12 21:07:41 +00:00
|
|
|
type = lib.types.nullOr lib.types.str;
|
2022-10-30 17:57:14 +00:00
|
|
|
description = "Server name for the email address.";
|
|
|
|
};
|
2023-03-12 21:07:41 +00:00
|
|
|
mail.imapHost = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
description = "Server host for IMAP (reading mail).";
|
|
|
|
};
|
|
|
|
mail.smtpHost = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
description = "Server host for SMTP (sending mail).";
|
|
|
|
};
|
2022-10-30 17:57:14 +00:00
|
|
|
};
|
|
|
|
|
2022-12-22 00:31:25 +00:00
|
|
|
config = lib.mkIf config.mail.enable {
|
2022-10-30 17:57:14 +00:00
|
|
|
|
|
|
|
home-manager.users.${config.user} = {
|
2024-04-20 13:42:06 +00:00
|
|
|
programs.mbsync = {
|
|
|
|
enable = true;
|
|
|
|
};
|
2023-07-30 03:56:41 +00:00
|
|
|
|
|
|
|
# Automatically check for mail and keep files synced locally
|
2023-04-04 00:36:05 +00:00
|
|
|
services.mbsync = lib.mkIf pkgs.stdenv.isLinux {
|
|
|
|
enable = true;
|
|
|
|
frequency = "*:0/5";
|
|
|
|
postExec = "${pkgs.notmuch}/bin/notmuch new";
|
|
|
|
};
|
2023-07-30 03:56:41 +00:00
|
|
|
|
|
|
|
# Used to watch for new mail and trigger sync
|
2023-04-15 16:58:37 +00:00
|
|
|
services.imapnotify.enable = pkgs.stdenv.isLinux;
|
2023-07-30 03:56:41 +00:00
|
|
|
|
|
|
|
# Allows sending email from CLI/sendmail
|
2023-07-28 22:49:24 +00:00
|
|
|
programs.msmtp.enable = true;
|
2023-07-30 03:56:41 +00:00
|
|
|
|
|
|
|
# Better local mail search
|
2023-07-28 22:49:24 +00:00
|
|
|
programs.notmuch = {
|
|
|
|
enable = true;
|
2024-04-20 13:42:06 +00:00
|
|
|
new.ignore = [
|
|
|
|
".mbsyncstate.lock"
|
|
|
|
".mbsyncstate.journal"
|
|
|
|
".mbsyncstate.new"
|
|
|
|
];
|
2023-07-28 22:49:24 +00:00
|
|
|
};
|
2023-07-30 03:56:41 +00:00
|
|
|
|
2022-10-30 17:57:14 +00:00
|
|
|
accounts.email = {
|
2023-07-30 03:56:41 +00:00
|
|
|
|
|
|
|
# Where email files are stored
|
2022-10-30 17:57:14 +00:00
|
|
|
maildirBasePath = "${config.homePath}/mail";
|
2023-07-30 03:56:41 +00:00
|
|
|
|
2022-10-30 17:57:14 +00:00
|
|
|
accounts = {
|
2024-04-20 13:42:06 +00:00
|
|
|
home =
|
|
|
|
let
|
|
|
|
address = "${config.mail.user}@${config.mail.server}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
userName = address;
|
|
|
|
realName = config.fullName;
|
|
|
|
primary = true;
|
|
|
|
inherit address;
|
|
|
|
aliases = map (user: "${user}@${config.mail.server}") [
|
|
|
|
"me"
|
|
|
|
"hey"
|
|
|
|
"admin"
|
|
|
|
];
|
|
|
|
|
|
|
|
# Options for contact completion
|
|
|
|
alot = { };
|
|
|
|
|
|
|
|
imap = {
|
|
|
|
host = config.mail.imapHost;
|
|
|
|
port = 993;
|
|
|
|
tls.enable = true;
|
|
|
|
};
|
2023-07-30 03:56:41 +00:00
|
|
|
|
2024-04-20 13:42:06 +00:00
|
|
|
# Watch for mail and run notifications or sync
|
|
|
|
imapnotify = {
|
|
|
|
enable = true;
|
|
|
|
boxes = [ "Inbox" ];
|
|
|
|
onNotify = "${pkgs.isync}/bin/mbsync -a";
|
|
|
|
onNotifyPost =
|
|
|
|
lib.mkIf config.home-manager.users.${config.user}.services.dunst.enable
|
|
|
|
"${pkgs.libnotify}/bin/notify-send 'New mail arrived'";
|
|
|
|
};
|
2023-07-30 03:56:41 +00:00
|
|
|
|
2024-04-20 13:42:06 +00:00
|
|
|
# Name of the directory in maildir for this account
|
|
|
|
maildir = {
|
|
|
|
path = "main";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Bi-directional syncing options for local files
|
|
|
|
mbsync = {
|
|
|
|
enable = true;
|
|
|
|
create = "both";
|
|
|
|
expunge = "both";
|
|
|
|
remove = "both";
|
|
|
|
patterns = [ "*" ];
|
|
|
|
extraConfig.channel = {
|
|
|
|
CopyArrivalDate = "yes"; # Sync time of original message
|
|
|
|
};
|
2022-10-30 17:57:14 +00:00
|
|
|
};
|
2023-07-30 03:56:41 +00:00
|
|
|
|
2024-04-20 13:42:06 +00:00
|
|
|
# Enable indexing
|
|
|
|
notmuch.enable = true;
|
2023-07-30 03:56:41 +00:00
|
|
|
|
2024-04-20 13:42:06 +00:00
|
|
|
# Used to login and send and receive emails
|
|
|
|
passwordCommand = "${pkgs.age}/bin/age --decrypt --identity ~/.ssh/id_ed25519 ${pkgs.writeText "mailpass.age" (builtins.readFile ../../../private/mailpass.age)}";
|
2023-07-30 03:56:41 +00:00
|
|
|
|
2024-04-20 13:42:06 +00:00
|
|
|
smtp = {
|
|
|
|
host = config.mail.smtpHost;
|
|
|
|
port = 465;
|
|
|
|
tls.enable = true;
|
|
|
|
};
|
2022-10-30 17:57:14 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|