From 5263fe459413a411e51355bfae5b5673b481dbe3 Mon Sep 17 00:00:00 2001 From: Shane Date: Sun, 27 Dec 2020 15:10:55 +0000 Subject: [PATCH] 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. --- modules/services/imapnotify.nix | 38 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/modules/services/imapnotify.nix b/modules/services/imapnotify.nix index b59b006e..4b3ebda7 100644 --- a/modules/services/imapnotify.nix +++ b/modules/services/imapnotify.nix @@ -19,8 +19,12 @@ let Unit = { Description = "imapnotify for ${name}"; }; Service = { - ExecStart = - "${pkgs.imapnotify}/bin/imapnotify -c ${genAccountConfig account}"; + ExecStart = "${pkgs.goimapnotify}/bin/goimapnotify -conf ${ + genAccountConfig account + }"; + Restart = "always"; + RestartSec = 30; + Type = "simple"; } // optionalAttrs account.notmuch.enable { Environment = "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc"; @@ -31,7 +35,7 @@ let }; 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 account.imap.port else if account.imap.tls.enable then @@ -40,23 +44,17 @@ let 143; toJSON = builtins.toJSON; - in '' - var child_process = require('child_process'); - - function getStdout(cmd) { - var stdout = child_process.execSync(cmd); - return stdout.toString().trim(); - } - - exports.host = ${toJSON account.imap.host} - exports.port = ${toJSON port}; - 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 toJSON { + inherit (account.imap) host; + inherit port; + tls = account.imap.tls.enable; + username = account.userName; + passwordCmd = + lib.concatMapStringsSep " " lib.escapeShellArg account.passwordCommand; + onNewMail = account.imapnotify.onNotify; + onNewMailPost = account.imapnotify.onNotifyPost; + inherit (account.imapnotify) boxes; + }); in { meta.maintainers = [ maintainers.nickhu ];