aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/imapnotify.nix
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2020-02-03 10:05:30 +0100
committerKatharina Fey <kookie@spacekookie.de>2020-02-03 10:05:30 +0100
commitc488527c95c874d3b8743c915173ad7bfb05d5af (patch)
tree2b874dc5606a9dff44096a5e8557f00dc52ac2b6 /home-manager/modules/services/imapnotify.nix
parent899a451e08f7d6d2c8214d119c2a0316849a0ed4 (diff)
parent6cc4fd6ede4909226cb81d3475834251ed1b7210 (diff)
Merge commit '6cc4fd6ede4909226cb81d3475834251ed1b7210'
Diffstat (limited to 'home-manager/modules/services/imapnotify.nix')
-rw-r--r--home-manager/modules/services/imapnotify.nix143
1 files changed, 63 insertions, 80 deletions
diff --git a/home-manager/modules/services/imapnotify.nix b/home-manager/modules/services/imapnotify.nix
index fbb0713e978..b59b006e335 100644
--- a/home-manager/modules/services/imapnotify.nix
+++ b/home-manager/modules/services/imapnotify.nix
@@ -6,102 +6,85 @@ let
cfg = config.services.imapnotify;
- safeName = lib.replaceChars ["@" ":" "\\" "[" "]"] ["-" "-" "-" "" ""];
+ safeName = lib.replaceChars [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ];
imapnotifyAccounts =
- filter (a: a.imapnotify.enable)
- (attrValues config.accounts.email.accounts);
+ 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 = {
- ExecStart = "${pkgs.imapnotify}/bin/imapnotify -c ${genAccountConfig account}";
- } // optionalAttrs account.notmuch.enable {
- Environment = "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc";
- };
-
- Install = {
- WantedBy = [ "default.target" ];
- };
+ let name = safeName account.name;
+ in {
+ name = "imapnotify-${name}";
+ value = {
+ Unit = { Description = "imapnotify for ${name}"; };
+
+ Service = {
+ ExecStart =
+ "${pkgs.imapnotify}/bin/imapnotify -c ${genAccountConfig account}";
+ } // optionalAttrs account.notmuch.enable {
+ Environment =
+ "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc";
};
+
+ Install = { WantedBy = [ "default.target" ]; };
};
+ };
genAccountConfig = account:
- pkgs.writeText "imapnotify-${safeName account.name}-config.js" (
- 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
- ''
- 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
-
-{
+ pkgs.writeText "imapnotify-${safeName account.name}-config.js" (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 ''
+ 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 {
meta.maintainers = [ maintainers.nickhu ];
options = {
- services.imapnotify = {
- enable = mkEnableOption "imapnotify";
- };
+ services.imapnotify = { enable = mkEnableOption "imapnotify"; };
accounts.email.accounts = mkOption {
- type = with types; attrsOf (submodule (
- import ./imapnotify-accounts.nix
- ));
+ type = with types; attrsOf (submodule (import ./imapnotify-accounts.nix));
};
};
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);
+ 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);
};
}