From 453c4a6002e51265f5bcaef3bf53a1362f4c7b6a Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Fri, 18 Sep 2026 05:56:06 +0530 Subject: chore(communication/neomutt): some minor refactoring --- .../communication/neomutt/account/assertions.nix | 30 ++++ modules/communication/neomutt/account/default.nix | 173 +++++++++------------ 2 files changed, 107 insertions(+), 96 deletions(-) create mode 100644 modules/communication/neomutt/account/assertions.nix (limited to 'modules/communication/neomutt') diff --git a/modules/communication/neomutt/account/assertions.nix b/modules/communication/neomutt/account/assertions.nix new file mode 100644 index 0000000..c19ab72 --- /dev/null +++ b/modules/communication/neomutt/account/assertions.nix @@ -0,0 +1,30 @@ +# Validates the neomutt account configurations +{ config, lib, ... }: +{ + config.assertions = [ + { + assertion = + !config.communication.neomutt.enable + || !lib.any (account: account.enable && account.passwordGopassSecret != null) ( + lib.attrValues config.communication.neomutt.accounts + ) + || config.security.gopass.enable; + message = '' + An enabled communication.neomutt account uses passwordGopassSecret but security.gopass.enable is not set. + Enable security.gopass to provide the account password command. + ''; + } + { + assertion = + !config.communication.neomutt.enable + || !lib.any (account: account.enable && account.gpg.key != null) ( + lib.attrValues config.communication.neomutt.accounts + ) + || config.security.gpg.enable; + message = '' + An enabled communication.neomutt account specifies a GPG key but security.gpg.enable is not set. + Enable security.gpg to provide mail signing and encryption support. + ''; + } + ]; +} diff --git a/modules/communication/neomutt/account/default.nix b/modules/communication/neomutt/account/default.nix index 6eec24e..5c0f8bf 100644 --- a/modules/communication/neomutt/account/default.nix +++ b/modules/communication/neomutt/account/default.nix @@ -1,6 +1,10 @@ # Converts neomutt account options into home-manager email config { config, lib, ... }: { + imports = [ + ./assertions.nix + ]; + options.communication.neomutt.accounts = lib.mkOption { type = lib.types.attrsOf ( lib.types.submodule { @@ -15,117 +19,94 @@ description = "Specification of email accounts."; }; - config = { - assertions = [ - { - assertion = - !config.communication.neomutt.enable - || !lib.any (account: account.enable && account.passwordGopassSecret != null) ( - lib.attrValues config.communication.neomutt.accounts - ) - || config.security.gopass.enable; - message = '' - An enabled communication.neomutt account uses passwordGopassSecret but security.gopass.enable is not set. - Enable security.gopass to provide the account password command. - ''; - } - { - assertion = - !config.communication.neomutt.enable - || !lib.any (account: account.enable && account.gpg.key != null) ( - lib.attrValues config.communication.neomutt.accounts - ) - || config.security.gpg.enable; - message = '' - An enabled communication.neomutt account specifies a GPG key but security.gpg.enable is not set. - Enable security.gpg to provide mail signing and encryption support. - ''; - } - ]; + config = lib.mkIf config.communication.neomutt.enable { + accounts.email.accounts = lib.mapAttrs (accountName: accountInformation: { + inherit (accountInformation) realName address primary; - } - // lib.mkIf config.communication.neomutt.enable { - accounts.email.accounts = lib.mapAttrs ( - name: account: - let - a = account; - in - { - inherit (a) realName address primary; - userName = if a.userName != null then a.userName else a.address; + userName = + if accountInformation.userName != null then + accountInformation.userName + else + accountInformation.address; - passwordCommand = - if a.passwordGopassSecret != null then - "${lib.getExe config.security.gopass.package} -o ${a.passwordGopassSecret}" - else - null; + passwordCommand = + if accountInformation.passwordGopassSecret != null then + "${lib.getExe config.security.gopass.package} -o ${accountInformation.passwordGopassSecret}" + else + null; - flavor = a.flavor; - inherit (a) aliases; + flavor = accountInformation.flavor; + inherit (accountInformation) aliases; - folders = { - inherit (a.folders) inbox trash; - } - // lib.optionalAttrs (a.folders.drafts != null) { drafts = a.folders.drafts; } - // lib.optionalAttrs (a.folders.sent != null) { sent = a.folders.sent; }; + folders = { + inherit (accountInformation.folders) inbox trash; + } + // lib.optionalAttrs (accountInformation.folders.drafts != null) { + drafts = accountInformation.folders.drafts; + } + // lib.optionalAttrs (accountInformation.folders.sent != null) { + sent = accountInformation.folders.sent; + }; - neomutt = { - enable = true; - mailboxType = a.neomutt.mailboxType; - extraConfig = a.neomutt.extraConfig; - }; + neomutt = { + enable = true; + mailboxType = accountInformation.neomutt.mailboxType; + extraConfig = accountInformation.neomutt.extraConfig; + }; - mbsync = { - enable = true; - create = a.mbsync.create; - patterns = a.mbsync.patterns; - flatten = a.mbsync.flatten; - extraConfig = { - account = a.mbsync.extraConfig.account; - channel = a.mbsync.extraConfig.channel; - local = a.mbsync.extraConfig.local; - remote = a.mbsync.extraConfig.remote; - }; + mbsync = { + enable = true; + create = accountInformation.mbsync.create; + patterns = accountInformation.mbsync.patterns; + flatten = accountInformation.mbsync.flatten; + extraConfig = { + account = accountInformation.mbsync.extraConfig.account; + channel = accountInformation.mbsync.extraConfig.channel; + local = accountInformation.mbsync.extraConfig.local; + remote = accountInformation.mbsync.extraConfig.remote; }; + }; - notmuch = { + notmuch = { + enable = true; + neomutt = { enable = true; - neomutt = { - enable = true; - virtualMailboxes = a.notmuch.neomutt.virtualMailboxes; - }; + virtualMailboxes = accountInformation.notmuch.neomutt.virtualMailboxes; }; + }; - imap = lib.optionalAttrs (a.imap.host != null) { - host = a.imap.host; - port = a.imap.port; - tls = { - enable = a.imap.tls.enable; - useStartTls = a.imap.tls.useStartTls; - }; + imap = lib.optionalAttrs (accountInformation.imap.host != null) { + host = accountInformation.imap.host; + port = accountInformation.imap.port; + tls = { + enable = accountInformation.imap.tls.enable; + useStartTls = accountInformation.imap.tls.useStartTls; }; + }; - smtp = lib.optionalAttrs (a.smtp.host != null) { - host = a.smtp.host; - port = a.smtp.port; - tls = { - enable = a.smtp.tls.enable; - useStartTls = a.smtp.tls.useStartTls; - }; + smtp = lib.optionalAttrs (accountInformation.smtp.host != null) { + host = accountInformation.smtp.host; + port = accountInformation.smtp.port; + tls = { + enable = accountInformation.smtp.tls.enable; + useStartTls = accountInformation.smtp.tls.useStartTls; }; + }; - gpg = lib.optionalAttrs (a.gpg.key != null) { - key = a.gpg.key; - signByDefault = a.gpg.signByDefault; - encryptByDefault = a.gpg.encryptByDefault; - }; + gpg = lib.optionalAttrs (accountInformation.gpg.key != null) { + key = accountInformation.gpg.key; + signByDefault = accountInformation.gpg.signByDefault; + encryptByDefault = accountInformation.gpg.encryptByDefault; + }; - signature = lib.optionalAttrs (a.signature.text != null || a.signature.command != null) { - text = a.signature.text; - command = a.signature.command; - showSignature = a.signature.showSignature; - }; - } - ) (lib.filterAttrs (n: a: a.enable) config.communication.neomutt.accounts); + signature = + lib.optionalAttrs + (accountInformation.signature.text != null || accountInformation.signature.command != null) + { + text = accountInformation.signature.text; + command = accountInformation.signature.command; + showSignature = accountInformation.signature.showSignature; + }; + }) (lib.filterAttrs (n: a: a.enable) config.communication.neomutt.accounts); }; } -- cgit v1.2.3