mirror of
https://github.com/nix-community/home-manager
synced 2024-11-30 06:59:45 +01:00
alot: add structured settings
- Also support tags. - Optionally write the hooks file. PR #812
This commit is contained in:
parent
642d9ffe24
commit
10673bff4c
5 changed files with 171 additions and 13 deletions
|
@ -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}]]" ]
|
||||
|
@ -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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
37
tests/modules/programs/alot/alot-expected.conf
Normal file
37
tests/modules/programs/alot/alot-expected.conf
Normal 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]]]
|
36
tests/modules/programs/alot/alot.nix
Normal file
36
tests/modules/programs/alot/alot.nix
Normal 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}
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
1
tests/modules/programs/alot/default.nix
Normal file
1
tests/modules/programs/alot/default.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ alot = ./alot.nix; }
|
Loading…
Reference in a new issue