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