From 85a895d60f7899df72e9000c113b5bf52ef1206f Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 11 Jul 2016 10:37:18 +0200 Subject: [PATCH] offlineimap: add nixos module (#16842) --- nixos/modules/module-list.nix | 1 + .../services/networking/offlineimap.nix | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 nixos/modules/services/networking/offlineimap.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 67178e765c8a..2ed711b79c45 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -368,6 +368,7 @@ ./services/networking/ntopng.nix ./services/networking/ntpd.nix ./services/networking/nylon.nix + ./services/networking/offlineimap.nix ./services/networking/oidentd.nix ./services/networking/openfire.nix ./services/networking/openntpd.nix diff --git a/nixos/modules/services/networking/offlineimap.nix b/nixos/modules/services/networking/offlineimap.nix new file mode 100644 index 000000000000..31ce9280f319 --- /dev/null +++ b/nixos/modules/services/networking/offlineimap.nix @@ -0,0 +1,73 @@ +{ 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)."; + + install = mkOption { + type = types.bool; + default = false; + example = true; + description = '' + Whether to install a user service for Offlineimap. Once + the service is started, emails will be fetched automatically. + + The service must be manually started for each user with + "systemctl --user start offlineimap" or globally through + services.offlineimap.enable. + ''; + }; + + 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."; + }; + + onCalendar = mkOption { + type = types.str; + default = "*:0/3"; # every 3 minutes + description = "How often is offlineimap started. Default is '*:0/3' meaning every 3 minutes. See systemd.time(7) for more information about the format."; + }; + + timeoutStartSec = mkOption { + type = types.str; + default = "120sec"; # Kill if still alive after 2 minutes + 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."; + }; + }; + config = mkIf (cfg.enable || cfg.install) { + systemd.user.services.offlineimap = { + description = "Offlineimap: a software to dispose your mailbox(es) as a local Maildir(s)"; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${cfg.package}/bin/offlineimap -u basic -o -1"; + TimeoutStartSec = cfg.timeoutStartSec; + }; + path = cfg.path; + }; + environment.systemPackages = [ "${cfg.package}" ]; + systemd.user.timers.offlineimap = { + description = "offlineimap timer"; + timerConfig = { + Unit = "offlineimap.service"; + OnCalendar = cfg.onCalendar; + # start immediately after computer is started: + Persistent = "true"; + }; + } // optionalAttrs cfg.enable { wantedBy = [ "default.target" ]; }; + }; +}