From c51d08cf271af95c62f40be9a281751669be55aa Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Wed, 6 Jan 2016 06:04:50 +0300 Subject: nixos/postsrsd: add module --- nixos/modules/misc/ids.nix | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/mail/postsrsd.nix | 107 +++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 nixos/modules/services/mail/postsrsd.nix diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index c9247815a35c..bcd1067b39c3 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -241,6 +241,7 @@ nm-openvpn = 217; mathics = 218; ejabberd = 219; + postsrsd = 220; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -459,6 +460,7 @@ nm-openvpn = 217; mathics = 218; ejabberd = 219; + postsrsd = 220; # When adding a gid, make sure it doesn't match an existing # uid. Users and groups with the same name should have equal diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 33a45f2240cc..dc7bd86b40f8 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -189,6 +189,7 @@ ./services/mail/mlmmj.nix ./services/mail/opensmtpd.nix ./services/mail/postfix.nix + ./services/mail/postsrsd.nix ./services/mail/spamassassin.nix ./services/misc/apache-kafka.nix ./services/misc/autofs.nix diff --git a/nixos/modules/services/mail/postsrsd.nix b/nixos/modules/services/mail/postsrsd.nix new file mode 100644 index 000000000000..36a0f8218d88 --- /dev/null +++ b/nixos/modules/services/mail/postsrsd.nix @@ -0,0 +1,107 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.postsrsd; + +in { + + ###### interface + + options = { + + services.postsrsd = { + + enable = mkOption { + type = types.bool; + default = false; + description = "Whether to enable the postsrsd SRS server for Postfix."; + }; + + domain = mkOption { + type = types.str; + description = "Domain name for rewrite"; + }; + + secretsFile = mkOption { + type = types.path; + default = "/var/lib/postsrsd/postsrsd.secret"; + description = "Secret keys used for signing and verification"; + }; + + forwardPort = mkOption { + type = types.int; + default = 10001; + description = "Port for the forward SRS lookup"; + }; + + reversePort = mkOption { + type = types.int; + default = 10002; + description = "Port for the reverse SRS lookup"; + }; + + user = mkOption { + type = types.str; + default = "postsrsd"; + description = "User for the daemon"; + }; + + group = mkOption { + type = types.str; + default = "postsrsd"; + description = "Group for the daemon"; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.enable { + + services.postsrsd.domain = mkDefault config.networking.hostName; + + users.extraUsers = optionalAttrs (cfg.user == "postsrsd") (singleton + { name = "postsrsd"; + group = cfg.group; + uid = config.ids.uids.postsrsd; + }); + + users.extraGroups = optionalAttrs (cfg.group == "postsrsd") (singleton + { name = "postsrsd"; + gid = config.ids.gids.postsrsd; + }); + + systemd.services.postsrsd = { + description = "PostSRSd SRS rewriting server"; + after = [ "network.target" ]; + before = [ "postfix.service" ]; + wantedBy = [ "multi-user.target" ]; + + path = [ pkgs.coreutils ]; + + serviceConfig = { + ExecStart = ''${pkgs.postsrsd}/sbin/postsrsd "-s${cfg.secretsFile}" "-d${cfg.domain}" -f${toString cfg.forwardPort} -r${toString cfg.reversePort}''; + User = cfg.user; + Group = cfg.group; + PermissionsStartOnly = true; + }; + + preStart = '' + if [ ! -e "${cfg.secretsFile}" ]; then + echo "WARNING: secrets file not found, autogenerating!" + mkdir -p -m750 "$(dirname "${cfg.secretsFile}")" + dd if=/dev/random bs=18 count=1 | base64 > "${cfg.secretsFile}" + chmod 600 "${cfg.secretsFile}" + fi + chown "${cfg.user}:${cfg.group}" "${cfg.secretsFile}" + ''; + }; + + }; +} -- cgit 1.4.1