at 16.09-beta 2.5 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.offlineimap; 7in { 8 9 options.services.offlineimap = { 10 enable = mkEnableOption "Offlineimap, a software to dispose your mailbox(es) as a local Maildir(s)."; 11 12 install = mkOption { 13 type = types.bool; 14 default = false; 15 example = true; 16 description = '' 17 Whether to install a user service for Offlineimap. Once 18 the service is started, emails will be fetched automatically. 19 20 The service must be manually started for each user with 21 "systemctl --user start offlineimap" or globally through 22 <varname>services.offlineimap.enable</varname>. 23 ''; 24 }; 25 26 package = mkOption { 27 type = types.package; 28 default = pkgs.offlineimap; 29 defaultText = "pkgs.offlineimap"; 30 description = "Offlineimap derivation to use."; 31 }; 32 33 path = mkOption { 34 type = types.listOf types.path; 35 default = []; 36 example = literalExample "[ pkgs.pass pkgs.bash pkgs.notmuch ]"; 37 description = "List of derivations to put in Offlineimap's path."; 38 }; 39 40 onCalendar = mkOption { 41 type = types.str; 42 default = "*:0/3"; # every 3 minutes 43 description = "How often is offlineimap started. Default is '*:0/3' meaning every 3 minutes. See systemd.time(7) for more information about the format."; 44 }; 45 46 timeoutStartSec = mkOption { 47 type = types.str; 48 default = "120sec"; # Kill if still alive after 2 minutes 49 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."; 50 }; 51 }; 52 config = mkIf (cfg.enable || cfg.install) { 53 systemd.user.services.offlineimap = { 54 description = "Offlineimap: a software to dispose your mailbox(es) as a local Maildir(s)"; 55 serviceConfig = { 56 Type = "oneshot"; 57 ExecStart = "${cfg.package}/bin/offlineimap -u syslog -o -1"; 58 TimeoutStartSec = cfg.timeoutStartSec; 59 }; 60 path = cfg.path; 61 }; 62 environment.systemPackages = [ "${cfg.package}" ]; 63 systemd.user.timers.offlineimap = { 64 description = "offlineimap timer"; 65 timerConfig = { 66 Unit = "offlineimap.service"; 67 OnCalendar = cfg.onCalendar; 68 # start immediately after computer is started: 69 Persistent = "true"; 70 }; 71 } // optionalAttrs cfg.enable { wantedBy = [ "default.target" ]; }; 72 }; 73}