1 { config, lib, pkgs, ... }:
3 cfg = config.services.offlineimap;
6 options.services.offlineimap = {
7 enable = lib.mkEnableOption "OfflineIMAP, a software to dispose your mailbox(es) as a local Maildir(s)";
9 install = lib.mkOption {
10 type = lib.types.bool;
13 Whether to install a user service for Offlineimap. Once
14 the service is started, emails will be fetched automatically.
16 The service must be manually started for each user with
17 "systemctl --user start offlineimap" or globally through
18 {var}`services.offlineimap.enable`.
22 package = lib.mkPackageOption pkgs "offlineimap" { };
25 type = lib.types.listOf lib.types.path;
27 example = lib.literalExpression "[ pkgs.pass pkgs.bash pkgs.notmuch ]";
28 description = "List of derivations to put in Offlineimap's path.";
31 onCalendar = lib.mkOption {
33 default = "*:0/3"; # every 3 minutes
34 description = "How often is offlineimap started. Default is '*:0/3' meaning every 3 minutes. See systemd.time(7) for more information about the format.";
37 timeoutStartSec = lib.mkOption {
39 default = "120sec"; # Kill if still alive after 2 minutes
40 description = "How long waiting for offlineimap before killing it. Default is '120sec' meaning every 2 minutes. See systemd.time(7) for more information about the format.";
43 config = lib.mkIf (cfg.enable || cfg.install) {
44 systemd.user.services.offlineimap = {
45 description = "Offlineimap: a software to dispose your mailbox(es) as a local Maildir(s)";
48 ExecStart = "${cfg.package}/bin/offlineimap -u syslog -o -1";
49 TimeoutStartSec = cfg.timeoutStartSec;
53 environment.systemPackages = [ cfg.package ];
54 systemd.user.timers.offlineimap = {
55 description = "offlineimap timer";
57 Unit = "offlineimap.service";
58 OnCalendar = cfg.onCalendar;
59 # start immediately after computer is started:
62 } // lib.optionalAttrs cfg.enable { wantedBy = [ "default.target" ]; };