1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

alot: add structured settings

- Also support tags.

- Optionally write the hooks file.

PR #812
This commit is contained in:
Matthieu Coudron 2019-08-21 16:38:52 +09:00 committed by Robert Helgesson
parent 642d9ffe24
commit 10673bff4c
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 171 additions and 13 deletions

View file

@ -12,6 +12,55 @@ let
boolStr = v: if v then "True" else "False";
mkKeyValue = key: value:
let
value' =
if isBool value then boolStr value
else toString value;
in
"${key} = ${value'}";
mk2ndLevelSectionName = name: "[" + name + "]";
tagSubmodule = types.submodule {
options = {
translated = mkOption {
type = types.nullOr types.str;
description = ''
Fixed string representation for this tag. The tag can be
hidden from view, if the key translated is set to
<literal>""</literal>, the empty string.
'';
};
translation = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
A pair of strings that define a regular substitution to
compute the string representation on the fly using
<literal>re.sub</literal>.
'';
};
normal = mkOption {
type = types.nullOr types.str;
default = null;
example = "'','', 'white','light red', 'white','#d66'";
description = ''
How to display the tag when unfocused.
See <link xlink:href="https://alot.readthedocs.io/en/latest/configuration/theming.html#tagstring-formatting"/>.
'';
};
focus = mkOption {
type = types.nullOr types.str;
default = null;
description = "How to display the tag when focused.";
};
};
};
accountStr = account: with account;
concatStringsSep "\n" (
[ "[[${name}]]" ]
@ -41,7 +90,7 @@ let
++ [ alot.extraConfig ]
++ [ "[[[abook]]]" ]
++ mapAttrsToList (n: v: n + "=" + v) alot.contactCompletion
);
);
configFile =
let
@ -52,8 +101,19 @@ let
# Generated by Home Manager.
# See http://alot.readthedocs.io/en/latest/configuration/config_options.html
${generators.toKeyValue { inherit mkKeyValue; } cfg.settings}
${cfg.extraConfig}
[tags]
''
+ (
let
submoduleToAttrs = m:
filterAttrs (name: v: name != "_module" && v != null) m;
in
generators.toINI { mkSectionName = mk2ndLevelSectionName; }
(mapAttrs (name: x: submoduleToAttrs x) cfg.tags)
)
+ ''
[bindings]
${bindingsToStr cfg.bindings.global}
@ -142,17 +202,39 @@ in
'';
};
tags = mkOption {
type = types.attrsOf tagSubmodule;
default = {};
description = "How to display the tags.";
};
settings = mkOption {
type = with types;
let
primitive = either (either (either str int) bool) float;
in
attrsOf primitive;
default = {
initial_command = "search tag:inbox AND NOT tag:killed";
auto_remove_unread = true;
handle_mouse = true;
prefer_plaintext = true;
};
example = literalExample ''
{
auto_remove_unread = true;
ask_subject = false;
thread_indent_replies = 2;
}
'';
description = ''
Configuration options added to alot configuration file.
'';
};
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
'';
default = "";
description = ''
Extra lines added to alot configuration file.
'';
@ -164,10 +246,11 @@ in
xdg.configFile."alot/config".text = configFile;
xdg.configFile."alot/hooks.py".text =
''
xdg.configFile."alot/hooks.py" = mkIf (cfg.hooks != "") {
text = ''
# Generated by Home Manager.
''
+ cfg.hooks;
};
};
}

View file

@ -35,6 +35,7 @@ import nmt {
./modules/home-environment
./modules/misc/fontconfig
./modules/programs/alacritty
./modules/programs/alot
./modules/programs/bash
./modules/programs/browserpass
./modules/programs/fish

View file

@ -0,0 +1,37 @@
# Generated by Home Manager.
# See http://alot.readthedocs.io/en/latest/configuration/config_options.html
auto_remove_unread = True
handle_mouse = True
initial_command = search tag:inbox AND NOT tag:killed
prefer_plaintext = True
[tags]
[bindings]
[[bufferlist]]
[[search]]
[[envelope]]
[[taglist]]
[[thread]]
[accounts]
[[hm@example.com]]
address=hm@example.com
draft_box=maildir:///home/hm-user/Mail/hm@example.com/Drafts
realname=H. M. Test
sendmail_command=
sent_box=maildir:///home/hm-user/Mail/hm@example.com/Sent
auto_remove_unread = True
ask_subject = False
handle_mouse = True
[[[abook]]]

View file

@ -0,0 +1,36 @@
{ config, lib, pkgs, ... }:
with lib;
{
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
accounts.email.accounts = {
"hm@example.com" = {
primary = true;
notmuch.enable = true;
alot = {
contactCompletion = { };
extraConfig = ''
auto_remove_unread = True
ask_subject = False
handle_mouse = True
'';
};
imap.port = 993;
};
};
programs.alot = { enable = true; };
nixpkgs.overlays =
[ (self: super: { alot = pkgs.writeScriptBin "dummy-alot" ""; }) ];
nmt.script = ''
assertFileExists home-files/.config/alot/config
assertFileContent home-files/.config/alot/config ${./alot-expected.conf}
'';
};
}

View file

@ -0,0 +1 @@
{ alot = ./alot.nix; }