summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeriklis Tsirakidis <periklis.tsirakidis@holidaycheck.com>2018-06-04 13:04:16 +0200
committerPeriklis Tsirakidis <periklis.tsirakidis@holidaycheck.com>2018-06-04 16:25:07 +0200
commitb85d89a1aee4db1417be1b9aaeb19df736a1364e (patch)
tree71fa654a712eee3a1790589283418da209241b78
parent07175b169bf4cab57bb8edffd3df96537dffeb57 (diff)
Init offlineimap service
-rw-r--r--default.nix1
-rw-r--r--modules/services/mail/offlineimap.nix63
-rw-r--r--release.nix1
-rw-r--r--tests/services-offlineimap.nix43
4 files changed, 108 insertions, 0 deletions
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 <filename>offlineimaprc</filename>.";
+ };
+ };
+
+ 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
+ '';
+}