1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-01 00:39:45 +01:00
home-manager/modules/programs/getmail.nix
Robert Helgesson 5f433eb164
Move platform check into modules
Before, loading a module would be guarded by an optional platform
condition. This made it possible to avoid loading and evaluating a
module if it did not support the host platform.

Unfortunately, this made it impossible to share a single configuration
between GNU/Linux and Darwin hosts, which some wish to do.

This removes the conditional load and instead inserts host platform
assertions in the modules that are platform specific.

Fixes #1906
2021-07-18 20:43:22 +02:00

66 lines
2 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
accounts =
filter (a: a.getmail.enable) (attrValues config.accounts.email.accounts);
renderAccountConfig = account:
with account;
let
passCmd = concatMapStringsSep ", " (x: "'${x}'") passwordCommand;
renderedMailboxes = 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 = "${maildir.absPath}/";
};
renderGetmailBoolean = v: if v then "true" else "false";
in ''
# Generated by Home-Manager.
[retriever]
type = ${retrieverType}
server = ${imap.host}
${optionalString (imap.port != null) "port = ${toString imap.port}"}
username = ${userName}
password_command = (${passCmd})
mailboxes = ( ${renderedMailboxes} )
[destination]
type = ${destination.destinationType}
path = ${destination.destinationPath}
[options]
delete = ${renderGetmailBoolean getmail.delete}
read_all = ${renderGetmailBoolean getmail.readAll}
'';
getmailEnabled = length (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 = mkOption {
type = with types; attrsOf (submodule (import ./getmail-accounts.nix));
};
};
config = mkIf getmailEnabled {
assertions = [
(hm.assertions.assertPlatform "programs.getmail" pkgs platforms.linux)
];
home.file = foldl' (a: b: a // b) { }
(map (a: { "${renderConfigFilepath a}".text = renderAccountConfig a; })
accounts);
};
}