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 . msmtp ; 8 9msmtpAccounts = 10filter ( a :a . msmtp . enable ) ( attrValues config . accounts . . accounts ); 11 12onOff = p :if p then "on" else "off" ; 13 14accountStr = account : 15with account ; 16concatStringsSep "\n" ([ "account ${ name } " ] 17++ mapAttrsToList ( n :v :n + " " + v ) ({ 18host = smtp . host ; 19from = address ; 20auth = "on" ; 21user = userName ; 22tls = onOff smtp . tls . enable ; 23tls_starttls = onOff smtp . tls . useStartTls ; 24} // optionalAttrs ( msmtp . tls . fingerprint != null ) { 25tls_fingerprint = msmtp . tls . fingerprint ; 26} // optionalAttrs ( smtp . port != null ) { port = toString smtp . port ; } 27// optionalAttrs ( smtp . tls . certificatesFile != null ) { 28tls_trust_file = smtp . tls . certificatesFile ; 29} // optionalAttrs ( passwordCommand != null ) { 30passwordeval = toString passwordCommand ; 31} // msmtp . extraConfig ) ++ optional primary "account default : ${ name } " 32++ map ( alias :'' 33 34account ${ alias } : ${ name } 35from ${ alias } 36'' ) aliases ); 37 38configFile = mailAccounts :'' 39# Generated by Home Manager. 40 41${ cfg . extraConfig } 42 43${ concatStringsSep "\n\n" ( map accountStr mailAccounts )} 44 45${ cfg . extraAccounts } 46'' ; 47 48in { 49 50options = { 51programs . msmtp = { 52enable = mkEnableOption "msmtp" ; 53 54extraConfig = mkOption { 55type = types . lines ; 56default = "" ; 57description = '' 58Extra configuration lines to add to {file}`~/.msmtprc`. 59See <https://marlam.de/msmtp/msmtprc.txt> for examples. 60 61Note, if running msmtp fails with the error message "account default 62was already defined" then you probably have an account command here. 63Account commands should be placed in 64[](#opt-accounts.email.accounts._name_.msmtp.extraConfig). 65'' ; 66}; 67 68extraAccounts = mkOption { 69type = types . lines ; 70default = "" ; 71description = '' 72Extra configuration lines to add to the end of {file}`~/.msmtprc`. 73See <https://marlam.de/msmtp/msmtprc.txt> for examples. 74'' ; 75}; 76}; 77 78accounts . . accounts = mkOption { 79type = with types ; attrsOf ( submodule ( import ./msmtp-accounts.nix )); 80}; 81}; 82 83config = mkIf cfg . enable { 84home . packages = [ pkgs . msmtp ]; 85 86xdg . configFile . "msmtp/config" . text = configFile msmtpAccounts ; 87 88home . sessionVariables = { 89MSMTP_QUEUE = " ${ config . xdg . dataHome } /msmtp/queue" ; 90MSMTP_LOG = " ${ config . xdg . dataHome } /msmtp/queue.log" ; 91}; 92}; 93}