2018-06-28 23:42:25 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.notmuch;
|
|
|
|
|
|
|
|
mkIniKeyValue = key: value:
|
|
|
|
let
|
|
|
|
tweakVal = v:
|
2020-02-02 00:39:17 +01:00
|
|
|
if isString v then
|
|
|
|
v
|
|
|
|
else if isList v then
|
|
|
|
concatMapStringsSep ";" tweakVal v
|
|
|
|
else if isBool v then
|
|
|
|
(if v then "true" else "false")
|
|
|
|
else
|
|
|
|
toString v;
|
|
|
|
in "${key}=${tweakVal value}";
|
|
|
|
|
|
|
|
notmuchIni = recursiveUpdate {
|
|
|
|
database = { path = config.accounts.email.maildirBasePath; };
|
|
|
|
|
|
|
|
maildir = { synchronize_flags = cfg.maildir.synchronizeFlags; };
|
|
|
|
|
|
|
|
new = {
|
|
|
|
ignore = cfg.new.ignore;
|
|
|
|
tags = cfg.new.tags;
|
|
|
|
};
|
2018-09-19 00:13:31 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
user = let
|
|
|
|
accounts = filter (a: a.notmuch.enable)
|
|
|
|
(attrValues config.accounts.email.accounts);
|
|
|
|
primary = filter (a: a.primary) accounts;
|
|
|
|
secondaries = filter (a: !a.primary) accounts;
|
|
|
|
in {
|
|
|
|
name = catAttrs "realName" primary;
|
|
|
|
primary_email = catAttrs "address" primary;
|
|
|
|
other_email = catAttrs "aliases" primary ++ catAttrs "address" secondaries
|
|
|
|
++ catAttrs "aliases" secondaries;
|
|
|
|
};
|
2018-06-28 23:42:25 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
search = { exclude_tags = cfg.search.excludeTags; };
|
|
|
|
} cfg.extraConfig;
|
2018-06-28 23:42:25 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2018-06-28 23:42:25 +02:00
|
|
|
options = {
|
|
|
|
programs.notmuch = {
|
2023-07-01 01:30:13 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Notmuch mail indexer");
|
2018-06-28 23:42:25 +02:00
|
|
|
|
|
|
|
new = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
options = {
|
|
|
|
ignore = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-06-28 23:42:25 +02:00
|
|
|
A list to specify files and directories that will not be
|
2023-07-01 01:30:13 +02:00
|
|
|
searched for messages by {command}`notmuch new`.
|
2018-06-28 23:42:25 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "unread" "inbox" ];
|
|
|
|
example = [ "new" ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-06-28 23:42:25 +02:00
|
|
|
A list of tags that will be added to all messages
|
2023-07-01 01:30:13 +02:00
|
|
|
incorporated by {command}`notmuch new`.
|
2018-06-28 23:42:25 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-06-28 23:42:25 +02:00
|
|
|
Options related to email processing performed by
|
2023-07-01 01:30:13 +02:00
|
|
|
{command}`notmuch new`.
|
2018-06-28 23:42:25 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrsOf (types.attrsOf types.str);
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-06-28 23:42:25 +02:00
|
|
|
Options that should be appended to the notmuch configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hooks = {
|
|
|
|
preNew = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "mbsync --all";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-06-28 23:42:25 +02:00
|
|
|
Bash statements run before scanning or importing new
|
|
|
|
messages into the database.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
postNew = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
notmuch tag +nixos -- tag:new and from:nixos1@discoursemail.com
|
|
|
|
'';
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-06-28 23:42:25 +02:00
|
|
|
Bash statements run after new messages have been imported
|
|
|
|
into the database and initial tags have been applied.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
postInsert = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-06-28 23:42:25 +02:00
|
|
|
Bash statements run after a message has been inserted
|
|
|
|
into the database and initial tags have been applied.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2018-11-25 01:14:15 +01:00
|
|
|
|
|
|
|
maildir = {
|
|
|
|
synchronizeFlags = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-11-25 01:14:15 +01:00
|
|
|
Whether to synchronize Maildir flags.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2019-04-10 15:24:35 +02:00
|
|
|
|
|
|
|
search = {
|
|
|
|
excludeTags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "deleted" "spam" ];
|
|
|
|
example = [ "trash" "spam" ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-04-10 15:24:35 +02:00
|
|
|
A list of tags that will be excluded from search results by
|
|
|
|
default. Using an excluded tag in a query will override that
|
|
|
|
exclusion.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2018-06-28 23:42:25 +02:00
|
|
|
};
|
2020-06-16 00:45:20 +02:00
|
|
|
|
|
|
|
accounts.email.accounts = mkOption {
|
2020-09-24 20:02:49 +02:00
|
|
|
type = with types;
|
|
|
|
attrsOf (submodule {
|
2023-07-01 01:30:13 +02:00
|
|
|
options.notmuch.enable =
|
|
|
|
mkEnableOption (lib.mdDoc "notmuch indexing");
|
2020-09-24 20:02:49 +02:00
|
|
|
});
|
2020-06-16 00:45:20 +02:00
|
|
|
};
|
2018-06-28 23:42:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
2020-02-02 00:39:17 +01:00
|
|
|
assertion = notmuchIni.user.name != [ ];
|
2018-06-28 23:42:25 +02:00
|
|
|
message = "notmuch: Must have a user name set.";
|
|
|
|
}
|
|
|
|
{
|
2020-02-02 00:39:17 +01:00
|
|
|
assertion = notmuchIni.user.primary_email != [ ];
|
2018-06-28 23:42:25 +02:00
|
|
|
message = "notmuch: Must have a user primary email address set.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
home.packages = [ pkgs.notmuch ];
|
|
|
|
|
|
|
|
home.sessionVariables = {
|
2022-02-05 17:45:12 +01:00
|
|
|
NOTMUCH_CONFIG = "${config.xdg.configHome}/notmuch/default/config";
|
2018-06-28 23:42:25 +02:00
|
|
|
NMBGIT = "${config.xdg.dataHome}/notmuch/nmbug";
|
|
|
|
};
|
|
|
|
|
2022-02-05 17:45:12 +01:00
|
|
|
xdg.configFile = let
|
2020-02-02 00:39:17 +01:00
|
|
|
hook = name: cmds: {
|
2022-02-05 17:45:12 +01:00
|
|
|
"notmuch/default/hooks/${name}".source = pkgs.writeShellScript name ''
|
|
|
|
export PATH="${pkgs.notmuch}/bin''${PATH:+:}$PATH"
|
|
|
|
export NOTMUCH_CONFIG="${config.xdg.configHome}/notmuch/default/config"
|
|
|
|
export NMBGIT="${config.xdg.dataHome}/notmuch/nmbug"
|
2020-02-02 00:39:17 +01:00
|
|
|
|
2022-02-05 17:45:12 +01:00
|
|
|
${cmds}
|
|
|
|
'';
|
2020-02-02 00:39:17 +01:00
|
|
|
};
|
2022-02-05 17:45:12 +01:00
|
|
|
in {
|
|
|
|
"notmuch/default/config".text =
|
|
|
|
let toIni = generators.toINI { mkKeyValue = mkIniKeyValue; };
|
|
|
|
in ''
|
|
|
|
# Generated by Home Manager.
|
|
|
|
|
|
|
|
'' + toIni notmuchIni;
|
|
|
|
}
|
|
|
|
// optionalAttrs (cfg.hooks.preNew != "") (hook "pre-new" cfg.hooks.preNew)
|
2020-02-02 00:39:17 +01:00
|
|
|
// optionalAttrs (cfg.hooks.postNew != "")
|
|
|
|
(hook "post-new" cfg.hooks.postNew)
|
|
|
|
// optionalAttrs (cfg.hooks.postInsert != "")
|
|
|
|
(hook "post-insert" cfg.hooks.postInsert);
|
2018-06-28 23:42:25 +02:00
|
|
|
};
|
|
|
|
}
|