mirror of
https://github.com/nix-community/home-manager
synced 2024-11-05 02:39:45 +01:00
36a53d9f26
This process was automated by [my fork of `nix-doc-munge`]. All conversions were automatically checked to produce the same DocBook result when converted back, modulo minor typographical/formatting differences on the acceptable-to-desirable spectrum. To reproduce this commit, run: $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \ nix shell nixpkgs#coreutils \ -c find . -name '*.nix' \ -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \ {} + $ ./format [my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
133 lines
4.1 KiB
Nix
133 lines
4.1 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.imapnotify;
|
|
|
|
safeName = lib.replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ];
|
|
|
|
configName = account: "imapnotify-${safeName account.name}-config.json";
|
|
|
|
imapnotifyAccounts =
|
|
filter (a: a.imapnotify.enable) (attrValues config.accounts.email.accounts);
|
|
|
|
genAccountUnit = account:
|
|
let name = safeName account.name;
|
|
in {
|
|
name = "imapnotify-${name}";
|
|
value = {
|
|
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}'";
|
|
Restart = "always";
|
|
RestartSec = 30;
|
|
Type = "simple";
|
|
} // optionalAttrs account.notmuch.enable {
|
|
Environment =
|
|
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config";
|
|
};
|
|
|
|
Install = { WantedBy = [ "default.target" ]; };
|
|
};
|
|
};
|
|
|
|
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";
|
|
};
|
|
};
|
|
};
|
|
|
|
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;
|
|
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 {
|
|
meta.maintainers = [ maintainers.nickhu ];
|
|
|
|
options = {
|
|
services.imapnotify = {
|
|
enable = mkEnableOption (lib.mdDoc "imapnotify");
|
|
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.goimapnotify;
|
|
defaultText = literalExpression "pkgs.goimapnotify";
|
|
example = literalExpression "pkgs.imapnotify";
|
|
description = lib.mdDoc "The imapnotify package to use";
|
|
};
|
|
};
|
|
|
|
accounts.email.accounts = mkOption {
|
|
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")
|
|
];
|
|
|
|
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);
|
|
};
|
|
}
|