imapnotify: switch to goimapnotify instead of node-imapnotify (#1675)

I also made some modifications to the systemd service to match the [AUR version](https://aur.archlinux.org/cgit/aur.git/tree/goimapnotify@.service?h=goimapnotify) of `goimapnotify`. In particular, restarting is useful in case a network failure causes `imapnotify` to exit - that shouldn't mean that it stops trying when the network comes back up.
This commit is contained in:
Shane 2020-12-27 15:10:55 +00:00 committed by GitHub
parent cd86c2638b
commit 5263fe4594
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,8 +19,12 @@ let
Unit = { Description = "imapnotify for ${name}"; }; Unit = { Description = "imapnotify for ${name}"; };
Service = { Service = {
ExecStart = ExecStart = "${pkgs.goimapnotify}/bin/goimapnotify -conf ${
"${pkgs.imapnotify}/bin/imapnotify -c ${genAccountConfig account}"; genAccountConfig account
}";
Restart = "always";
RestartSec = 30;
Type = "simple";
} // optionalAttrs account.notmuch.enable { } // optionalAttrs account.notmuch.enable {
Environment = Environment =
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc"; "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc";
@ -31,7 +35,7 @@ let
}; };
genAccountConfig = account: genAccountConfig = account:
pkgs.writeText "imapnotify-${safeName account.name}-config.js" (let pkgs.writeText "imapnotify-${safeName account.name}-config.json" (let
port = if account.imap.port != null then port = if account.imap.port != null then
account.imap.port account.imap.port
else if account.imap.tls.enable then else if account.imap.tls.enable then
@ -40,23 +44,17 @@ let
143; 143;
toJSON = builtins.toJSON; toJSON = builtins.toJSON;
in '' in toJSON {
var child_process = require('child_process'); inherit (account.imap) host;
inherit port;
function getStdout(cmd) { tls = account.imap.tls.enable;
var stdout = child_process.execSync(cmd); username = account.userName;
return stdout.toString().trim(); passwordCmd =
} lib.concatMapStringsSep " " lib.escapeShellArg account.passwordCommand;
onNewMail = account.imapnotify.onNotify;
exports.host = ${toJSON account.imap.host} onNewMailPost = account.imapnotify.onNotifyPost;
exports.port = ${toJSON port}; inherit (account.imapnotify) boxes;
exports.tls = ${toJSON account.imap.tls.enable}; });
exports.username = ${toJSON account.userName};
exports.password = getStdout("${toString account.passwordCommand}");
exports.onNotify = ${toJSON account.imapnotify.onNotify};
exports.onNotifyPost = ${toJSON account.imapnotify.onNotifyPost};
exports.boxes = ${toJSON account.imapnotify.boxes};
'');
in { in {
meta.maintainers = [ maintainers.nickhu ]; meta.maintainers = [ maintainers.nickhu ];