1 { config, lib, pkgs, ... }:
4 cfg = config.services.postsrsd;
14 enable = lib.mkOption {
15 type = lib.types.bool;
17 description = "Whether to enable the postsrsd SRS server for Postfix.";
20 secretsFile = lib.mkOption {
21 type = lib.types.path;
22 default = "/var/lib/postsrsd/postsrsd.secret";
23 description = "Secret keys used for signing and verification";
26 domain = lib.mkOption {
28 description = "Domain name for rewrite";
31 separator = lib.mkOption {
32 type = lib.types.enum ["-" "=" "+"];
34 description = "First separator character in generated addresses";
37 # bindAddress = lib.mkOption { # uncomment once 1.5 is released
38 # type = lib.types.str;
39 # default = "127.0.0.1";
40 # description = "Socket listen address";
43 forwardPort = lib.mkOption {
46 description = "Port for the forward SRS lookup";
49 reversePort = lib.mkOption {
52 description = "Port for the reverse SRS lookup";
55 timeout = lib.mkOption {
58 description = "Timeout for idle client connections in seconds";
61 excludeDomains = lib.mkOption {
62 type = lib.types.listOf lib.types.str;
64 description = "Origin domains to exclude from rewriting in addition to primary domain";
70 description = "User for the daemon";
73 group = lib.mkOption {
76 description = "Group for the daemon";
86 config = lib.mkIf cfg.enable {
88 services.postsrsd.domain = lib.mkDefault config.networking.hostName;
90 users.users = lib.optionalAttrs (cfg.user == "postsrsd") {
93 uid = config.ids.uids.postsrsd;
97 users.groups = lib.optionalAttrs (cfg.group == "postsrsd") {
98 postsrsd.gid = config.ids.gids.postsrsd;
101 systemd.services.postsrsd = {
102 description = "PostSRSd SRS rewriting server";
103 after = [ "network.target" ];
104 before = [ "postfix.service" ];
105 wantedBy = [ "multi-user.target" ];
107 path = [ pkgs.coreutils ];
110 ExecStart = ''${pkgs.postsrsd}/sbin/postsrsd "-s${cfg.secretsFile}" "-d${cfg.domain}" -a${cfg.separator} -f${toString cfg.forwardPort} -r${toString cfg.reversePort} -t${toString cfg.timeout} "-X${lib.concatStringsSep "," cfg.excludeDomains}"'';
113 PermissionsStartOnly = true;
117 if [ ! -e "${cfg.secretsFile}" ]; then
118 echo "WARNING: secrets file not found, autogenerating!"
119 DIR="$(dirname "${cfg.secretsFile}")"
120 install -m 750 -o ${cfg.user} -g ${cfg.group} -d "$DIR"
121 install -m 600 -o ${cfg.user} -g ${cfg.group} <(dd if=/dev/random bs=18 count=1 | base64) "${cfg.secretsFile}"