1 { config, lib, pkgs, ... }:
4 cfg = config.programs.msmtp;
7 meta.maintainers = with lib.maintainers; [ pacien ];
11 enable = lib.mkEnableOption "msmtp - an SMTP client";
13 setSendmail = lib.mkOption {
14 type = lib.types.bool;
17 Whether to set the system sendmail to msmtp's.
21 defaults = lib.mkOption {
22 type = lib.types.attrs;
25 aliases = "/etc/aliases";
30 Default values applied to all accounts.
31 See msmtp(1) for the available options.
35 accounts = lib.mkOption {
36 type = with lib.types; attrsOf attrs;
40 host = "smtp.example";
43 passwordeval = "cat /secrets/password.txt";
47 Named accounts and their respective configurations.
48 The special name "default" allows a default account to be defined.
49 See msmtp(1) for the available options.
51 Use `programs.msmtp.extraConfig` instead of this attribute set-based
52 option if ordered account inheritance is needed.
54 It is advised to use the `passwordeval` setting to read the password
55 from a secret file to avoid having it written in the world-readable
56 nix store. The password file must end with a newline (`\n`).
60 extraConfig = lib.mkOption {
61 type = lib.types.lines;
64 Extra lines to add to the msmtp configuration verbatim.
65 See msmtp(1) for the syntax and available options.
71 config = lib.mkIf cfg.enable {
72 environment.systemPackages = [ pkgs.msmtp ];
74 services.mail.sendmailSetuidWrapper = lib.mkIf cfg.setSendmail {
76 source = "${pkgs.msmtp}/bin/sendmail";
83 environment.etc."msmtprc".text = let
85 if v == true then "on"
86 else if v == false then "off"
87 else lib.generators.mkValueStringDefault {} v;
88 mkKeyValueString = k: v: "${k} ${mkValueString v}";
89 mkInnerSectionString =
90 attrs: builtins.concatStringsSep "\n" (lib.mapAttrsToList mkKeyValueString attrs);
91 mkAccountString = name: attrs: ''
93 ${mkInnerSectionString attrs}
97 ${mkInnerSectionString cfg.defaults}
99 ${builtins.concatStringsSep "\n" (lib.mapAttrsToList mkAccountString cfg.accounts)}