dotfiles/modules/common/mail/default.nix

100 lines
3.0 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; };
services.mbsync = lib.mkIf pkgs.stdenv.isLinux {
enable = true;
frequency = "*:0/5";
postExec = "${pkgs.notmuch}/bin/notmuch new";
};
services.imapnotify.enable = pkgs.stdenv.isLinux;
programs.msmtp.enable = true;
programs.notmuch = {
enable = true;
new.ignore = [ ".mbsyncstate.lock" ".mbsyncstate.journal" ];
};
2022-10-30 17:57:14 +00:00
accounts.email = {
maildirBasePath = "${config.homePath}/mail";
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"
];
alot = { };
flavor = "plain";
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;
};
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
};
maildir = { path = "main"; };
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
};
};
notmuch.enable = true;
2022-10-30 17:57:14 +00:00
passwordCommand =
"${pkgs.age}/bin/age --decrypt --identity ${config.identityFile} ${
pkgs.writeText "mailpass.age"
(builtins.readFile ../../../private/mailpass.age)
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;
};
};
};
};
};
};
}