···
+
{ config, pkgs, lib, ... }:
+
cfg = config.services.zeyple;
+
ini = pkgs.formats.ini { };
+
gpgHome = pkgs.runCommand "zeyple-gpg-home" { } ''
+
for file in ${lib.concatStringsSep " " cfg.keys}; do
+
${config.programs.gnupg.package}/bin/gpg --homedir="$out" --import "$file"
+
options.services.zeyple = {
+
enable = mkEnableOption (lib.mdDoc "Zeyple, an utility program to automatically encrypt outgoing emails with GPG");
+
description = lib.mdDoc ''
+
If left as the default value this user will automatically be created
+
on system activation, otherwise the sysadmin is responsible for
+
ensuring the user exists.
+
description = lib.mdDoc ''
+
Group to use to run Zeyple.
+
If left as the default value this group will automatically be created
+
on system activation, otherwise the sysadmin is responsible for
+
ensuring the user exists.
+
description = lib.mdDoc ''
+
Zeyple configuration. refer to
+
<https://github.com/infertux/zeyple/blob/master/zeyple/zeyple.conf.example>
+
for details on supported values.
+
type = with types; listOf path;
+
description = lib.mdDoc "List of public key files that will be imported by gpg.";
+
rotateLogs = mkOption {
+
description = lib.mdDoc "Whether to enable rotation of log files.";
+
config = mkIf cfg.enable {
+
users.groups = optionalAttrs (cfg.group == "zeyple") { "${cfg.group}" = { }; };
+
users.users = optionalAttrs (cfg.user == "zeyple") {
+
services.zeyple.settings = {
+
zeyple = mapAttrs (name: mkDefault) {
+
log_file = "/var/log/zeyple/zeyple.log";
+
gpg = mapAttrs (name: mkDefault) { home = "${gpgHome}"; };
+
relay = mapAttrs (name: mkDefault) {
+
environment.etc."zeyple.conf".source = ini.generate "zeyple.conf" cfg.settings;
+
systemd.tmpfiles.rules = [ "f '${cfg.settings.zeyple.log_file}' 0600 ${cfg.user} ${cfg.group} - -" ];
+
services.logrotate = mkIf cfg.rotateLogs {
+
files = cfg.settings.zeyple.log_file;
+
services.postfix.extraMasterConf = ''
+
zeyple unix - n n - - pipe
+
user=${cfg.user} argv=${pkgs.zeyple}/bin/zeyple ''${recipient}
+
localhost:${toString cfg.settings.relay.port} inet n - n - 10 smtpd
+
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks,no_milters
+
-o smtpd_helo_restrictions=
+
-o smtpd_client_restrictions=
+
-o smtpd_sender_restrictions=
+
-o smtpd_recipient_restrictions=permit_mynetworks,reject
+
-o mynetworks=127.0.0.0/8,[::1]/128
+
-o smtpd_authorized_xforward_hosts=127.0.0.0/8,[::1]/128
+
services.postfix.extraConfig = "content_filter = zeyple";