astroid: init

Astroid is a notmuch/gtk based MUA: https://github.com/astroidmail/astroid
This commit is contained in:
Matthieu Coudron 2018-09-30 18:06:02 +09:00 committed by Matthieu Coudron
parent 05c93ff3ae
commit 736e340bde
6 changed files with 320 additions and 0 deletions

View file

@ -380,6 +380,7 @@ in
type = types.attrsOf (types.submodule [
mailAccountOpts
(import ../programs/alot-accounts.nix)
(import ../programs/astroid-accounts.nix)
(import ../programs/mbsync-accounts.nix)
(import ../programs/msmtp-accounts.nix)
(import ../programs/notmuch-accounts.nix)

View file

@ -27,6 +27,7 @@ let
./misc/xdg.nix
./programs/alot.nix
./programs/autorandr.nix
./programs/astroid.nix
./programs/bash.nix
./programs/beets.nix
./programs/browserpass.nix

View file

@ -0,0 +1,41 @@
{ config, lib, ... }:
with lib;
{
options.astroid = {
enable = mkEnableOption "Astroid";
sendMailCommand = mkOption {
type = types.nullOr types.str;
description = ''
Command to send a mail. If msmtp is enabled for the account,
then this is set to
<command>msmtpq --read-envelope-from --read-recipients</command>.
'';
};
extraConfig = mkOption {
type = types.attrs;
default = {};
example = ''
{
select_query = "";
}
'';
description = ''
Extra settings to add to this astroid account configuration.
'';
};
};
config = mkIf config.notmuch.enable {
astroid.sendMailCommand = mkOptionDefault (
if config.msmtp.enable
then "msmtpq --read-envelope-from --read-recipients"
else null
);
};
}

View file

@ -0,0 +1,136 @@
{
"astroid": {
"config": {
"version": "11"
},
"notmuch_config": "\/home\/teto\/.notmuch-config",
"debug": {
"dryrun_sending": "false"
},
"hints": {
"level": "0"
},
"log": {
"syslog": "false",
"stdout": "true",
"level": "info"
}
},
"accounts": {
"charlie": {
"name": "Charlie Root",
"email": "root@localhost",
"gpgkey": "",
"always_gpg_sign": "false",
"sendmail": "msmtp -i -t",
"default": "true",
"save_sent": "false",
"save_sent_to": "\/home\/root\/Mail\/sent\/cur\/",
"additional_sent_tags": "",
"save_drafts_to": "\/home\/root\/Mail\/drafts\/",
"signature_separate": "false",
"signature_file": "",
"signature_file_markdown": "",
"signature_default_on": "true",
"signature_attach": "false",
"select_query": ""
}
},
"startup": {
"queries": {
"inbox": "tag:inbox"
}
},
"terminal": {
"height": "10",
"font_description": "default"
},
"thread_index": {
"page_jump_rows": "6",
"sort_order": "newest",
"cell": {
"font_description": "default",
"line_spacing": "2",
"date_length": "10",
"message_count_length": "4",
"authors_length": "20",
"subject_color": "#807d74",
"subject_color_selected": "#000000",
"background_color_selected": "",
"background_color_marked": "#fff584",
"background_color_marked_selected": "#bcb559",
"tags_length": "80",
"tags_upper_color": "#e5e5e5",
"tags_lower_color": "#333333",
"tags_alpha": "0.5",
"hidden_tags": "attachment,flagged,unread"
}
},
"general": {
"time": {
"clock_format": "local",
"same_year": "%b %-e",
"diff_year": "%x"
}
},
"editor": {
"cmd": "\/nix\/store\/svbc11jg7aq9c2mdz233cadxnqnqdckx-vim-8.1.0146\/bin\/vim -g --servername %2 --socketid %3 -f -c 'set ft=mail' '+set fileencoding=utf-8' '+set ff=unix' '+set enc=utf-8' '+set fo+=w' %1",
"external_editor": "false",
"charset": "utf-8",
"save_draft_on_force_quit": "true",
"attachment_words": "attach",
"attachment_directory": "~",
"markdown_processor": "marked"
},
"mail": {
"reply": {
"quote_line": "Excerpts from %1's message of %2:",
"mailinglist_reply_to_sender": "true"
},
"forward": {
"quote_line": "Forwarding %1's message of %2:",
"disposition": "inline"
},
"sent_tags": "sent",
"message_id_fqdn": "",
"message_id_user": "",
"user_agent": "default",
"send_delay": "2",
"close_on_success": "false",
"format_flowed": "false"
},
"poll": {
"interval": "60",
"always_full_refresh": "false"
},
"attachment": {
"external_open_cmd": "xdg-open"
},
"thread_view": {
"open_html_part_external": "false",
"preferred_type": "plain",
"preferred_html_only": "false",
"allow_remote_when_encrypted": "false",
"open_external_link": "xdg-open",
"default_save_directory": "~",
"indent_messages": "false",
"gravatar": {
"enable": "true"
},
"mark_unread_delay": "0.5",
"expand_flagged": "true"
},
"crypto": {
"gpg": {
"path": "gpg2",
"always_trust": "true",
"enabled": "true"
}
},
"saved_searches": {
"show_on_startup": "false",
"save_history": "true",
"history_lines_to_show": "15",
"history_lines": "1000"
}
}

View file

@ -0,0 +1,129 @@
# look at dev/get_keys.py to generate a default mappings
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.astroid;
astroidAccounts = filterAttrs (n: v: v.notmuch.enable)
(config.accounts.email.accounts);
sendMailCommand = account:
if account.astroid.sendMailCommand != null then account.astroid.sendMailCommand
else
if account.msmtp.enable then cfg.msmtp.sendCommand else "";
accountAttr = account: with account; {
email = address;
name = realName;
sendmail = sendMailCommand account;
additional_sent_tags = "";
default = if primary then "true" else "false";
save_drafts_to = folders.drafts;
save_sent = "true";
save_sent_to = folders.sent;
select_query = "";
}
// optionalAttrs (signature.showSignature != "none") {
signature_attach= if (signature.showSignature == "attach") then "true" else "false";
signature_default_on = if (signature.showSignature != "none") then "true" else "false";
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 = if gpg.signByDefault then "true" else "false";
gpgkey = gpg.key;
}
// astroid.extraConfig
;
# See https://github.com/astroidmail/astroid/wiki/Configuration-Reference
configFile = mailAccounts: let
template = builtins.fromJSON (builtins.readFile ./astroid-config-template.json);
astroidConfig =
recursiveUpdate (template // {
astroid.notmuch_config = "${config.xdg.configHome}/notmuch/notmuchrc";
accounts = mapAttrs (name: account: (accountAttr account) ) astroidAccounts;
crypto.gpg.path = "${pkgs.gnupg}/bin/gpg";
}
// cfg.extraConfig
)
cfg.externalEditor;
in
builtins.toJSON astroidConfig;
in
{
options = {
programs.astroid = {
enable = mkEnableOption "Astroid";
pollScript = mkOption {
type = types.str;
default = "";
example = ''
mbsync gmail
'';
description = ''
Script to run to fetch/update mails.
'';
};
externalEditor = mkOption {
type = types.str;
default = ''
gvim -c 'set ft=mail' '+set fileencoding=utf-8' '+set ff=unix' '+set enc=utf-8' '+set fo+=w' %1
'';
# converts it into json that can be appended to the config
apply = cmd:
{
editor = {
"external_editor" = "true";
"cmd" = cmd;
};
};
example = ''
nvim-qt -- -c 'set ft=mail' '+set fileencoding=utf-8' '+set ff=unix' '+set enc=utf-8' '+set fo+=w' %1
'';
description = ''
You can use %1 / %2 / %3 to refer respectively to:
- filename
- servername
- socketid
See <link xlink:href='https://github.com/astroidmail/astroid/wiki/Customizing-editor' />
'';
};
extraConfig = mkOption {
type = types.attrs;
default = {};
example = literalExample ''
{
poll.interval = 0;
}
'';
description = ''
JSON config that will override the default astroid configuration.
'';
};
};
};
config = mkIf cfg.enable {
home.packages = [ pkgs.astroid ];
xdg.configFile."astroid/config".source = pkgs.runCommandNoCC "out.json"
{x = configFile astroidAccounts; } ''echo "$x" | ${pkgs.jq}/bin/jq . > $out'';
xdg.configFile."astroid/poll.sh" = {
executable = true;
text = "# Generated by home-manager\n" + cfg.pollScript;
};
};
}

View file

@ -60,6 +60,18 @@ in
'';
};
};
sendCommand = mkOption {
type = types.str;
default = "msmtpq --read-envelope-from --read-recipients";
# apply = p:
# if hasPrefix "/" p
# then p
# else "${config.home.homeDirectory}/${p}";
description = ''
Default command to use to send mail.
'';
};
};
config = mkIf cfg.enable {