alot: apply nixfmt

This commit is contained in:
Robert Helgesson 2020-05-01 22:33:05 +02:00
parent 10673bff4c
commit 70f7c9f355
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 69 additions and 95 deletions

1
format
View file

@ -33,7 +33,6 @@ find . -name '*.nix' \
! -path ./modules/misc/xdg.nix \ ! -path ./modules/misc/xdg.nix \
! -path ./modules/modules.nix \ ! -path ./modules/modules.nix \
! -path ./modules/programs/afew.nix \ ! -path ./modules/programs/afew.nix \
! -path ./modules/programs/alot.nix \
! -path ./modules/programs/bash.nix \ ! -path ./modules/programs/bash.nix \
! -path ./modules/programs/emacs.nix \ ! -path ./modules/programs/emacs.nix \
! -path ./modules/programs/firefox.nix \ ! -path ./modules/programs/firefox.nix \

View file

@ -7,20 +7,16 @@ let
cfg = config.programs.alot; cfg = config.programs.alot;
alotAccounts = filter (a: a.notmuch.enable) alotAccounts =
(attrValues config.accounts.email.accounts); filter (a: a.notmuch.enable) (attrValues config.accounts.email.accounts);
boolStr = v: if v then "True" else "False"; boolStr = v: if v then "True" else "False";
mkKeyValue = key: value: mkKeyValue = key: value:
let let value' = if isBool value then boolStr value else toString value;
value' = in "${key} = ${value'}";
if isBool value then boolStr value
else toString value;
in
"${key} = ${value'}";
mk2ndLevelSectionName = name: "[" + name + "]"; mk2ndLevelSectionName = name: "[" + name + "]";
tagSubmodule = types.submodule { tagSubmodule = types.submodule {
options = { options = {
@ -58,84 +54,66 @@ let
default = null; default = null;
description = "How to display the tag when focused."; description = "How to display the tag when focused.";
}; };
}; };
}; };
accountStr = account: with account; accountStr = account:
concatStringsSep "\n" ( with account;
[ "[[${name}]]" ] concatStringsSep "\n" ([ "[[${name}]]" ]
++ mapAttrsToList (n: v: n + "=" + v) ( ++ mapAttrsToList (n: v: n + "=" + v) ({
{ address = address;
address = address; realname = realName;
realname = realName; sendmail_command =
sendmail_command = optionalString (alot.sendMailCommand != null) alot.sendMailCommand;
optionalString (alot.sendMailCommand != null) alot.sendMailCommand; sent_box = "maildir" + "://" + maildir.absPath + "/" + folders.sent;
sent_box = "maildir" + "://" + maildir.absPath + "/" + folders.sent; draft_box = "maildir" + "://" + maildir.absPath + "/" + folders.drafts;
draft_box = "maildir" + "://"+ maildir.absPath + "/" + folders.drafts; } // optionalAttrs (aliases != [ ]) {
} aliases = concatStringsSep "," aliases;
// optionalAttrs (aliases != []) { } // optionalAttrs (gpg != null) {
aliases = concatStringsSep "," aliases; gpg_key = gpg.key;
} encrypt_by_default = if gpg.encryptByDefault then "all" else "none";
// optionalAttrs (gpg != null) { sign_by_default = boolStr gpg.signByDefault;
gpg_key = gpg.key; } // optionalAttrs (signature.showSignature != "none") {
encrypt_by_default = if gpg.encryptByDefault then "all" else "none"; signature = pkgs.writeText "signature.txt" signature.text;
sign_by_default = boolStr gpg.signByDefault; signature_as_attachment = boolStr (signature.showSignature == "attach");
} }) ++ [ alot.extraConfig ] ++ [ "[[[abook]]]" ]
// optionalAttrs (signature.showSignature != "none") { ++ mapAttrsToList (n: v: n + "=" + v) alot.contactCompletion);
signature = pkgs.writeText "signature.txt" signature.text;
signature_as_attachment =
boolStr (signature.showSignature == "attach");
}
)
++ [ alot.extraConfig ]
++ [ "[[[abook]]]" ]
++ mapAttrsToList (n: v: n + "=" + v) alot.contactCompletion
);
configFile = configFile = let
let bindingsToStr = attrSet:
bindingsToStr = attrSet: concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${v}") attrSet);
concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${v}") attrSet); in ''
in # Generated by Home Manager.
'' # See http://alot.readthedocs.io/en/latest/configuration/config_options.html
# Generated by Home Manager.
# See http://alot.readthedocs.io/en/latest/configuration/config_options.html
${generators.toKeyValue { inherit mkKeyValue; } cfg.settings} ${generators.toKeyValue { inherit mkKeyValue; } cfg.settings}
${cfg.extraConfig} ${cfg.extraConfig}
[tags] [tags]
'' '' + (let
+ ( submoduleToAttrs = m:
let filterAttrs (name: v: name != "_module" && v != null) m;
submoduleToAttrs = m: in generators.toINI { mkSectionName = mk2ndLevelSectionName; }
filterAttrs (name: v: name != "_module" && v != null) m; (mapAttrs (name: x: submoduleToAttrs x) cfg.tags)) + ''
in [bindings]
generators.toINI { mkSectionName = mk2ndLevelSectionName; } ${bindingsToStr cfg.bindings.global}
(mapAttrs (name: x: submoduleToAttrs x) cfg.tags)
)
+ ''
[bindings]
${bindingsToStr cfg.bindings.global}
[[bufferlist]] [[bufferlist]]
${bindingsToStr cfg.bindings.bufferlist} ${bindingsToStr cfg.bindings.bufferlist}
[[search]] [[search]]
${bindingsToStr cfg.bindings.search} ${bindingsToStr cfg.bindings.search}
[[envelope]] [[envelope]]
${bindingsToStr cfg.bindings.envelope} ${bindingsToStr cfg.bindings.envelope}
[[taglist]] [[taglist]]
${bindingsToStr cfg.bindings.taglist} ${bindingsToStr cfg.bindings.taglist}
[[thread]] [[thread]]
${bindingsToStr cfg.bindings.thread} ${bindingsToStr cfg.bindings.thread}
[accounts] [accounts]
${concatStringsSep "\n\n" (map accountStr alotAccounts)} ${concatStringsSep "\n\n" (map accountStr alotAccounts)}
''; '';
in in {
{
options.programs.alot = { options.programs.alot = {
enable = mkOption { enable = mkOption {
type = types.bool; type = types.bool;
@ -161,42 +139,42 @@ in
options = { options = {
global = mkOption { global = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Global keybindings."; description = "Global keybindings.";
}; };
bufferlist = mkOption { bufferlist = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Bufferlist mode keybindings."; description = "Bufferlist mode keybindings.";
}; };
search = mkOption { search = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Search mode keybindings."; description = "Search mode keybindings.";
}; };
envelope = mkOption { envelope = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Envelope mode keybindings."; description = "Envelope mode keybindings.";
}; };
taglist = mkOption { taglist = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Taglist mode keybindings."; description = "Taglist mode keybindings.";
}; };
thread = mkOption { thread = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Thread mode keybindings."; description = "Thread mode keybindings.";
}; };
}; };
}; };
default = {}; default = { };
description = '' description = ''
Keybindings. Keybindings.
''; '';
@ -204,16 +182,14 @@ in
tags = mkOption { tags = mkOption {
type = types.attrsOf tagSubmodule; type = types.attrsOf tagSubmodule;
default = {}; default = { };
description = "How to display the tags."; description = "How to display the tags.";
}; };
settings = mkOption { settings = mkOption {
type = with types; type = with types;
let let primitive = either (either (either str int) bool) float;
primitive = either (either (either str int) bool) float; in attrsOf primitive;
in
attrsOf primitive;
default = { default = {
initial_command = "search tag:inbox AND NOT tag:killed"; initial_command = "search tag:inbox AND NOT tag:killed";
auto_remove_unread = true; auto_remove_unread = true;
@ -242,15 +218,14 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ pkgs.alot ]; home.packages = [ pkgs.alot ];
xdg.configFile."alot/config".text = configFile; xdg.configFile."alot/config".text = configFile;
xdg.configFile."alot/hooks.py" = mkIf (cfg.hooks != "") { xdg.configFile."alot/hooks.py" = mkIf (cfg.hooks != "") {
text = '' text = ''
# Generated by Home Manager. # Generated by Home Manager.
'' '' + cfg.hooks;
+ cfg.hooks;
}; };
}; };
} }