fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1# alot config loader is sensitive to leading space ! 2{ config , lib , pkgs , ...} : 3 4with lib ; 5 6let 7 8cfg = config . programs . alot ; 9 10enabledAccounts = 11filter ( a :a . notmuch . enable ) ( attrValues config . accounts . . accounts ); 12 13# sorted: primary first 14alotAccounts = sort ( a :b :! ( a . primary -> b . primary )) enabledAccounts ; 15 16boolStr = v :if v then "True" else "False" ; 17 18mkKeyValue = key :value : 19let value' = if isBool value then boolStr value else toString value ; 20in " ${ key } = ${ value' } " ; 21 22mk2ndLevelSectionName = name :"[" + name + "]" ; 23 24tagSubmodule = types . submodule { 25options = { 26translated = mkOption { 27type = types . nullOr types . str ; 28description = '' 29Fixed string representation for this tag. The tag can be 30hidden from view, if the key translated is set to 31`""`, the empty string. 32'' ; 33}; 34 35translation = mkOption { 36type = types . nullOr types . str ; 37default = null ; 38description = '' 39A pair of strings that define a regular substitution to 40compute the string representation on the fly using 41`re.sub`. 42'' ; 43}; 44 45normal = mkOption { 46type = types . nullOr types . str ; 47default = null ; 48example = "'','', 'white','light red', 'white','#d66'" ; 49description = '' 50How to display the tag when unfocused. 51See <https://alot.readthedocs.io/en/latest/configuration/theming.html#tagstring-formatting>. 52'' ; 53}; 54 55focus = mkOption { 56type = types . nullOr types . str ; 57default = null ; 58description = "How to display the tag when focused." ; 59}; 60}; 61}; 62 63accountStr = account : 64with account ; 65concatStringsSep "\n" ([ "[[ ${ name } ]]" ] 66++ mapAttrsToList ( n :v :n + "=" + v ) ({ 67address = address ; 68realname = realName ; 69sendmail_command = 70optionalString ( alot . sendMailCommand != null ) alot . sendMailCommand ; 71} // optionalAttrs ( folders . sent != null ) { 72sent_box = "maildir" + "://" + maildir . absPath + "/" + folders . sent ; 73} // optionalAttrs ( folders . drafts != null ) { 74draft_box = "maildir" + "://" + maildir . absPath + "/" + folders . drafts ; 75} // optionalAttrs ( aliases != [ ]) { 76aliases = concatStringsSep "," aliases ; 77} // optionalAttrs ( gpg != null ) { 78gpg_key = gpg . key ; 79encrypt_by_default = if gpg . encryptByDefault then "all" else "none" ; 80sign_by_default = boolStr gpg . signByDefault ; 81} // optionalAttrs ( signature . showSignature != "none" ) { 82signature = pkgs . writeText "signature.txt" signature . text ; 83signature_as_attachment = boolStr ( signature . showSignature == "attach" ); 84}) ++ [ alot . extraConfig ] ++ [ "[[[abook]]]" ] 85++ mapAttrsToList ( n :v :n + "=" + v ) alot . contactCompletion ); 86 87configFile = let 88bindingsToStr = attrSet : 89concatStringsSep "\n" ( mapAttrsToList ( n :v :" ${ n } = ${ v } " ) attrSet ); 90in '' 91# Generated by Home Manager. 92# See http://alot.readthedocs.io/en/latest/configuration/config_options.html 93 94${ generators . toKeyValue { inherit mkKeyValue ; } cfg . settings } 95${ cfg . extraConfig } 96[tags] 97'' + ( let 98submoduleToAttrs = m : 99filterAttrs ( name :v :name != "_module" && v != null ) m ; 100in generators . toINI { mkSectionName = mk2ndLevelSectionName ; } 101( mapAttrs ( name :x :submoduleToAttrs x ) cfg . tags )) + '' 102[bindings] 103${ bindingsToStr cfg . bindings . global } 104 105[[bufferlist]] 106${ bindingsToStr cfg . bindings . bufferlist } 107[[search]] 108${ bindingsToStr cfg . bindings . search } 109[[envelope]] 110${ bindingsToStr cfg . bindings . envelope } 111[[taglist]] 112${ bindingsToStr cfg . bindings . taglist } 113[[thread]] 114${ bindingsToStr cfg . bindings . thread } 115 116[accounts] 117 118${ concatStringsSep "\n\n" ( map accountStr alotAccounts )} 119'' ; 120 121in { 122options = { 123programs . alot = { 124enable = mkOption { 125type = types . bool ; 126default = false ; 127example = true ; 128description = '' 129Whether to enable the Alot mail user agent. Alot uses the 130Notmuch email system and will therefore be automatically 131enabled for each email account that is managed by Notmuch. 132'' ; 133}; 134 135hooks = mkOption { 136type = types . lines ; 137default = "" ; 138description = '' 139Content of the hooks file. 140'' ; 141}; 142 143bindings = mkOption { 144type = types . submodule { 145options = { 146global = mkOption { 147type = types . attrsOf types . str ; 148default = { }; 149description = "Global keybindings." ; 150}; 151 152bufferlist = mkOption { 153type = types . attrsOf types . str ; 154default = { }; 155description = "Bufferlist mode keybindings." ; 156}; 157 158search = mkOption { 159type = types . attrsOf types . str ; 160default = { }; 161description = "Search mode keybindings." ; 162}; 163 164envelope = mkOption { 165type = types . attrsOf types . str ; 166default = { }; 167description = "Envelope mode keybindings." ; 168}; 169 170taglist = mkOption { 171type = types . attrsOf types . str ; 172default = { }; 173description = "Taglist mode keybindings." ; 174}; 175 176thread = mkOption { 177type = types . attrsOf types . str ; 178default = { }; 179description = "Thread mode keybindings." ; 180}; 181}; 182}; 183default = { }; 184description = '' 185Keybindings. 186'' ; 187}; 188 189tags = mkOption { 190type = types . attrsOf tagSubmodule ; 191default = { }; 192description = "How to display the tags." ; 193}; 194 195settings = mkOption { 196type = with types ; 197let primitive = either ( either ( either str int ) bool ) float ; 198in attrsOf primitive ; 199default = { 200initial_command = "search tag:inbox AND NOT tag:killed" ; 201auto_remove_unread = true ; 202handle_mouse = true ; 203prefer_plaintext = true ; 204}; 205example = literalExpression '' 206{ 207auto_remove_unread = true; 208ask_subject = false; 209thread_indent_replies = 2; 210} 211'' ; 212description = '' 213Configuration options added to alot configuration file. 214'' ; 215}; 216 217extraConfig = mkOption { 218type = types . lines ; 219default = "" ; 220description = '' 221Extra lines added to alot configuration file. 222'' ; 223}; 224}; 225 226accounts . . accounts = mkOption { 227type = with types ; attrsOf ( submodule ( import ./alot-accounts.nix pkgs )); 228}; 229}; 230 231config = mkIf cfg . enable { 232home . packages = [ pkgs . alot ]; 233 234xdg . configFile . "alot/config" . text = configFile ; 235 236xdg . configFile . "alot/hooks.py" = mkIf ( cfg . hooks != "" ) { 237text = '' 238# Generated by Home Manager. 239'' + cfg . hooks ; 240}; 241}; 242}