Skip to content

Commit 2b5c707

Browse files
committed
msmtp: add new option to delegate use to msmtpq
Add option `programs.msmtp.offlineSupport` which when enabled delegates the usage of `msmtp` to `msmtpq` script. This is achieved by an internal option `msmtpCommand` which should be called when `msmtp` is used by another module.
1 parent 8b55a6a commit 2b5c707

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

modules/programs/aerc/accounts.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ in
243243
// optPwCmd "outgoing" passwordCommand;
244244

245245
msmtp = cfg: {
246-
outgoing = "msmtpq --read-envelope-from --read-recipients";
246+
outgoing = "${config.msmtp.msmtpCommand} --read-envelope-from --read-recipients";
247247
};
248248

249249
};

modules/programs/alot/accounts.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ in
5858

5959
config = lib.mkIf config.notmuch.enable {
6060
alot.sendMailCommand = lib.mkOptionDefault (
61-
if config.msmtp.enable then "msmtpq --read-envelope-from --read-recipients" else null
61+
if config.msmtp.enable then
62+
"${config.msmtp.msmtpCommand} --read-envelope-from --read-recipients"
63+
else
64+
null
6265
);
6366
};
6467
}

modules/programs/astroid/accounts.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
config = lib.mkIf config.notmuch.enable {
2828
astroid.sendMailCommand = lib.mkIf config.msmtp.enable (
29-
lib.mkOptionDefault "msmtpq --read-envelope-from --read-recipients"
29+
lib.mkOptionDefault "${config.msmtp.msmtpCommand} --read-envelope-from --read-recipients"
3030
);
3131
};
3232
}

modules/programs/msmtp/default.nix

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ in
5252
{
5353

5454
options = {
55-
programs.msmtp = {
55+
programs.msmtp = rec {
5656
enable = lib.mkEnableOption "msmtp";
5757

5858
package = lib.mkPackageOption pkgs "msmtp" { };
@@ -114,6 +114,23 @@ in
114114
See <https://marlam.de/msmtp/msmtprc.txt> for examples.
115115
'';
116116
};
117+
118+
msmtpCommand = mkOption {
119+
type = types.package;
120+
internal = true;
121+
readOnly = true;
122+
default = if offlineSupport then "${pkgs.msmtp}/bin/msmtpq" else "${pkgs.msmtp}/bin/msmtp";
123+
};
124+
125+
offlineSupport = lib.mkOption {
126+
type = types.bool;
127+
default = true;
128+
description = ''
129+
Use msmtpq script instead of msmtp. The script allows an offline
130+
first workflow by adding all mails to a queue regardless of the
131+
network status, and flushing them later.
132+
'';
133+
};
117134
};
118135

119136
accounts.email.accounts = mkOption {
@@ -135,7 +152,7 @@ in
135152
(lib.mkIf (cfg.extraAccounts != "") (lib.mkAfter cfg.extraAccounts))
136153
];
137154

138-
home.sessionVariables = {
155+
home.sessionVariables = lib.optionalAttrs cfg.offlineSupport {
139156
MSMTPQ_Q = "${config.xdg.dataHome}/msmtp/queue";
140157
MSMTPQ_LOG = "${config.xdg.dataHome}/msmtp/queue.log";
141158
};

modules/programs/neomutt/accounts.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ in
6161

6262
sendMailCommand = mkOption {
6363
type = types.nullOr types.str;
64-
default = if config.msmtp.enable then "msmtpq --read-envelope-from --read-recipients" else null;
64+
default =
65+
if config.msmtp.enable then
66+
"${config.msmtp.msmtpCommand} --read-envelope-from --read-recipients"
67+
else
68+
null;
6569
defaultText = lib.literalExpression ''
6670
if config.msmtp.enable then
6771
"msmtpq --read-envelope-from --read-recipients"

0 commit comments

Comments
 (0)