summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2026-03-28 18:45:51 -0500
committerTim Keller <tjk@tjkeller.xyz>2026-03-28 18:45:51 -0500
commit23b92aaaa7702221e80199c9d47fa1f73b3722c1 (patch)
tree1ddb00e495adf08f0d7aacd4f3cecac595679d5e
parent4f39c537629bdd39f73937f93de3d369613da5be (diff)
downloadnixos-23b92aaaa7702221e80199c9d47fa1f73b3722c1.tar.xz
nixos-23b92aaaa7702221e80199c9d47fa1f73b3722c1.zip
add mailer service and zedMailer module
-rw-r--r--nixos/services/mailer.nix67
-rw-r--r--nixos/services/zfs/zed-mailer.nix20
2 files changed, 87 insertions, 0 deletions
diff --git a/nixos/services/mailer.nix b/nixos/services/mailer.nix
new file mode 100644
index 0000000..fadaaf1
--- /dev/null
+++ b/nixos/services/mailer.nix
@@ -0,0 +1,67 @@
+{ lib, pkgs, config, ... }: let
+ cfg = config.services.mail._mailer;
+in {
+ options.services.mail._mailer = {
+ enable = lib.mkEnableOption "enable msmtp mailer service";
+ sender = {
+ host = lib.mkOption {
+ type = lib.types.str;
+ description = "";
+ example = "smtp.mail.example.com";
+ };
+ user = lib.mkOption {
+ type = lib.types.str;
+ description = "";
+ example = "myname@example.com";
+ };
+ from = lib.mkOption {
+ type = lib.types.str;
+ description = "";
+ example = "myname@example.com";
+ };
+ passwordFile = lib.mkOption {
+ type = lib.types.path;
+ description = "";
+ };
+ };
+ recipient = lib.mkOption {
+ type = lib.types.str;
+ description = "";
+ example = "admin@example.com";
+ };
+ };
+
+ # https://wiki.nixos.org/wiki/ZFS#Mail_notifications_(ZFS_Event_Daemon)
+ config = lib.mkIf cfg.enable {
+ # MTA
+ programs.msmtp = {
+ enable = true;
+ setSendmail = true;
+ defaults = {
+ aliases = "/etc/aliases";
+ port = 587;
+ auth = "plain";
+ tls = "on";
+ tls_starttls = "on";
+ };
+ accounts = {
+ default = with cfg.sender; {
+ inherit host user from;
+ passwordeval = "cat ${passwordFile}";
+ };
+ };
+ };
+
+ # Configure an alias for root account.
+ # With this alias configured, all mails sent to root, such as cron job
+ # results and failed sudo login events, will be redirected to the
+ # configured email account.
+ environment.etc.aliases.text = ''
+ root: ${cfg.recipient}
+ '';
+
+ # For zed enableMail, enable sendmailSetuidWrapper
+ services.mail.sendmailSetuidWrapper.enable = true;
+ };
+}
+
diff --git a/nixos/services/zfs/zed-mailer.nix b/nixos/services/zfs/zed-mailer.nix
new file mode 100644
index 0000000..06acd1f
--- /dev/null
+++ b/nixos/services/zfs/zed-mailer.nix
@@ -0,0 +1,20 @@
+{ lib, pkgs, config, ... }: let
+ cfg = config.services.zfs._zedMailer;
+in {
+ options.services.zfs._zedMailer = {
+ enable = lib.mkEnableOption "enable zed mailer service";
+ };
+
+ # https://wiki.nixos.org/wiki/ZFS#Mail_notifications_(ZFS_Event_Daemon)
+ config = lib.mkIf cfg.enable {
+ services.zfs.zed = {
+ enableMail = true;
+ settings = {
+ ZED_EMAIL_ADDR = [ "root" ];
+ # send notification if scrub succeeds
+ ZED_NOTIFY_VERBOSE = true;
+ };
+ };
+ };
+}
+