2018-09-30 09:06:02 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
with builtins;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.astroid;
|
|
|
|
|
2020-11-30 02:54:55 +00:00
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
2018-09-30 09:06:02 +00:00
|
|
|
astroidAccounts =
|
2020-02-01 23:39:17 +00:00
|
|
|
filterAttrs (n: v: v.astroid.enable) config.accounts.email.accounts;
|
2018-09-30 09:06:02 +00:00
|
|
|
|
|
|
|
boolOpt = b: if b then "true" else "false";
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
accountAttr = account:
|
|
|
|
with account;
|
|
|
|
{
|
|
|
|
email = address;
|
|
|
|
name = realName;
|
|
|
|
sendmail = astroid.sendMailCommand;
|
|
|
|
additional_sent_tags = "";
|
|
|
|
default = boolOpt primary;
|
2021-09-28 14:16:13 +00:00
|
|
|
save_drafts_to = "${maildir.absPath}/${folders.drafts}/cur/";
|
2020-02-01 23:39:17 +00:00
|
|
|
save_sent = "true";
|
2021-09-28 14:16:13 +00:00
|
|
|
save_sent_to = "${maildir.absPath}/${folders.sent}/cur/";
|
2020-02-01 23:39:17 +00:00
|
|
|
select_query = "";
|
|
|
|
} // optionalAttrs (signature.showSignature != "none") {
|
|
|
|
signature_attach = boolOpt (signature.showSignature == "attach");
|
|
|
|
signature_default_on = boolOpt (signature.showSignature != "none");
|
|
|
|
signature_file = pkgs.writeText "signature.txt" signature.text;
|
|
|
|
signature_file_markdown = "false";
|
|
|
|
signature_separate = "true"; # prepends '--\n' to the signature
|
|
|
|
} // optionalAttrs (gpg != null) {
|
|
|
|
always_gpg_sign = boolOpt gpg.signByDefault;
|
|
|
|
gpgkey = gpg.key;
|
|
|
|
} // astroid.extraConfig;
|
2018-09-30 09:06:02 +00:00
|
|
|
|
|
|
|
# See https://github.com/astroidmail/astroid/wiki/Configuration-Reference
|
2020-11-30 02:54:55 +00:00
|
|
|
finalConfig = let
|
|
|
|
template = fromJSON (readFile ./astroid-config-template.json);
|
|
|
|
astroidConfig = foldl' recursiveUpdate template [
|
|
|
|
{
|
2022-02-05 16:45:12 +00:00
|
|
|
astroid.notmuch_config =
|
|
|
|
"${config.xdg.configHome}/notmuch/default/config";
|
2020-11-30 02:54:55 +00:00
|
|
|
accounts = mapAttrs (n: accountAttr) astroidAccounts;
|
|
|
|
crypto.gpg.path = "${pkgs.gnupg}/bin/gpg";
|
|
|
|
}
|
|
|
|
cfg.extraConfig
|
|
|
|
cfg.externalEditor
|
|
|
|
];
|
|
|
|
in astroidConfig;
|
2018-09-30 09:06:02 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2018-09-30 09:06:02 +00:00
|
|
|
options = {
|
|
|
|
programs.astroid = {
|
2023-07-01 23:45:18 +00:00
|
|
|
enable = mkEnableOption "Astroid";
|
2018-09-30 09:06:02 +00:00
|
|
|
|
|
|
|
pollScript = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "mbsync gmail";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2018-09-30 09:06:02 +00:00
|
|
|
Script to run to fetch/update mails.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
externalEditor = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
# Converts it into JSON that can be merged into the configuration.
|
|
|
|
apply = cmd:
|
|
|
|
optionalAttrs (cmd != null) {
|
|
|
|
editor = {
|
|
|
|
"external_editor" = "true";
|
|
|
|
"cmd" = cmd;
|
|
|
|
};
|
|
|
|
};
|
2020-02-01 23:39:17 +00:00
|
|
|
example =
|
|
|
|
"nvim-qt -- -c 'set ft=mail' '+set fileencoding=utf-8' '+set ff=unix' '+set enc=utf-8' '+set fo+=w' %1";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2023-07-01 00:40:42 +00:00
|
|
|
You can use the following variables:
|
|
|
|
|
|
|
|
`%1`
|
|
|
|
: file name
|
|
|
|
|
|
|
|
`%2`
|
|
|
|
: server name
|
|
|
|
|
|
|
|
`%3`
|
|
|
|
: socket ID
|
|
|
|
|
|
|
|
See [Customizing editor](https://github.com/astroidmail/astroid/wiki/Customizing-editor)
|
|
|
|
on the Astroid wiki.
|
2018-09-30 09:06:02 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2020-11-30 02:54:55 +00:00
|
|
|
type = jsonFormat.type;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2020-11-30 02:54:55 +00:00
|
|
|
{
|
|
|
|
poll.interval = 0;
|
|
|
|
}
|
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2018-09-30 09:06:02 +00:00
|
|
|
JSON config that will override the default Astroid configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-06-15 22:45:20 +00:00
|
|
|
|
|
|
|
accounts.email.accounts = mkOption {
|
|
|
|
type = with types; attrsOf (submodule (import ./astroid-accounts.nix));
|
|
|
|
};
|
2018-09-30 09:06:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-02-01 23:39:17 +00:00
|
|
|
home.packages = [ pkgs.astroid ];
|
|
|
|
|
2020-11-30 02:54:55 +00:00
|
|
|
xdg.configFile."astroid/config".source =
|
|
|
|
jsonFormat.generate "astroid-config" finalConfig;
|
2018-09-30 09:06:02 +00:00
|
|
|
|
|
|
|
xdg.configFile."astroid/poll.sh" = {
|
|
|
|
executable = true;
|
|
|
|
text = ''
|
|
|
|
# Generated by Home Manager
|
|
|
|
|
|
|
|
${cfg.pollScript}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|