fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . notmuch ; 8 9mkIniKeyValue = key :value : 10let 11tweakVal = v : 12if isString v then 13v 14else if isList v then 15concatMapStringsSep ";" tweakVal v 16else if isBool v then 17( if v then "true" else "false" ) 18else 19toString v ; 20in " ${ key } = ${ tweakVal value } " ; 21 22notmuchIni = recursiveUpdate { 23database = { path = config . accounts . . maildirBasePath ; }; 24 25maildir = { synchronize_flags = cfg . maildir . synchronizeFlags ; }; 26 27new = { 28ignore = cfg . new . ignore ; 29tags = cfg . new . tags ; 30}; 31 32user = let 33accounts = filter ( a :a . notmuch . enable ) 34( attrValues config . accounts . . accounts ); 35primary = filter ( a :a . primary ) accounts ; 36secondaries = filter ( a :! a . primary ) accounts ; 37in { 38name = catAttrs "realName" primary ; 39primary_email = catAttrs "address" primary ; 40other_email = catAttrs "aliases" primary ++ catAttrs "address" secondaries 41++ catAttrs "aliases" secondaries ; 42}; 43 44search = { exclude_tags = cfg . search . excludeTags ; }; 45} cfg . extraConfig ; 46 47in { 48options = { 49programs . notmuch = { 50enable = mkEnableOption "Notmuch mail indexer" ; 51 52new = mkOption { 53type = types . submodule { 54options = { 55ignore = mkOption { 56type = types . listOf types . str ; 57default = [ ]; 58description = '' 59A list to specify files and directories that will not be 60searched for messages by {command}`notmuch new`. 61'' ; 62}; 63 64tags = mkOption { 65type = types . listOf types . str ; 66default = [ "unread" "inbox" ]; 67example = [ "new" ]; 68description = '' 69A list of tags that will be added to all messages 70incorporated by {command}`notmuch new`. 71'' ; 72}; 73}; 74}; 75default = { }; 76description = '' 77Options related to email processing performed by 78{command}`notmuch new`. 79'' ; 80}; 81 82extraConfig = mkOption { 83type = types . attrsOf ( types . attrsOf types . str ); 84default = { }; 85description = '' 86Options that should be appended to the notmuch configuration file. 87'' ; 88}; 89 90hooks = { 91preNew = mkOption { 92type = types . lines ; 93default = "" ; 94example = "mbsync --all" ; 95description = '' 96Bash statements run before scanning or importing new 97messages into the database. 98'' ; 99}; 100 101postNew = mkOption { 102type = types . lines ; 103default = "" ; 104example = '' 105notmuch tag +nixos -- tag:new and from:nixos1@discoursemail.com 106'' ; 107description = '' 108Bash statements run after new messages have been imported 109into the database and initial tags have been applied. 110'' ; 111}; 112 113postInsert = mkOption { 114type = types . lines ; 115default = "" ; 116description = '' 117Bash statements run after a message has been inserted 118into the database and initial tags have been applied. 119'' ; 120}; 121}; 122 123maildir = { 124synchronizeFlags = mkOption { 125type = types . bool ; 126default = true ; 127description = '' 128Whether to synchronize Maildir flags. 129'' ; 130}; 131}; 132 133search = { 134excludeTags = mkOption { 135type = types . listOf types . str ; 136default = [ "deleted" "spam" ]; 137example = [ "trash" "spam" ]; 138description = '' 139A list of tags that will be excluded from search results by 140default. Using an excluded tag in a query will override that 141exclusion. 142'' ; 143}; 144}; 145}; 146 147accounts . . accounts = mkOption { 148type = with types ; 149attrsOf ( submodule { 150options . notmuch . enable = mkEnableOption "notmuch indexing" ; 151}); 152}; 153}; 154 155config = mkIf cfg . enable { 156assertions = [ 157{ 158assertion = notmuchIni . user . name != [ ]; 159message = "notmuch: Must have a user name set." ; 160} 161{ 162assertion = notmuchIni . user . primary_email != [ ]; 163message = "notmuch: Must have a user primary email address set." ; 164} 165]; 166 167home . packages = [ pkgs . notmuch ]; 168 169home . sessionVariables = { 170NOTMUCH_CONFIG = " ${ config . xdg . configHome } /notmuch/default/config" ; 171NMBGIT = " ${ config . xdg . dataHome } /notmuch/nmbug" ; 172}; 173 174xdg . configFile = let 175hook = name :cmds :{ 176"notmuch/default/hooks/ ${ name } " . source = pkgs . writeShellScript name '' 177export PATH =" ${ pkgs . notmuch } /bin '' $ { PATH:+:} $ PATH " 178export NOTMUCH_CONFIG=" ${ config . xdg . configHome } /notmuch/default/config " 179export NMBGIT=" ${ config . xdg . dataHome } /notmuch/nmbug " 180 181${ cmds } 182'' ; 183}; 184in { 185"notmuch/default/config" . text = 186let toIni = generators . toINI { mkKeyValue = mkIniKeyValue ; }; 187in '' 188# Generated by Home Manager. 189 190'' + toIni notmuchIni ; 191} 192// optionalAttrs ( cfg . hooks . preNew != "" ) ( hook "pre-new" cfg . hooks . preNew ) 193// optionalAttrs ( cfg . hooks . postNew != "" ) 194( hook "post-new" cfg . hooks . postNew ) 195// optionalAttrs ( cfg . hooks . postInsert != "" ) 196( hook "post-insert" cfg . hooks . postInsert ); 197}; 198}