fork/home-manager
git clone https://git.julia.blue/fork/home-manager
5f433eb1
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7accounts = 8filter ( a :a . getmail . enable ) ( attrValues config . accounts . . accounts ); 9 10renderAccountConfig = account : 11with account ; 12let 13passCmd = concatMapStringsSep ", " ( x :"' ${ x } '" ) passwordCommand ; 14renderedMailboxes = concatMapStrings ( x :"' ${ x } ', " ) getmail . mailboxes ; 15retrieverType = if imap . tls . enable then 16"SimpleIMAPSSLRetriever" 17else 18"SimpleIMAPRetriever" ; 19destination = if getmail . destinationCommand != null then { 20destinationType = "MDA_external" ; 21destinationPath = getmail . destinationCommand ; 22} else { 23destinationType = "Maildir" ; 24destinationPath = " ${ maildir . absPath } /" ; 25}; 26renderGetmailBoolean = v :if v then "true" else "false" ; 27in '' 28# Generated by Home-Manager. 29[retriever] 30type = ${ retrieverType } 31server = ${ imap . host } 32${ optionalString ( imap . port != null ) "port = ${ toString imap . port } " } 33username = ${ userName } 34password_command = ( ${ passCmd } ) 35mailboxes = ( ${ renderedMailboxes } ) 36 37[destination] 38type = ${ destination . destinationType } 39path = ${ destination . destinationPath } 40 41[options] 42delete = ${ renderGetmailBoolean getmail . delete } 43read_all = ${ renderGetmailBoolean getmail . readAll } 44'' ; 45getmailEnabled = length ( filter ( a :a . getmail . enable ) accounts ) > 0 ; 46# Watch out! This is used by the getmail.service too! 47renderConfigFilepath = a : 48".getmail/getmail ${ if a . primary then "rc" else a . name } " ; 49 50in { 51options = { 52accounts . . accounts = mkOption { 53type = with types ; attrsOf ( submodule ( import ./getmail-accounts.nix )); 54}; 55}; 56 57config = mkIf getmailEnabled { 58assertions = [ 59( hm . assertions . assertPlatform "programs.getmail" pkgs platforms . linux ) 60]; 61 62home . file = foldl' ( a :b :a // b ) { } 63( map ( a :{ " ${ renderConfigFilepath a } " . text = renderAccountConfig a ; }) 64accounts ); 65}; 66}