From 368af96a92a7f302021b95454de600844d021d45 Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 15 Sep 2024 14:39:26 -0400 Subject: [PATCH] Services: modularize msmtp --- flake.lock | 12 ++++++------ hosts/Hevana/default.nix | 20 +++++++++++++++++++- modules/services/msmtp.nix | 31 ++++++++++++++----------------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/flake.lock b/flake.lock index f37c629..b708b0c 100644 --- a/flake.lock +++ b/flake.lock @@ -281,11 +281,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1726062873, - "narHash": "sha256-IiA3jfbR7K/B5+9byVi9BZGWTD4VSbWe8VLpp9B/iYk=", + "lastModified": 1726243404, + "narHash": "sha256-sjiGsMh+1cWXb53Tecsm4skyFNag33GPbVgCdfj3n9I=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "rev": "345c263f2f53a3710abe117f28a5cb86d0ba4059", "type": "github" }, "original": { @@ -297,11 +297,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1726062281, - "narHash": "sha256-PyFVySdGj3enKqm8RQuo4v1KLJLmNLOq2yYOHsI6e2Q=", + "lastModified": 1726320982, + "narHash": "sha256-RuVXUwcYwaUeks6h3OLrEmg14z9aFXdWppTWPMTwdQw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e65aa8301ba4f0ab8cb98f944c14aa9da07394f8", + "rev": "8f7492cce28977fbf8bd12c72af08b1f6c7c3e49", "type": "github" }, "original": { diff --git a/hosts/Hevana/default.nix b/hosts/Hevana/default.nix index b416917..4c176a0 100644 --- a/hosts/Hevana/default.nix +++ b/hosts/Hevana/default.nix @@ -154,7 +154,25 @@ in home = "${services-root}/jellyfin"; url = config.secrets.services.jellyfin.url; }; - msmtp.enable = true; + msmtp = { + enable = true; + accounts.default = { + host = config.secrets.services.msmtp.host; + user = config.secrets.services.msmtp.user; + password = config.secrets.services.msmtp.password; + auth = true; + tls = true; + tls_starttls = true; + port = 587; + from = "${config.networking.hostName}@${config.secrets.networking.domains.primary}"; + }; + aliases = { + text = '' + default: ${config.secrets.users.aires.email} + ''; + mode = "0644"; + }; + }; netdata = { enable = true; type = "parent"; diff --git a/modules/services/msmtp.nix b/modules/services/msmtp.nix index d5b7e30..229d46c 100644 --- a/modules/services/msmtp.nix +++ b/modules/services/msmtp.nix @@ -6,31 +6,28 @@ let in { options = { - aux.system.services.msmtp.enable = lib.mkEnableOption "Enables mail server"; + aux.system.services.msmtp = { + enable = lib.mkEnableOption "Enables mail server"; + accounts = lib.mkOption { + type = lib.types.attrs; + description = "A list of accounts to use for msmtp."; + }; + aliases = lib.mkOption { + default = {}; + type = lib.types.attrs; + description = "Optional email aliases to add."; + }; + }; }; config = lib.mkIf cfg.enable { programs.msmtp = { enable = true; defaults.aliases = "/etc/aliases"; - accounts.default = { - host = config.secrets.services.msmtp.host; - user = config.secrets.services.msmtp.user; - password = config.secrets.services.msmtp.password; - auth = true; - tls = true; - tls_starttls = true; - port = 587; - from = "${config.networking.hostName}@${config.secrets.networking.domains.primary}"; - }; + accounts = cfg.accounts; }; # Send all mail to my email address by default - environment.etc."aliases" = { - text = '' - default: ${config.secrets.users.aires.email} - ''; - mode = "0644"; - }; + environment.etc."aliases" = cfg.aliases; }; }