2020-12-03 21:23:20 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.msmtp;
|
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = with maintainers; [ pacien ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.msmtp = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "msmtp - an SMTP client");
|
2020-12-03 21:23:20 +00:00
|
|
|
|
|
|
|
setSendmail = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-12-03 21:23:20 +00:00
|
|
|
Whether to set the system sendmail to msmtp's.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaults = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
aliases = "/etc/aliases";
|
|
|
|
port = 587;
|
|
|
|
tls = true;
|
|
|
|
};
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-12-03 21:23:20 +00:00
|
|
|
Default values applied to all accounts.
|
|
|
|
See msmtp(1) for the available options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
accounts = mkOption {
|
|
|
|
type = with types; attrsOf attrs;
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
"default" = {
|
|
|
|
host = "smtp.example";
|
|
|
|
auth = true;
|
|
|
|
user = "someone";
|
|
|
|
passwordeval = "cat /secrets/password.txt";
|
|
|
|
};
|
|
|
|
};
|
2022-08-14 07:03:30 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-12-03 21:23:20 +00:00
|
|
|
Named accounts and their respective configurations.
|
|
|
|
The special name "default" allows a default account to be defined.
|
|
|
|
See msmtp(1) for the available options.
|
|
|
|
|
|
|
|
Use `programs.msmtp.extraConfig` instead of this attribute set-based
|
|
|
|
option if ordered account inheritance is needed.
|
|
|
|
|
|
|
|
It is advised to use the `passwordeval` setting to read the password
|
|
|
|
from a secret file to avoid having it written in the world-readable
|
|
|
|
nix store. The password file must end with a newline (`\n`).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-12-03 21:23:20 +00:00
|
|
|
Extra lines to add to the msmtp configuration verbatim.
|
|
|
|
See msmtp(1) for the syntax and available options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.msmtp ];
|
|
|
|
|
|
|
|
services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail {
|
|
|
|
program = "sendmail";
|
|
|
|
source = "${pkgs.msmtp}/bin/sendmail";
|
|
|
|
setuid = false;
|
|
|
|
setgid = false;
|
2021-06-09 23:47:55 +00:00
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
2020-12-03 21:23:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."msmtprc".text = let
|
|
|
|
mkValueString = v:
|
|
|
|
if v == true then "on"
|
|
|
|
else if v == false then "off"
|
|
|
|
else generators.mkValueStringDefault {} v;
|
|
|
|
mkKeyValueString = k: v: "${k} ${mkValueString v}";
|
|
|
|
mkInnerSectionString =
|
|
|
|
attrs: concatStringsSep "\n" (mapAttrsToList mkKeyValueString attrs);
|
|
|
|
mkAccountString = name: attrs: ''
|
|
|
|
account ${name}
|
|
|
|
${mkInnerSectionString attrs}
|
|
|
|
'';
|
|
|
|
in ''
|
|
|
|
defaults
|
|
|
|
${mkInnerSectionString cfg.defaults}
|
|
|
|
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList mkAccountString cfg.accounts)}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|