# alot config loader is sensitive to leading space ! { config, lib, pkgs, ... }: with lib; let cfg = config.programs.alot; dag = config.lib.dag; alotAccounts = filter (a: a.alot.enable) (attrValues config.accounts.email.accounts); contactCompletionStr = account: '' [[[abook]]] type = shellcommand command = '' + ( if (account.alot.contactCompletionCommand != null) then account.alot.contactCompletionCommand else config.programs.notmuch.contactCompletion); sendMailCommand = account: if account.alot.sendMailCommand != null then account.alot.sendMailCommand else if account.msmtp.enable then config.programs.msmtp.sendCommand account else ""; accountStr = account: with account; '' [[${name}]] address = ${address} realname = ${realName} sendmail_command = ${sendMailCommand account} # contact completion ${contactCompletionStr account} ''; configFile = mailAccounts: let bindingsToStr = attrSet: concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${v}") attrSet); in '' # Generated by home-manager # see http://alot.readthedocs.io/en/latest/configuration/config_options.html hooksfile = "''${XDG_CONFIG_HOME:-$HOME/.config}/alot/hm_hooks" ${cfg.extraConfig} [bindings] ${bindingsToStr cfg.bindings.global} [[bufferlist]] ${bindingsToStr cfg.bindings.bufferlist} [[search]] ${bindingsToStr cfg.bindings.search} [[envelope]] ${bindingsToStr cfg.bindings.envelope} [[taglist]] ${bindingsToStr cfg.bindings.taglist} [[thread]] ${bindingsToStr cfg.bindings.thread} [accounts] ${concatStringsSep "\n" (map accountStr mailAccounts)} ''; in { options = { programs.alot = { enable = mkEnableOption "Alot"; extraHookFile = mkOption { type = types.lines; default = ""; description = '' Content to append to the hooks file (after home-manager python code). ''; }; bindings = mkOption { type = types.submodule { options = { global = mkOption { type = types.attrsOf types.str; default = {}; description = "Global keybindings."; }; bufferlist = mkOption { type = types.attrsOf types.str; default = {}; description = "Bufferlist mode keybindings."; }; search = mkOption { type = types.attrsOf types.str; default = {}; description = "Search mode keybindings."; }; envelope = mkOption { type = types.attrsOf types.str; default = {}; description = "Envelope mode keybindings."; }; taglist = mkOption { type = types.attrsOf types.str; default = {}; description = "Taglist mode keybindings."; }; thread = mkOption { type = types.attrsOf types.str; default = {}; description = "Thread mode keybindings."; }; }; }; default = {}; description = '' Bindings. ''; }; extraConfig = mkOption { type = types.lines; default = '' auto_remove_unread = True ask_subject = False handle_mouse = True initial_command = "search tag:inbox AND NOT tag:killed" input_timeout = 0.3 prefer_plaintext = True thread_indent_replies = 4 ''; description = '' Extra lines added to alot configuration file. ''; }; }; accounts.email.accounts = mkOption { options = [ { alot = { enable = mkEnableOption "alot"; contactCompletionCommand = mkOption { type = types.nullOr types.str; default = null; description = '' Command to run to send a message. See for more advice. ''; }; sendMailCommand = mkOption { type = types.nullOr types.str; default = null; description = '' Command to send a mail. ''; }; }; } ]; }; }; config = mkIf cfg.enable { home.packages = [ pkgs.alot ]; xdg.configFile."alot/config".text = configFile alotAccounts; xdg.configFile."alot/hm_hooks".text = '' # Home-manager custom hooks '' + cfg.extraHookFile; }; }