1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-05 16:41:04 +01:00
home-manager/modules/programs/getmail.nix
Austin Horstman 0b491b460f
treewide: remove with lib (#6735)
Continuation of `with lib;` cleanup.
2025-03-31 22:32:16 -05:00

65 lines
2.1 KiB
Nix

{ config, lib, pkgs, ... }:
let
accounts = lib.filter (a: a.getmail.enable)
(lib.attrValues config.accounts.email.accounts);
renderAccountConfig = account:
let
inherit (account) getmail imap passwordCommand;
passCmd = lib.concatMapStringsSep ", " (x: "'${x}'") passwordCommand;
renderedMailboxes =
lib.concatMapStrings (x: "'${x}', ") getmail.mailboxes;
retrieverType = if imap.tls.enable then
"SimpleIMAPSSLRetriever"
else
"SimpleIMAPRetriever";
destination = if getmail.destinationCommand != null then {
destinationType = "MDA_external";
destinationPath = getmail.destinationCommand;
} else {
destinationType = "Maildir";
destinationPath = "${account.maildir.absPath}/";
};
renderGetmailBoolean = v: if v then "true" else "false";
in ''
# Generated by Home-Manager.
[retriever]
type = ${retrieverType}
server = ${imap.host}
${lib.optionalString (imap.port != null) "port = ${toString imap.port}"}
username = ${account.userName}
password_command = (${passCmd})
mailboxes = ( ${renderedMailboxes} )
[destination]
type = ${destination.destinationType}
path = ${destination.destinationPath}
[options]
delete = ${renderGetmailBoolean getmail.delete}
read_all = ${renderGetmailBoolean getmail.readAll}
'';
getmailEnabled = lib.length (lib.filter (a: a.getmail.enable) accounts) > 0;
# Watch out! This is used by the getmail.service too!
renderConfigFilepath = a:
".getmail/getmail${if a.primary then "rc" else a.name}";
in {
options = {
accounts.email.accounts = lib.mkOption {
type = with lib.types;
attrsOf (submodule (import ./getmail-accounts.nix));
};
};
config = lib.mkIf getmailEnabled {
assertions = [
(lib.hm.assertions.assertPlatform "programs.getmail" pkgs
lib.platforms.linux)
];
home.file = lib.foldl' (a: b: a // b) { }
(map (a: { "${renderConfigFilepath a}".text = renderAccountConfig a; })
accounts);
};
}