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