nixpkgs/nixos/modules/programs/msmtp.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

117 lines
3.0 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.msmtp;
in
{
meta.maintainers = with lib.maintainers; [ pacien ];
options = {
programs.msmtp = {
enable = lib.mkEnableOption "msmtp - an SMTP client";
setSendmail = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to set the system sendmail to msmtp's.
'';
};
defaults = lib.mkOption {
type = lib.types.attrs;
default = { };
example = {
aliases = "/etc/aliases";
port = 587;
tls = true;
};
description = ''
Default values applied to all accounts.
See msmtp(1) for the available options.
'';
};
accounts = lib.mkOption {
type = with lib.types; attrsOf attrs;
default = { };
example = {
"default" = {
host = "smtp.example";
auth = true;
user = "someone";
passwordeval = "cat /secrets/password.txt";
};
};
description = ''
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 = lib.mkOption {
type = lib.types.lines;
default = "";
description = ''
Extra lines to add to the msmtp configuration verbatim.
See msmtp(1) for the syntax and available options.
'';
};
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.msmtp ];
services.mail.sendmailSetuidWrapper = lib.mkIf cfg.setSendmail {
program = "sendmail";
source = "${pkgs.msmtp}/bin/sendmail";
setuid = false;
setgid = false;
owner = "root";
group = "root";
};
environment.etc."msmtprc".text =
let
mkValueString =
v:
if v == true then
"on"
else if v == false then
"off"
else
lib.generators.mkValueStringDefault { } v;
mkKeyValueString = k: v: "${k} ${mkValueString v}";
mkInnerSectionString =
attrs: builtins.concatStringsSep "\n" (lib.mapAttrsToList mkKeyValueString attrs);
mkAccountString = name: attrs: ''
account ${name}
${mkInnerSectionString attrs}
'';
in
''
defaults
${mkInnerSectionString cfg.defaults}
${builtins.concatStringsSep "\n" (lib.mapAttrsToList mkAccountString cfg.accounts)}
${cfg.extraConfig}
'';
};
}