fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4with builtins ; 5 6let 7 8cfg = config . programs . astroid ; 9 10jsonFormat = pkgs . formats . json { }; 11 12astroidAccounts = 13filterAttrs ( n :v :v . astroid . enable ) config . accounts . . accounts ; 14 15boolOpt = b :if b then "true" else "false" ; 16 17accountAttr = account : 18with account ; 19{ 20= address ; 21name = realName ; 22sendmail = astroid . sendMailCommand ; 23additional_sent_tags = "" ; 24default = boolOpt primary ; 25save_drafts_to = " ${ maildir . absPath } / ${ folders . drafts } /cur/" ; 26save_sent = "true" ; 27save_sent_to = " ${ maildir . absPath } / ${ folders . sent } /cur/" ; 28select_query = "" ; 29} // optionalAttrs ( signature . showSignature != "none" ) { 30signature_attach = boolOpt ( signature . showSignature == "attach" ); 31signature_default_on = boolOpt ( signature . showSignature != "none" ); 32signature_file = pkgs . writeText "signature.txt" signature . text ; 33signature_file_markdown = "false" ; 34signature_separate = "true" ; # prepends '--\n' to the signature 35} // optionalAttrs ( gpg != null ) { 36always_gpg_sign = boolOpt gpg . signByDefault ; 37gpgkey = gpg . key ; 38} // astroid . extraConfig ; 39 40# See https://github.com/astroidmail/astroid/wiki/Configuration-Reference 41finalConfig = let 42template = fromJSON ( readFile ./astroid-config-template.json ); 43astroidConfig = foldl' recursiveUpdate template [ 44{ 45astroid . notmuch_config = 46" ${ config . xdg . configHome } /notmuch/default/config" ; 47accounts = mapAttrs ( n :accountAttr ) astroidAccounts ; 48crypto . gpg . path = " ${ pkgs . gnupg } /bin/gpg" ; 49} 50cfg . extraConfig 51cfg . externalEditor 52]; 53in astroidConfig ; 54 55in { 56options = { 57programs . astroid = { 58enable = mkEnableOption "Astroid" ; 59 60pollScript = mkOption { 61type = types . str ; 62default = "" ; 63example = "mbsync gmail" ; 64description = '' 65Script to run to fetch/update mails. 66'' ; 67}; 68 69externalEditor = mkOption { 70type = types . nullOr types . str ; 71default = null ; 72# Converts it into JSON that can be merged into the configuration. 73apply = cmd : 74optionalAttrs ( cmd != null ) { 75editor = { 76"external_editor" = "true" ; 77"cmd" = cmd ; 78}; 79}; 80example = 81"nvim-qt -- -c 'set ft=mail' '+set fileencoding=utf-8' '+set ff=unix' '+set enc=utf-8' '+set fo+=w' %1" ; 82description = '' 83You can use the following variables: 84 85`%1` 86: file name 87 88`%2` 89: server name 90 91`%3` 92: socket ID 93 94See [Customizing editor](https://github.com/astroidmail/astroid/wiki/Customizing-editor) 95on the Astroid wiki. 96'' ; 97}; 98 99extraConfig = mkOption { 100type = jsonFormat . type ; 101default = { }; 102example = literalExpression '' 103{ 104poll.interval = 0; 105} 106'' ; 107description = '' 108JSON config that will override the default Astroid configuration. 109'' ; 110}; 111}; 112 113accounts . . accounts = mkOption { 114type = with types ; attrsOf ( submodule ( import ./astroid-accounts.nix )); 115}; 116}; 117 118config = mkIf cfg . enable { 119home . packages = [ pkgs . astroid ]; 120 121xdg . configFile . "astroid/config" . source = 122jsonFormat . generate "astroid-config" finalConfig ; 123 124xdg . configFile . "astroid/poll.sh" = { 125executable = true ; 126text = '' 127# Generated by Home Manager 128 129${ cfg . pollScript } 130'' ; 131}; 132}; 133}