Add a script for stalwart to wait pocketid to start so OIDC doesnt fail

This commit is contained in:
aloslider committed 2026-10-31 20:00:39 +03:00
1 parent c92b90e406
commit 32c756fde5
1 file changed
+16
@@ -8,6 +8,18 @@ let
planPath = config.sops.templates."stalwart-oidc-plan.json".path; planPath = config.sops.templates."stalwart-oidc-plan.json".path;
cliEnvPath = config.sops.templates."stalwart-cli.env".path; cliEnvPath = config.sops.templates."stalwart-cli.env".path;
hostDataPath = "${common.dataDir}/stalwart"; hostDataPath = "${common.dataDir}/stalwart";
pocketIdReady = pkgs.writeShellScript "stalwart-wait-pocket-id" ''
set -euo pipefail
url="${"http://127.0.0.1:${toString rootCfg.pocket-id.server.hostHttpPort}/.well-known/openid-configuration"}"
for i in $(seq 1 90); do
if ${lib.getExe pkgs.curl} -fsS -o /dev/null --max-time 2 "$url"; then
exit 0
fi
sleep 1
done
echo "Pocket ID did not serve $url" >&2
exit 1
'';
in in
{ {
imports = [ ./config.nix ]; imports = [ ./config.nix ];
@@ -77,6 +89,8 @@ in
wantedBy = [ "${common.backend}-${moduleCfg.targetName}.target" ]; wantedBy = [ "${common.backend}-${moduleCfg.targetName}.target" ];
partOf = [ "${common.backend}-${moduleCfg.targetName}.target" ]; partOf = [ "${common.backend}-${moduleCfg.targetName}.target" ];
preStart = '' preStart = ''
${pocketIdReady}
mkdir -p ${hostDataPath}/{config,data} mkdir -p ${hostDataPath}/{config,data}
chown -R 2000:2000 ${hostDataPath} 2>/dev/null || chmod 775 ${hostDataPath} chown -R 2000:2000 ${hostDataPath} 2>/dev/null || chmod 775 ${hostDataPath}
chmod 775 ${hostDataPath}/{config,data} chmod 775 ${hostDataPath}/{config,data}
@@ -139,6 +153,8 @@ in
"$cli_image" \ "$cli_image" \
apply --stdin apply --stdin
${pocketIdReady}
${common.backend} restart ${cfg.name} ${common.backend} restart ${cfg.name}
ok=0 ok=0