mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-06 00:51:04 +01:00
treewide: reformat nixfmt-rfc-style
Reformat repository using new nixfmt-rfc-style.
This commit is contained in:
parent
5df48c4255
commit
cba2f9ce95
1051 changed files with 37028 additions and 26594 deletions
|
|
@ -1,4 +1,9 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
with lib;
|
||||
|
||||
|
|
@ -10,83 +15,106 @@ let
|
|||
|
||||
configName = account: "imapnotify-${safeName account.name}-config.json";
|
||||
|
||||
imapnotifyAccounts =
|
||||
filter (a: a.imapnotify.enable) (attrValues config.accounts.email.accounts);
|
||||
imapnotifyAccounts = filter (a: a.imapnotify.enable) (attrValues config.accounts.email.accounts);
|
||||
|
||||
genAccountUnit = account:
|
||||
let name = safeName account.name;
|
||||
in {
|
||||
genAccountUnit =
|
||||
account:
|
||||
let
|
||||
name = safeName account.name;
|
||||
in
|
||||
{
|
||||
name = "imapnotify-${name}";
|
||||
value = {
|
||||
Unit = { Description = "imapnotify for ${name}"; };
|
||||
Unit = {
|
||||
Description = "imapnotify for ${name}";
|
||||
};
|
||||
|
||||
Service = {
|
||||
# Use the nix store path for config to ensure service restarts when it changes
|
||||
ExecStart =
|
||||
"${getExe cfg.package} -conf '${genAccountConfig account}'" + " ${
|
||||
lib.optionalString (account.imapnotify.extraArgs != [ ])
|
||||
(toString account.imapnotify.extraArgs)
|
||||
}";
|
||||
"${getExe cfg.package} -conf '${genAccountConfig account}'"
|
||||
+ " ${lib.optionalString (account.imapnotify.extraArgs != [ ]) (
|
||||
toString account.imapnotify.extraArgs
|
||||
)}";
|
||||
Restart = "always";
|
||||
RestartSec = 30;
|
||||
Type = "simple";
|
||||
Environment = [ "PATH=${cfg.path}" ]
|
||||
++ optional account.notmuch.enable
|
||||
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config";
|
||||
Environment =
|
||||
[ "PATH=${cfg.path}" ]
|
||||
++ optional account.notmuch.enable "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config";
|
||||
};
|
||||
|
||||
Install = { WantedBy = [ "default.target" ]; };
|
||||
Install = {
|
||||
WantedBy = [ "default.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
genAccountAgent = account:
|
||||
let name = safeName account.name;
|
||||
in {
|
||||
genAccountAgent =
|
||||
account:
|
||||
let
|
||||
name = safeName account.name;
|
||||
in
|
||||
{
|
||||
name = "imapnotify-${name}";
|
||||
value = {
|
||||
enable = true;
|
||||
config = {
|
||||
# Use the nix store path for config to ensure service restarts when it changes
|
||||
ProgramArguments =
|
||||
[ "${getExe cfg.package}" "-conf" "${genAccountConfig account}" ];
|
||||
KeepAlive = true;
|
||||
ThrottleInterval = 30;
|
||||
ExitTimeOut = 0;
|
||||
ProcessType = "Background";
|
||||
RunAtLoad = true;
|
||||
} // optionalAttrs account.notmuch.enable {
|
||||
EnvironmentVariables.NOTMUCH_CONFIG =
|
||||
"${config.xdg.configHome}/notmuch/default/config";
|
||||
};
|
||||
config =
|
||||
{
|
||||
# Use the nix store path for config to ensure service restarts when it changes
|
||||
ProgramArguments = [
|
||||
"${getExe cfg.package}"
|
||||
"-conf"
|
||||
"${genAccountConfig account}"
|
||||
];
|
||||
KeepAlive = true;
|
||||
ThrottleInterval = 30;
|
||||
ExitTimeOut = 0;
|
||||
ProcessType = "Background";
|
||||
RunAtLoad = true;
|
||||
}
|
||||
// optionalAttrs account.notmuch.enable {
|
||||
EnvironmentVariables.NOTMUCH_CONFIG = "${config.xdg.configHome}/notmuch/default/config";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
genAccountConfig = account:
|
||||
pkgs.writeText (configName account) (let
|
||||
port = if account.imap.port != null then
|
||||
account.imap.port
|
||||
else if account.imap.tls.enable then
|
||||
993
|
||||
else
|
||||
143;
|
||||
genAccountConfig =
|
||||
account:
|
||||
pkgs.writeText (configName account) (
|
||||
let
|
||||
port =
|
||||
if account.imap.port != null then
|
||||
account.imap.port
|
||||
else if account.imap.tls.enable then
|
||||
993
|
||||
else
|
||||
143;
|
||||
|
||||
toJSON = builtins.toJSON;
|
||||
in toJSON ({
|
||||
inherit (account.imap) host;
|
||||
inherit port;
|
||||
tls = account.imap.tls.enable;
|
||||
tlsOptions.starttls = account.imap.tls.useStartTls;
|
||||
username = account.userName;
|
||||
passwordCmd =
|
||||
lib.concatMapStringsSep " " lib.escapeShellArg account.passwordCommand;
|
||||
inherit (account.imapnotify) boxes;
|
||||
} // optionalAttrs (account.imapnotify.onNotify != "") {
|
||||
onNewMail = account.imapnotify.onNotify;
|
||||
} // optionalAttrs (account.imapnotify.onNotifyPost != "") {
|
||||
onNewMailPost = account.imapnotify.onNotifyPost;
|
||||
} // account.imapnotify.extraConfig));
|
||||
toJSON = builtins.toJSON;
|
||||
in
|
||||
toJSON (
|
||||
{
|
||||
inherit (account.imap) host;
|
||||
inherit port;
|
||||
tls = account.imap.tls.enable;
|
||||
tlsOptions.starttls = account.imap.tls.useStartTls;
|
||||
username = account.userName;
|
||||
passwordCmd = lib.concatMapStringsSep " " lib.escapeShellArg account.passwordCommand;
|
||||
inherit (account.imapnotify) boxes;
|
||||
}
|
||||
// optionalAttrs (account.imapnotify.onNotify != "") {
|
||||
onNewMail = account.imapnotify.onNotify;
|
||||
}
|
||||
// optionalAttrs (account.imapnotify.onNotifyPost != "") {
|
||||
onNewMailPost = account.imapnotify.onNotifyPost;
|
||||
}
|
||||
// account.imapnotify.extraConfig
|
||||
)
|
||||
);
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
meta.maintainers = [ maintainers.nickhu ];
|
||||
|
||||
options = {
|
||||
|
|
@ -114,41 +142,45 @@ in {
|
|||
};
|
||||
|
||||
accounts.email.accounts = mkOption {
|
||||
type = with types;
|
||||
attrsOf
|
||||
(submodule (import ./imapnotify-accounts.nix { inherit pkgs lib; }));
|
||||
type = with types; attrsOf (submodule (import ./imapnotify-accounts.nix { inherit pkgs lib; }));
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = let
|
||||
checkAccounts = pred: msg:
|
||||
let badAccounts = filter pred imapnotifyAccounts;
|
||||
in {
|
||||
assertion = badAccounts == [ ];
|
||||
message = "imapnotify: Missing ${msg} for accounts: "
|
||||
+ concatMapStringsSep ", " (a: a.name) badAccounts;
|
||||
};
|
||||
in [
|
||||
(checkAccounts (a: a.maildir == null) "maildir configuration")
|
||||
(checkAccounts (a: a.imap == null) "IMAP configuration")
|
||||
(checkAccounts (a: a.passwordCommand == null) "password command")
|
||||
(checkAccounts (a: a.userName == null) "username")
|
||||
];
|
||||
assertions =
|
||||
let
|
||||
checkAccounts =
|
||||
pred: msg:
|
||||
let
|
||||
badAccounts = filter pred imapnotifyAccounts;
|
||||
in
|
||||
{
|
||||
assertion = badAccounts == [ ];
|
||||
message =
|
||||
"imapnotify: Missing ${msg} for accounts: " + concatMapStringsSep ", " (a: a.name) badAccounts;
|
||||
};
|
||||
in
|
||||
[
|
||||
(checkAccounts (a: a.maildir == null) "maildir configuration")
|
||||
(checkAccounts (a: a.imap == null) "IMAP configuration")
|
||||
(checkAccounts (a: a.passwordCommand == null) "password command")
|
||||
(checkAccounts (a: a.userName == null) "username")
|
||||
];
|
||||
|
||||
services.imapnotify.path = lib.mkMerge [
|
||||
(lib.mkIf config.programs.notmuch.enable [ pkgs.notmuch ])
|
||||
(lib.mkIf config.programs.mbsync.enable
|
||||
[ config.programs.mbsync.package ])
|
||||
(lib.mkIf config.programs.mbsync.enable [ config.programs.mbsync.package ])
|
||||
];
|
||||
|
||||
systemd.user.services = listToAttrs (map genAccountUnit imapnotifyAccounts);
|
||||
|
||||
launchd.agents = listToAttrs (map genAccountAgent imapnotifyAccounts);
|
||||
|
||||
xdg.configFile = listToAttrs (map (account: {
|
||||
name = "imapnotify/${configName account}";
|
||||
value.source = genAccountConfig account;
|
||||
}) imapnotifyAccounts);
|
||||
xdg.configFile = listToAttrs (
|
||||
map (account: {
|
||||
name = "imapnotify/${configName account}";
|
||||
value.source = genAccountConfig account;
|
||||
}) imapnotifyAccounts
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue