diff --git a/modules/programs/msmtp/default.nix b/modules/programs/msmtp/default.nix index 137864879..a597ceb90 100644 --- a/modules/programs/msmtp/default.nix +++ b/modules/programs/msmtp/default.nix @@ -46,17 +46,6 @@ let from ${alias} '') aliases ); - - configFile = mailAccounts: '' - # Generated by Home Manager. - - ${cfg.extraConfig} - - ${lib.concatStringsSep "\n\n" (map accountStr mailAccounts)} - - ${cfg.extraAccounts} - ''; - in { @@ -66,9 +55,36 @@ in package = lib.mkPackageOption pkgs "msmtp" { }; + configContent = mkOption { + default = ""; + type = types.lines; + example = lib.literalExpression '' + lib.mkOrder 1200 '''' + set syslog + ''''; + ''; + description = '' + Content added to msmtp config. + See for examples. + + Note, if running msmtp fails with the error message "account default + was already defined" then you probably have an account command here. + Account commands should be placed in + [](#opt-accounts.email.accounts._name_.msmtp.extraConfig). + ''; + }; + extraConfig = mkOption { type = types.lines; default = ""; + visible = false; + apply = + x: + lib.warnIfNot (x == "") '' + `programs.msmtp.extraConfig` is deprecated, use `programs.msmtp.configContent` instead. + + Example: programs.msmtp.configContent = lib.mkBefore "set syslog"; + '' x; description = '' Extra configuration lines to add to {file}`~/.msmtprc`. See for examples. @@ -83,6 +99,14 @@ in extraAccounts = mkOption { type = types.lines; default = ""; + visible = false; + apply = + x: + lib.warnIfNot (x == "") '' + `programs.msmtp.extraAccounts` is deprecated, use `programs.msmtp.configContent` instead. + + Example: programs.msmtp.configContent = lib.mkAfter "set syslog"; + '' x; description = '' Extra configuration lines to add to the end of {file}`~/.msmtprc`. See for examples. @@ -95,14 +119,25 @@ in }; }; - config = lib.mkIf cfg.enable { - home.packages = [ cfg.package ]; + config = lib.mkIf cfg.enable ( + lib.mkMerge [ + { + home.packages = [ cfg.package ]; - xdg.configFile."msmtp/config".text = configFile msmtpAccounts; + xdg.configFile."msmtp/config".text = cfg.configContent; - home.sessionVariables = { - MSMTPQ_Q = "${config.xdg.dataHome}/msmtp/queue"; - MSMTPQ_LOG = "${config.xdg.dataHome}/msmtp/queue.log"; - }; - }; + programs.msmtp.configContent = lib.mkMerge [ + (lib.mkBefore "# Generated by Home Manager.") + (lib.mkIf (cfg.extraConfig != "") (lib.mkBefore cfg.extraConfig)) + (lib.concatStringsSep "\n\n" (map accountStr msmtpAccounts)) + (lib.mkIf (cfg.extraAccounts != "") (lib.mkAfter cfg.extraAccounts)) + ]; + + home.sessionVariables = { + MSMTPQ_Q = "${config.xdg.dataHome}/msmtp/queue"; + MSMTPQ_LOG = "${config.xdg.dataHome}/msmtp/queue.log"; + }; + } + ] + ); }