services.exim: Fix failing systemd service ExecStartPre script

The previous script ran unprivileged by default (because the default
value of cfg.user was "exim"), and enabling the exim service always
failed. It also would have created the directory with unspecified permissions.

The new mechanism uses coreutil's install tool to create the
directory on systemd service start, with proper ownership and
restrictive permissions.

Fixes NixOS#385522
This commit is contained in:
Michael Franzl
2025-08-28 19:03:32 +02:00
committed by Bjørn Forsman
parent 35ca1b1069
commit 593cac9f89
+1 -8
View File
@@ -123,18 +123,11 @@ in
wantedBy = [ "multi-user.target" ];
restartTriggers = [ config.environment.etc."exim.conf".source ];
serviceConfig = {
ExecStartPre = "+${coreutils}/bin/install --group=${cfg.group} --owner=${cfg.user} --mode=0700 --directory ${cfg.spoolDir}";
ExecStart = "!${cfg.package}/bin/exim -bdf -q${cfg.queueRunnerInterval}";
ExecReload = "!${coreutils}/bin/kill -HUP $MAINPID";
User = cfg.user;
};
preStart = ''
if ! test -d ${cfg.spoolDir}; then
${coreutils}/bin/mkdir -p ${cfg.spoolDir}
${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.spoolDir}
fi
'';
};
};
}