2022-05-12 07:11:22 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.mujmap;
|
|
|
|
|
|
|
|
mujmapAccounts =
|
|
|
|
filter (a: a.mujmap.enable) (attrValues config.accounts.email.accounts);
|
|
|
|
|
|
|
|
missingNotmuchAccounts = map (a: a.name)
|
|
|
|
(filter (a: !a.notmuch.enable && a.mujmap.notmuchSetupWarning)
|
|
|
|
mujmapAccounts);
|
|
|
|
|
|
|
|
notmuchConfigHelp =
|
|
|
|
map (name: "accounts.email.accounts.${name}.notmuch.enable = true;")
|
|
|
|
missingNotmuchAccounts;
|
|
|
|
|
|
|
|
settingsFormat = pkgs.formats.toml { };
|
|
|
|
|
|
|
|
filterNull = attrs: attrsets.filterAttrs (n: v: v != null) attrs;
|
|
|
|
|
|
|
|
configFile = account:
|
|
|
|
let
|
|
|
|
settings'' = if (account.jmap == null) then
|
|
|
|
{ }
|
|
|
|
else
|
|
|
|
filterNull {
|
|
|
|
fqdn = account.jmap.host;
|
|
|
|
session_url = account.jmap.sessionUrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
settings' = settings'' // {
|
|
|
|
username = account.userName;
|
|
|
|
password_command = escapeShellArgs account.passwordCommand;
|
|
|
|
} // filterNull account.mujmap.settings;
|
|
|
|
|
|
|
|
settings = if (hasAttr "fqdn" settings') then
|
|
|
|
(removeAttrs settings' [ "session_url" ])
|
|
|
|
else
|
|
|
|
settings';
|
|
|
|
in {
|
|
|
|
name = "${account.maildir.absPath}/mujmap.toml";
|
|
|
|
value.source = settingsFormat.generate
|
|
|
|
"mujmap-${lib.replaceStrings [ "@" ] [ "_at_" ] account.address}.toml"
|
|
|
|
settings;
|
|
|
|
};
|
|
|
|
|
|
|
|
tagsOpts = {
|
|
|
|
lowercase = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
If true, translate all mailboxes to lowercase names when mapping to notmuch
|
|
|
|
tags.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
directory_separator = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/";
|
|
|
|
example = ".";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Directory separator for mapping notmuch tags to maildirs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
inbox = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "inbox";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Tag for notmuch to use for messages stored in the mailbox labeled with the
|
2023-07-01 01:30:13 +02:00
|
|
|
`Inbox` name attribute.
|
|
|
|
|
|
|
|
If set to an empty string, this mailbox *and its child
|
|
|
|
mailboxes* are not synchronized with a tag.
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
deleted = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "deleted";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Tag for notmuch to use for messages stored in the mailbox labeled with the
|
2023-07-01 01:30:13 +02:00
|
|
|
`Trash` name attribute.
|
|
|
|
|
|
|
|
If set to an empty string, this mailbox *and its child
|
|
|
|
mailboxes* are not synchronized with a tag.
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sent = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "sent";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Tag for notmuch to use for messages stored in the mailbox labeled with the
|
2023-07-01 01:30:13 +02:00
|
|
|
`Sent` name attribute.
|
|
|
|
|
|
|
|
If set to an empty string, this mailbox *and its child
|
|
|
|
mailboxes* are not synchronized with a tag.
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
spam = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "spam";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Tag for notmuch to use for messages stored in the mailbox labeled with the
|
2023-07-01 01:30:13 +02:00
|
|
|
`Junk` name attribute and/or with the `$Junk` keyword,
|
|
|
|
*except* for messages with the `$NotJunk` keyword.
|
|
|
|
|
|
|
|
If set to an empty string, this mailbox, *its child
|
|
|
|
mailboxes*, and these keywords are not synchronized with a tag.
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
important = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "important";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Tag for notmuch to use for messages stored in the mailbox labeled with the
|
2023-07-01 01:30:13 +02:00
|
|
|
`Important` name attribute and/or with the `$Important`
|
2022-05-12 07:11:22 +02:00
|
|
|
keyword.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
If set to an empty string, this mailbox, *its child
|
|
|
|
mailboxes*, and these keywords are not synchronized with a tag.
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
phishing = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "phishing";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Tag for notmuch to use for the IANA `$Phishing` keyword.
|
|
|
|
|
2022-05-12 07:11:22 +02:00
|
|
|
If set to an empty string, this keyword is not synchronized with a tag.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
rootOpts = {
|
|
|
|
username = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "alice@example.com";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Username for basic HTTP authentication.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
If `null`, defaults to
|
|
|
|
[](#opt-accounts.email.accounts._name_.userName).
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password_command = mkOption {
|
|
|
|
type = types.nullOr (types.either types.str (types.listOf types.str));
|
|
|
|
default = null;
|
|
|
|
apply = p: if isList p then escapeShellArgs p else p;
|
|
|
|
example = "pass alice@example.com";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Shell command which will print a password to stdout for basic HTTP
|
|
|
|
authentication.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
If `null`, defaults to
|
|
|
|
[](#opt-accounts.email.accounts._name_.passwordCommand).
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
fqdn = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "example.com";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Fully qualified domain name of the JMAP service.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2022-05-12 07:11:22 +02:00
|
|
|
mujmap looks up the JMAP SRV record for this host to determine the JMAP session
|
|
|
|
URL. Mutually exclusive with
|
2023-07-01 01:30:13 +02:00
|
|
|
[](#opt-accounts.email.accounts._name_.mujmap.settings.session_url).
|
|
|
|
|
|
|
|
If `null`, defaults to
|
|
|
|
[](#opt-accounts.email.accounts._name_.jmap.host).
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
session_url = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "https://jmap.example.com/.well-known/jmap";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-01-24 11:30:04 +01:00
|
|
|
Session URL to connect to.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2022-05-12 07:11:22 +02:00
|
|
|
Mutually exclusive with
|
2023-07-01 01:30:13 +02:00
|
|
|
[](#opt-accounts.email.accounts._name_.mujmap.settings.fqdn).
|
|
|
|
|
|
|
|
If `null`, defaults to
|
|
|
|
[](#opt-accounts.email.accounts._name_.jmap.sessionUrl).
|
2022-05-12 07:11:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
auto_create_new_mailboxes = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Whether to create new mailboxes automatically on the server from notmuch
|
|
|
|
tags.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cache_dir = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
The cache directory in which to store mail files while they are being
|
|
|
|
downloaded. The default is operating-system specific.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tags = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
options = tagsOpts;
|
|
|
|
};
|
|
|
|
default = { };
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Tag configuration.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2022-05-12 07:11:22 +02:00
|
|
|
Beware that there are quirks that require manual consideration if changing the
|
|
|
|
values of these files; please see
|
2023-07-01 01:30:13 +02:00
|
|
|
<https://github.com/elizagamedev/mujmap/blob/main/mujmap.toml.example>
|
2022-05-12 07:11:22 +02:00
|
|
|
for more details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mujmapOpts = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "mujmap JMAP synchronization for notmuch";
|
2022-05-12 07:11:22 +02:00
|
|
|
|
|
|
|
notmuchSetupWarning = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
Warn if Notmuch is not also enabled for this account.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
This can safely be disabled if {file}`mujmap.toml` is managed
|
2022-05-12 07:11:22 +02:00
|
|
|
outside of Home Manager.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
options = rootOpts;
|
|
|
|
};
|
|
|
|
default = { };
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Settings which are applied to {file}`mujmap.toml`
|
2022-05-12 07:11:22 +02:00
|
|
|
for the account.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
See the [mujmap project](https://github.com/elizagamedev/mujmap)
|
2022-05-12 07:11:22 +02:00
|
|
|
for documentation of settings not explicitly covered by this module.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mujmapModule = types.submodule { options = { mujmap = mujmapOpts; }; };
|
|
|
|
in {
|
|
|
|
meta.maintainers = with maintainers; [ elizagamedev ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.mujmap = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "mujmap Gmail synchronization for notmuch";
|
2022-05-12 07:11:22 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.mujmap;
|
|
|
|
defaultText = "pkgs.mujmap";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-05-12 07:11:22 +02:00
|
|
|
mujmap package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
accounts.email.accounts =
|
|
|
|
mkOption { type = with types; attrsOf mujmapModule; };
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf (missingNotmuchAccounts != [ ]) {
|
|
|
|
warnings = [''
|
|
|
|
mujmap is enabled for the following email accounts, but notmuch is not:
|
|
|
|
|
|
|
|
${concatStringsSep "\n " missingNotmuchAccounts}
|
|
|
|
|
|
|
|
Notmuch can be enabled with:
|
|
|
|
|
|
|
|
${concatStringsSep "\n " notmuchConfigHelp}
|
|
|
|
|
|
|
|
If you have configured notmuch outside of Home Manager, you can suppress this
|
|
|
|
warning with:
|
|
|
|
|
|
|
|
programs.mujmap.notmuchSetupWarning = false;
|
|
|
|
''];
|
|
|
|
})
|
|
|
|
|
|
|
|
{
|
|
|
|
warnings = flatten (map (account: account.warnings) mujmapAccounts);
|
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
# Notmuch should ignore non-mail files created by mujmap.
|
|
|
|
programs.notmuch.new.ignore = [ "/.*[.](toml|json|lock)$/" ];
|
|
|
|
|
|
|
|
home.file = listToAttrs (map configFile mujmapAccounts);
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|