From b85d89a1aee4db1417be1b9aaeb19df736a1364e Mon Sep 17 00:00:00 2001 From: Periklis Tsirakidis Date: Mon, 4 Jun 2018 13:04:16 +0200 Subject: [PATCH] Init offlineimap service --- default.nix | 1 + modules/services/mail/offlineimap.nix | 63 +++++++++++++++++++++++++++ release.nix | 1 + tests/services-offlineimap.nix | 43 ++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 modules/services/mail/offlineimap.nix create mode 100644 tests/services-offlineimap.nix diff --git a/default.nix b/default.nix index f8a7f8d..19349f8 100644 --- a/default.nix +++ b/default.nix @@ -50,6 +50,7 @@ let ./modules/services/emacs.nix ./modules/services/khd ./modules/services/kwm + ./modules/services/mail/offlineimap.nix ./modules/services/mopidy.nix ./modules/services/nix-daemon.nix ./modules/services/nix-gc diff --git a/modules/services/mail/offlineimap.nix b/modules/services/mail/offlineimap.nix new file mode 100644 index 0000000..b3cdc2f --- /dev/null +++ b/modules/services/mail/offlineimap.nix @@ -0,0 +1,63 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.offlineimap; +in { + + options.services.offlineimap = { + enable = mkEnableOption "Offlineimap, a software to dispose your mailbox(es) as a local Maildir(s)."; + + package = mkOption { + type = types.package; + default = pkgs.offlineimap; + defaultText = "pkgs.offlineimap"; + description = "Offlineimap derivation to use."; + }; + + path = mkOption { + type = types.listOf types.path; + default = []; + example = literalExample "[ pkgs.pass pkgs.bash pkgs.notmuch ]"; + description = "List of derivations to put in Offlineimap's path."; + }; + + startInterval = mkOption { + type = types.nullOr types.int; + default = null; + example = literalExample "300"; + description = "Optional key to start offlineimap services each N seconds"; + }; + + runQuick = mkOption { + type = types.nullOr types.bool; + default = null; + description = '' + Run only quick synchronizations. + Ignore any flag updates on IMAP servers. If a flag on the remote IMAP changes, and we have the message locally, it will be left untouched in a quick run. + ''; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + description = "Additional text to be appended to offlineimaprc."; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + environment.etc."offlineimaprc".text = cfg.extraConfig; + launchd.user.agents.offlineimap = { + path = [ cfg.package ]; + command = "offlineimap"; + serviceConfig.KeepAlive = false; + serviceConfig.RunAtLoad = true; + serviceConfig.ProgramArguments = [ "-c" "/etc/offlineimaprc" ] ++ optional (cfg.runQuick != null) "-q"; + serviceConfig.StartInterval = cfg.startInterval; + serviceConfig.StandardErrorPath = "/var/log/offlineimap.log"; + serviceConfig.StandardOutPath = "/var/log/offlineimap.log"; + }; + }; +} diff --git a/release.nix b/release.nix index b1d1f47..0e0281b 100644 --- a/release.nix +++ b/release.nix @@ -101,6 +101,7 @@ let tests.services-activate-system = makeTest ./tests/services-activate-system.nix; tests.services-buildkite-agent = makeTest ./tests/services-buildkite-agent.nix; tests.services-ofborg = makeTest ./tests/services-ofborg.nix; + tests.services-offlineimap = makeTest ./tests/services-offlineimap.nix; tests.services-skhd = makeTest ./tests/services-skhd.nix; tests.system-defaults-write = makeTest ./tests/system-defaults-write.nix; tests.system-keyboard-mapping = makeTest ./tests/system-keyboard-mapping.nix; diff --git a/tests/services-offlineimap.nix b/tests/services-offlineimap.nix new file mode 100644 index 0000000..dfbbb57 --- /dev/null +++ b/tests/services-offlineimap.nix @@ -0,0 +1,43 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + offlineimap = pkgs.runCommand "offlineimap-0.0.0" {} "mkdir -p $out"; +in + +{ + services.offlineimap.enable = true; + services.offlineimap.package = offlineimap; + services.offlineimap.runQuick = true; + services.offlineimap.extraConfig = '' + [general] + accounts = test + ui = quiet + + [Account test] + localrepository = testLocal + remoterepository = testRemote + autorefresh = 2 + maxage = 2017-07-01 + + [Repository testLocal] + type = GmailMaildir + + [Repository testRemote] + type = Gmail + ssl = yes + starttls = no + expunge = yes + ''; + + test = '' + echo >&2 "checking offlineimap service in ~/Library/LaunchAgents" + grep "org.nixos.offlineimap" ${config.out}/user/Library/LaunchAgents/org.nixos.offlineimap.plist + grep "exec\ offlineimap" ${config.out}/user/Library/LaunchAgents/org.nixos.offlineimap.plist + grep "\-q" ${config.out}/user/Library/LaunchAgents/org.nixos.offlineimap.plist + + echo >&2 "checking config in /etc/offlineimaprc" + grep "accounts\ \=\ test" ${config.out}/etc/offlineimaprc + ''; +}