aboutsummaryrefslogtreecommitdiffstats
path: root/modules/communication/neomutt/account
diff options
context:
space:
mode:
Diffstat (limited to 'modules/communication/neomutt/account')
-rw-r--r--modules/communication/neomutt/account/default.nix106
-rw-r--r--modules/communication/neomutt/account/flavors/gmail.nix45
-rw-r--r--modules/communication/neomutt/account/options.nix328
3 files changed, 479 insertions, 0 deletions
diff --git a/modules/communication/neomutt/account/default.nix b/modules/communication/neomutt/account/default.nix
new file mode 100644
index 0000000..183e5ff
--- /dev/null
+++ b/modules/communication/neomutt/account/default.nix
@@ -0,0 +1,106 @@
+{ config, lib, ... }:
+
+with lib;
+
+let
+ inherit (lib) types;
+in
+{
+ options.communication.neomutt.accounts = mkOption {
+ type = types.attrsOf (
+ types.submodule {
+ imports = [
+ ./options.nix
+ ./flavors/gmail.nix
+ ];
+ }
+ );
+ default = { };
+ description = "Specification of email accounts.";
+ };
+
+ config = mkIf config.communication.neomutt.enable {
+ accounts.email.accounts = mapAttrs (
+ name: account:
+ let
+ a = account;
+ in
+ {
+ inherit (a) realName address primary;
+ userName = if a.userName != null then a.userName else a.address;
+
+ passwordCommand =
+ if a.passwordGopassSecret != null then
+ "${lib.getExe config.security.gopass.package} -o ${a.passwordGopassSecret}"
+ else
+ null;
+
+ flavor = a.flavor;
+ inherit (a) aliases;
+
+ folders = {
+ inherit (a.folders) inbox trash;
+ }
+ // optionalAttrs (a.folders.drafts != null) { drafts = a.folders.drafts; }
+ // optionalAttrs (a.folders.sent != null) { sent = a.folders.sent; };
+
+ neomutt = {
+ enable = true;
+ mailboxType = a.neomutt.mailboxType;
+ extraConfig = a.neomutt.extraConfig;
+ };
+
+ mbsync = {
+ enable = true;
+ create = a.mbsync.create;
+ patterns = a.mbsync.patterns;
+ flatten = a.mbsync.flatten;
+ extraConfig = {
+ account = a.mbsync.extraConfig.account;
+ channel = a.mbsync.extraConfig.channel;
+ local = a.mbsync.extraConfig.local;
+ remote = a.mbsync.extraConfig.remote;
+ };
+ };
+
+ notmuch = {
+ enable = true;
+ neomutt = {
+ enable = true;
+ virtualMailboxes = a.notmuch.neomutt.virtualMailboxes;
+ };
+ };
+
+ imap = optionalAttrs (a.imap.host != null) {
+ host = a.imap.host;
+ port = a.imap.port;
+ tls = {
+ enable = a.imap.tls.enable;
+ useStartTls = a.imap.tls.useStartTls;
+ };
+ };
+
+ smtp = optionalAttrs (a.smtp.host != null) {
+ host = a.smtp.host;
+ port = a.smtp.port;
+ tls = {
+ enable = a.smtp.tls.enable;
+ useStartTls = a.smtp.tls.useStartTls;
+ };
+ };
+
+ gpg = optionalAttrs (a.gpg.key != null) {
+ key = a.gpg.key;
+ signByDefault = a.gpg.signByDefault;
+ encryptByDefault = a.gpg.encryptByDefault;
+ };
+
+ signature = optionalAttrs (a.signature.text != null || a.signature.command != null) {
+ text = a.signature.text;
+ command = a.signature.command;
+ showSignature = a.signature.showSignature;
+ };
+ }
+ ) (filterAttrs (n: a: a.enable) config.communication.neomutt.accounts);
+ };
+}
diff --git a/modules/communication/neomutt/account/flavors/gmail.nix b/modules/communication/neomutt/account/flavors/gmail.nix
new file mode 100644
index 0000000..5ccceed
--- /dev/null
+++ b/modules/communication/neomutt/account/flavors/gmail.nix
@@ -0,0 +1,45 @@
+{
+ config,
+ lib,
+ name,
+ ...
+}:
+
+{
+ config = lib.mkIf (config.flavor == "gmail.com") {
+ folders = {
+ inbox = lib.mkDefault "Inbox";
+ drafts = lib.mkDefault "[Gmail]/Drafts";
+ sent = lib.mkDefault "[Gmail]/Sent Mail";
+ trash = lib.mkDefault "[Gmail]/Trash";
+ };
+
+ mbsync = {
+ create = lib.mkDefault "maildir";
+ patterns = lib.mkDefault [
+ "INBOX"
+ "[Gmail]/Drafts"
+ "[Gmail]/Sent Mail"
+ "[Gmail]/Spam"
+ "[Gmail]/Trash"
+ ];
+ extraConfig.channel = {
+ Sync = lib.mkDefault "All";
+ CopyArrivalDate = lib.mkDefault "yes";
+ Expunge = lib.mkDefault "Both";
+ SyncState = lib.mkDefault "*";
+ };
+ };
+
+ neomutt.extraConfig = lib.mkDefault ''
+ mailboxes =Inbox ="[Gmail]/Drafts" ="[Gmail]/Sent Mail" ="[Gmail]/Spam" ="[Gmail]/Trash"
+ '';
+
+ notmuch.neomutt.virtualMailboxes = lib.mkDefault [
+ {
+ name = "All Mail";
+ query = "folder:${name}/Inbox or folder:\"${name}/[Gmail]/Sent Mail\"";
+ }
+ ];
+ };
+}
diff --git a/modules/communication/neomutt/account/options.nix b/modules/communication/neomutt/account/options.nix
new file mode 100644
index 0000000..bb53231
--- /dev/null
+++ b/modules/communication/neomutt/account/options.nix
@@ -0,0 +1,328 @@
+{ lib, ... }:
+
+{
+ options = {
+ enable = lib.mkEnableOption "this email account" // {
+ default = true;
+ };
+
+ realName = lib.mkOption {
+ type = lib.types.str;
+ description = "Name displayed when sending mails.";
+ };
+
+ address = lib.mkOption {
+ type = lib.types.str;
+ description = "Email address of this account.";
+ };
+
+ userName = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "Server username. Defaults to address if null.";
+ };
+
+ passwordGopassSecret = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "Gopass secret path (e.g. mail/user@gmail.com). Constructs passwordCommand automatically.";
+ };
+
+ primary = lib.mkOption {
+ type = lib.types.bool;
+ default = false;
+ description = "Whether this is the primary account.";
+ };
+
+ flavor = lib.mkOption {
+ type = lib.types.nullOr (
+ lib.types.enum [
+ "gmail.com"
+ "fastmail.com"
+ "outlook.office365.com"
+ "outlook.office365.com-ews"
+ "mailbox.org"
+ "migadu.com"
+ "posteo.de"
+ "runbox.com"
+ "yandex.com"
+ "davmail"
+ "plain"
+ ]
+ );
+ default = null;
+ description = "Email provider flavor for automatic configuration.";
+ };
+
+ folders = {
+ inbox = lib.mkOption {
+ type = lib.types.str;
+ default = "Inbox";
+ description = "Inbox folder.";
+ };
+
+ drafts = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "Drafts folder.";
+ };
+
+ sent = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "Sent mail folder.";
+ };
+
+ trash = lib.mkOption {
+ type = lib.types.str;
+ default = "Trash";
+ description = "Trash folder.";
+ };
+ };
+
+ neomutt = {
+ mailboxType = lib.mkOption {
+ type = lib.types.enum [
+ "maildir"
+ "imap"
+ ];
+ default = "maildir";
+ description = "Whether this account uses maildir folders or IMAP mailboxes.";
+ };
+
+ extraConfig = lib.mkOption {
+ type = lib.types.lines;
+ default = "";
+ description = "Extra neomutt config lines for this account.";
+ };
+ };
+
+ mbsync = {
+ create = lib.mkOption {
+ type = lib.types.enum [
+ "none"
+ "maildir"
+ "imap"
+ "both"
+ ];
+ default = "none";
+ description = "Automatically create missing mailboxes.";
+ };
+
+ patterns = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = [ "INBOX" ];
+ description = "Mailbox patterns to synchronize.";
+ };
+
+ flatten = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "Flatten hierarchy delimiter.";
+ };
+
+ extraConfig = {
+ account = lib.mkOption {
+ type = lib.types.attrsOf (
+ lib.types.oneOf [
+ lib.types.str
+ lib.types.int
+ lib.types.bool
+ (lib.types.listOf lib.types.str)
+ ]
+ );
+ default = { };
+ description = "Account section extra configuration.";
+ };
+
+ channel = lib.mkOption {
+ type = lib.types.attrsOf (
+ lib.types.oneOf [
+ lib.types.str
+ lib.types.int
+ lib.types.bool
+ (lib.types.listOf lib.types.str)
+ ]
+ );
+ default = { };
+ description = "Channel extra configuration.";
+ };
+
+ local = lib.mkOption {
+ type = lib.types.attrsOf (
+ lib.types.oneOf [
+ lib.types.str
+ lib.types.int
+ lib.types.bool
+ (lib.types.listOf lib.types.str)
+ ]
+ );
+ default = { };
+ description = "Local store extra configuration.";
+ };
+
+ remote = lib.mkOption {
+ type = lib.types.attrsOf (
+ lib.types.oneOf [
+ lib.types.str
+ lib.types.int
+ lib.types.bool
+ (lib.types.listOf lib.types.str)
+ ]
+ );
+ default = { };
+ description = "Remote store extra configuration.";
+ };
+ };
+ };
+
+ notmuch = {
+ neomutt = {
+ virtualMailboxes = lib.mkOption {
+ type = lib.types.listOf (
+ lib.types.submodule {
+ options = {
+ name = lib.mkOption {
+ type = lib.types.str;
+ description = "Display name.";
+ };
+
+ query = lib.mkOption {
+ type = lib.types.str;
+ description = "Notmuch query.";
+ };
+
+ limit = lib.mkOption {
+ type = lib.types.nullOr lib.types.int;
+ default = null;
+ description = "Result limit.";
+ };
+
+ type = lib.mkOption {
+ type = lib.types.nullOr (
+ lib.types.enum [
+ "threads"
+ "messages"
+ ]
+ );
+ default = null;
+ description = "Result type.";
+ };
+ };
+ }
+ );
+ default = [ ];
+ description = "Virtual mailboxes from notmuch queries.";
+ };
+ };
+ };
+
+ imap = {
+ host = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "IMAP server hostname.";
+ };
+
+ port = lib.mkOption {
+ type = lib.types.nullOr lib.types.port;
+ default = null;
+ description = "IMAP server port.";
+ };
+
+ tls = {
+ enable = lib.mkOption {
+ type = lib.types.bool;
+ default = true;
+ description = "Enable TLS.";
+ };
+
+ useStartTls = lib.mkOption {
+ type = lib.types.bool;
+ default = false;
+ description = "Use STARTTLS.";
+ };
+ };
+ };
+
+ smtp = {
+ host = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "SMTP server hostname.";
+ };
+
+ port = lib.mkOption {
+ type = lib.types.nullOr lib.types.port;
+ default = null;
+ description = "SMTP server port.";
+ };
+
+ tls = {
+ enable = lib.mkOption {
+ type = lib.types.bool;
+ default = true;
+ description = "Enable TLS.";
+ };
+
+ useStartTls = lib.mkOption {
+ type = lib.types.bool;
+ default = false;
+ description = "Use STARTTLS.";
+ };
+ };
+ };
+
+ gpg = {
+ key = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "GPG key to use.";
+ };
+
+ signByDefault = lib.mkOption {
+ type = lib.types.bool;
+ default = false;
+ description = "Sign messages by default.";
+ };
+
+ encryptByDefault = lib.mkOption {
+ type = lib.types.bool;
+ default = false;
+ description = "Encrypt messages by default.";
+ };
+ };
+
+ signature = {
+ text = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "Signature text.";
+ };
+
+ command = lib.mkOption {
+ type = lib.types.nullOr lib.types.path;
+ default = null;
+ description = "Command that generates a signature.";
+ };
+
+ showSignature = lib.mkOption {
+ type = lib.types.nullOr (
+ lib.types.enum [
+ "append"
+ "attach"
+ "none"
+ ]
+ );
+ default = null;
+ description = "Signature display method.";
+ };
+ };
+
+ aliases = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = [ ];
+ description = "Alternative email addresses for this account.";
+ };
+ };
+}