#!/usr/bin/env bash
set -euxo pipefail

# setup workspace
mkdir /workspace
cd /workspace
git init 
git remote add origin ${NOMAD_META_REPO_URL}
git fetch origin ${NOMAD_META_COMMIT}
git checkout ${NOMAD_META_COMMIT} -b ${NOMAD_META_BRANCH}
if [[ -s /var/run/secrets/albatros/secret.txt ]]; then
  export SECRET_PATH=/var/run/secrets/albatros/secret.txt
fi

# wait for nix daemon during 120 seconds
timeout -s 9 120 bash -c 'until nix store ping; do sleep 2; done'

# launch user's build
./.albatros