fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . programs . lieer ; 7 8lieerAccounts = 9filter ( a :a . lieer . enable ) ( attrValues config . accounts . . accounts ); 10 11nonGmailAccounts = 12map ( a :a . name ) ( filter ( a :a . flavor != "gmail.com" ) lieerAccounts ); 13 14nonGmailConfigHelp = 15map ( name :''accounts.email.accounts. ${ name } .flavor = "gmail.com";'' ) 16nonGmailAccounts ; 17 18missingNotmuchAccounts = map ( a :a . name ) 19( filter ( a :! a . notmuch . enable && a . lieer . notmuchSetupWarning ) 20lieerAccounts ); 21 22notmuchConfigHelp = 23map ( name :"accounts.email.accounts. ${ name } .notmuch.enable = true;" ) 24missingNotmuchAccounts ; 25 26settingsFormat = pkgs . formats . json { }; 27 28configFile = account :{ 29name = " ${ account . maildir . absPath } /.gmailieer.json" ; 30value . source = settingsFormat . generate "lieer- ${ account . address } .json" 31({ account = account . address ; } // account . lieer . settings ); 32}; 33 34settingsOpts = { 35drop_non_existing_label = mkOption { 36type = types . bool ; 37default = false ; 38description = '' 39Allow missing labels on the Gmail side to be dropped. 40'' ; 41}; 42 43file_extension = mkOption { 44type = types . str ; 45default = "" ; 46example = "mbox" ; 47description = '' 48Extension to include in local file names, which can be useful 49for indexing with third-party programs. 50'' ; 51}; 52 53ignore_empty_history = mkOption { 54type = types . bool ; 55default = false ; 56description = '' 57Work around a Gmail API quirk where an empty change history 58is sometimes returned. 59 60See this 61[GitHub issue](https://github.com/gauteh/lieer/issues/120) 62for more details. 63'' ; 64}; 65 66ignore_remote_labels = mkOption { 67type = types . listOf types . str ; 68default = [ 69"CATEGORY_FORUMS" 70"CATEGORY_PROMOTIONS" 71"CATEGORY_UPDATES" 72"CATEGORY_SOCIAL" 73"CATEGORY_PERSONAL" 74]; 75description = '' 76Set Gmail labels to ignore when syncing from remote labels to 77local tags (before translations). 78'' ; 79}; 80 81ignore_tags = mkOption { 82type = types . listOf types . str ; 83default = [ ]; 84description = '' 85Set labels to ignore when syncing from local tags to 86remote labels (after translations). 87'' ; 88}; 89 90local_trash_tag = mkOption { 91type = types . str ; 92default = "trash" ; 93description = '' 94Local tag to which the remote Gmail 'TRASH' label is translated. 95'' ; 96}; 97 98remove_local_messages = mkOption { 99type = types . bool ; 100default = true ; 101description = '' 102Remove local messages that have been deleted on the remote. 103'' ; 104}; 105 106replace_slash_with_dot = mkOption { 107type = types . bool ; 108default = false ; 109description = '' 110Replace '/' with '.' in Gmail labels. 111'' ; 112}; 113 114timeout = mkOption { 115type = types . ints . unsigned ; 116default = 600 ; 117description = '' 118HTTP timeout in seconds. 0 means forever or system timeout. 119'' ; 120}; 121}; 122 123syncOpts = { 124enable = mkEnableOption "lieer synchronization service" ; 125 126frequency = mkOption { 127type = types . str ; 128default = "*:0/5" ; 129description = '' 130How often to synchronize the account. 131 132This value is passed to the systemd timer configuration as the 133onCalendar option. See 134{manpage}`systemd.time(7)` 135for more information about the format. 136'' ; 137}; 138}; 139 140lieerOpts = { 141enable = mkEnableOption "lieer Gmail synchronization for notmuch" ; 142 143notmuchSetupWarning = mkOption { 144type = types . bool ; 145default = true ; 146description = '' 147Warn if Notmuch is not also enabled for this account. 148 149This can safely be disabled if {command}`notmuch init` 150has been used to configure this account outside of Home 151Manager. 152'' ; 153}; 154 155settings = mkOption { 156type = types . submodule { 157freeformType = settingsFormat . type ; 158options = settingsOpts ; 159}; 160default = { }; 161description = '' 162Settings which are applied to {file}`.gmailieer.json` 163for the account. 164 165See the [lieer manual](https://github.com/gauteh/lieer/) 166for documentation of settings not explicitly covered by this module. 167'' ; 168}; 169 170sync = syncOpts ; 171}; 172 173lieerModule = types . submodule { 174imports = [ 175( mkRenamedOptionModule [ "lieer" "dropNonExistingLabels" ] [ 176"lieer" 177"settings" 178"drop_non_existing_label" 179]) 180( mkRenamedOptionModule [ "lieer" "ignoreTagsRemote" ] [ 181"lieer" 182"settings" 183"ignore_remote_labels" 184]) 185( mkRenamedOptionModule [ "lieer" "ignoreTagsLocal" ] [ 186"lieer" 187"settings" 188"ignore_tags" 189]) 190( mkRenamedOptionModule [ "lieer" "timeout" ] [ 191"lieer" 192"settings" 193"timeout" 194]) 195( mkRenamedOptionModule [ "lieer" "replaceSlashWithDot" ] [ 196"lieer" 197"settings" 198"replace_slash_with_dot" 199]) 200]; 201 202options = { 203lieer = lieerOpts ; 204 205warnings = mkOption { 206type = types . listOf types . str ; 207default = [ ]; 208internal = true ; 209visible = false ; 210}; 211}; 212}; 213 214renamedOptions = account : 215let prefix = [ "accounts" "email" "accounts" account . name "lieer" ]; 216in [ 217( mkRenamedOptionModule ( prefix ++ [ "dropNonExistingLabels" ]) 218( prefix ++ [ "settings" "drop_non_existing_label" ])) 219( mkRenamedOptionModule ( prefix ++ [ "ignoreTagsRemote" ]) 220( prefix ++ [ "settings" "ignore_remote_labels" ])) 221( mkRenamedOptionModule ( prefix ++ [ "ignoreTagsLocal" ]) 222( prefix ++ [ "settings" "ignore_tags" ])) 223( mkRenamedOptionModule ( prefix ++ [ "timeout" ]) 224( prefix ++ [ "settings" "timeout" ])) 225( mkRenamedOptionModule ( prefix ++ [ "replaceSlashWithDot" ]) 226( prefix ++ [ "settings" "replace_slash_with_dot" ])) 227]; 228 229in { 230meta . maintainers = [ maintainers . tadfisher ]; 231 232options = { 233programs . lieer = { 234enable = mkEnableOption "lieer Gmail synchronization for notmuch" ; 235 236package = mkOption { 237type = types . package ; 238default = pkgs . lieer ; 239defaultText = "pkgs.lieer" ; 240description = '' 241lieer package to use. 242'' ; 243}; 244}; 245 246accounts . . accounts = 247mkOption { type = with types ; attrsOf lieerModule ; }; 248}; 249 250config = mkIf cfg . enable ( mkMerge [ 251( mkIf ( missingNotmuchAccounts != [ ]) { 252warnings = [ '' 253lieer is enabled for the following email accounts, but notmuch is not: 254 255${ concatStringsSep "\n " missingNotmuchAccounts } 256 257Notmuch can be enabled with: 258 259${ concatStringsSep "\n " notmuchConfigHelp } 260 261If you have configured notmuch outside of Home Manager, you can suppress this 262warning with: 263 264programs.lieer.notmuchSetupWarning = false; 265'' ]; 266}) 267 268{ 269assertions = [{ 270assertion = nonGmailAccounts == [ ]; 271message = '' 272lieer is enabled for non-Gmail accounts: 273 274${ concatStringsSep "\n " nonGmailAccounts } 275 276If these accounts are actually Gmail accounts, you can 277fix this error with: 278 279${ concatStringsSep "\n " nonGmailConfigHelp } 280'' ; 281}]; 282 283warnings = flatten ( map ( account :account . warnings ) lieerAccounts ); 284 285home . packages = [ cfg . package ]; 286 287# Notmuch should ignore non-mail files created by lieer. 288programs . notmuch . new . ignore = [ "/.*[.](json|lock|bak)$/" ]; 289 290home . file = listToAttrs ( map configFile lieerAccounts ); 291} 292]); 293}