treewide: implement auto importing for modules

Reduce maintenance burden and increase efficiency by automatically
importing modules following a specific convention.

Co-authored-by: awwpotato <awwpotato@voidq.com>
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-06-20 14:39:55 -05:00
parent fefeb0e928
commit 4fca600cb1
461 changed files with 72 additions and 474 deletions

View file

@ -0,0 +1,32 @@
{ config, lib, ... }:
{
options.astroid = {
enable = lib.mkEnableOption "Astroid";
sendMailCommand = lib.mkOption {
type = lib.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`.
'';
};
extraConfig = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = { };
example = {
select_query = "";
};
description = ''
Extra settings to add to this astroid account configuration.
'';
};
};
config = lib.mkIf config.notmuch.enable {
astroid.sendMailCommand = lib.mkIf config.msmtp.enable (
lib.mkOptionDefault "msmtpq --read-envelope-from --read-recipients"
);
};
}

View file

@ -0,0 +1,113 @@
{
"astroid": {
"config": {
"version": "11"
},
"debug": {
"dryrun_sending": "false"
},
"hints": {
"level": "0"
},
"log": {
"syslog": "false",
"stdout": "true",
"level": "info"
}
},
"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": {
"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,141 @@
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkOption types;
cfg = config.programs.astroid;
jsonFormat = pkgs.formats.json { };
astroidAccounts = lib.filterAttrs (n: v: v.astroid.enable) config.accounts.email.accounts;
boolOpt = b: if b then "true" else "false";
accountAttr =
account:
with account;
{
email = address;
name = realName;
sendmail = astroid.sendMailCommand;
additional_sent_tags = "";
default = boolOpt primary;
save_drafts_to = "${maildir.absPath}/${folders.drafts}/cur/";
save_sent = "true";
save_sent_to = "${maildir.absPath}/${folders.sent}/cur/";
select_query = "";
}
// lib.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
}
// lib.optionalAttrs (gpg != null) {
always_gpg_sign = boolOpt gpg.signByDefault;
gpgkey = gpg.key;
}
// astroid.extraConfig;
# See https://github.com/astroidmail/astroid/wiki/Configuration-Reference
finalConfig =
let
template = lib.importJSON ./astroid-config-template.json;
astroidConfig = lib.foldl' lib.recursiveUpdate template [
{
astroid.notmuch_config = "${config.xdg.configHome}/notmuch/default/config";
accounts = lib.mapAttrs (n: accountAttr) astroidAccounts;
crypto.gpg.path = "${pkgs.gnupg}/bin/gpg";
}
cfg.extraConfig
cfg.externalEditor
];
in
astroidConfig;
in
{
options = {
programs.astroid = {
enable = lib.mkEnableOption "Astroid";
package = lib.mkPackageOption pkgs "astroid" { nullable = true; };
pollScript = mkOption {
type = types.str;
default = "";
example = "mbsync gmail";
description = ''
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:
lib.optionalAttrs (cmd != null) {
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 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.
'';
};
extraConfig = mkOption {
type = jsonFormat.type;
default = { };
example = lib.literalExpression ''
{
poll.interval = 0;
}
'';
description = ''
JSON config that will override the default Astroid configuration.
'';
};
};
accounts.email.accounts = mkOption {
type = with types; attrsOf (submodule (import ./accounts.nix));
};
};
config = lib.mkIf cfg.enable {
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile."astroid/config".source = jsonFormat.generate "astroid-config" finalConfig;
xdg.configFile."astroid/poll.sh" = lib.mkIf (cfg.pollScript != "") {
executable = true;
text = ''
# Generated by Home Manager
${cfg.pollScript}
'';
};
};
}