treewide: implement auto importing for modules
Reduce maintenance burden and increase efficiency by automatically importing modules following a specific convention. Co-authored-by: awwpotato <awwpotato@voidq.com> Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
fefeb0e928
commit
4fca600cb1
461 changed files with 72 additions and 474 deletions
52
modules/programs/getmail/accounts.nix
Normal file
52
modules/programs/getmail/accounts.nix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.getmail = {
|
||||
enable = lib.mkEnableOption "the getmail mail retriever for this account";
|
||||
|
||||
destinationCommand = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "\${pkgs.maildrop}/bin/maildrop";
|
||||
description = ''
|
||||
Specify a command delivering the incoming mail to your maildir.
|
||||
'';
|
||||
};
|
||||
|
||||
mailboxes = mkOption {
|
||||
type = types.nonEmptyListOf types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"INBOX"
|
||||
"INBOX.spam"
|
||||
];
|
||||
description = ''
|
||||
A non-empty list of mailboxes. To download all mail you can
|
||||
use the `ALL` mailbox.
|
||||
'';
|
||||
};
|
||||
|
||||
delete = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable if you want to delete read messages from the server. Most
|
||||
users should either enable `delete` or disable
|
||||
`readAll`.
|
||||
'';
|
||||
};
|
||||
|
||||
readAll = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Enable if you want to fetch all, even the read messages from the
|
||||
server. Most users should either enable `delete` or
|
||||
disable `readAll`.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
69
modules/programs/getmail/default.nix
Normal file
69
modules/programs/getmail/default.nix
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
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 ./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
|
||||
);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue