dotfiles/modules/common/mail/default.nix

125 lines
3.6 KiB
Nix
Raw Normal View History

2022-10-30 17:57:14 +00:00
{ config, pkgs, lib, ... }: {
2023-07-29 03:28:08 +00:00
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} = {
programs.mbsync = { enable = true; };
2023-07-30 03:56:41 +00:00
# Automatically check for mail and keep files synced locally
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
services.imapnotify.enable = pkgs.stdenv.isLinux;
2023-07-30 03:56:41 +00:00
# Allows sending email from CLI/sendmail
programs.msmtp.enable = true;
2023-07-30 03:56:41 +00:00
# Better local mail search
programs.notmuch = {
enable = true;
new.ignore = [ ".mbsyncstate.lock" ".mbsyncstate.journal" ];
};
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 = {
2022-12-21 21:18:03 +00:00
home = let address = "${config.mail.user}@${config.mail.server}";
2022-10-30 17:57:14 +00:00
in {
userName = address;
realName = config.fullName;
primary = true;
inherit address;
2022-12-21 21:18:03 +00:00
aliases = map (user: "${user}@${config.mail.server}") [
2022-10-30 17:57:14 +00:00
"me"
"hey"
"admin"
];
2023-07-30 03:56:41 +00:00
# Options for contact completion
2022-10-30 17:57:14 +00:00
alot = { };
2023-07-30 03:56:41 +00:00
2022-10-30 17:57:14 +00:00
imap = {
2023-03-12 21:07:41 +00:00
host = config.mail.imapHost;
2022-10-30 17:57:14 +00:00
port = 993;
tls.enable = true;
};
2023-07-30 03:56:41 +00:00
# Watch for mail and run notifications or sync
2022-10-30 17:57:14 +00:00
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'";
2022-10-30 17:57:14 +00:00
};
2023-07-30 03:56:41 +00:00
# Name of the directory in maildir for this account
2022-10-30 17:57:14 +00:00
maildir = { path = "main"; };
2023-07-30 03:56:41 +00:00
# Bi-directional syncing options for local files
2022-10-30 17:57:14 +00:00
mbsync = {
enable = true;
2023-03-12 21:07:41 +00:00
create = "both";
expunge = "both";
remove = "both";
2022-10-30 17:57:14 +00:00
patterns = [ "*" ];
extraConfig.channel = {
CopyArrivalDate = "yes"; # Sync time of original message
};
};
2023-07-30 03:56:41 +00:00
# Enable indexing
notmuch.enable = true;
2023-07-30 03:56:41 +00:00
# Used to login and send and receive emails
2022-10-30 17:57:14 +00:00
passwordCommand =
"${pkgs.age}/bin/age --decrypt --identity ~/.ssh/id_ed25519 ${
pkgs.writeText "mailpass.age"
(builtins.readFile ../../../private/mailpass.age)
2022-10-30 17:57:14 +00:00
}";
2023-07-30 03:56:41 +00:00
2022-10-30 17:57:14 +00:00
smtp = {
2023-03-12 21:07:41 +00:00
host = config.mail.smtpHost;
2022-10-30 17:57:14 +00:00
port = 465;
tls.enable = true;
};
};
};
};
};
};
}