blob: 8a04acb3b7ea6faba196f086d678d598efa8f2a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
{ 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}
'';
};
}
|