bscpkgs/garlic/garlicd/garlicd

73 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -e
msg() {
>&2 echo "garlicd: $@"
}
if [ -z "$1" ]; then
>&2 echo "usage: garlicd <bscpkgs directory>"
exit 1
fi
export PATH="@extraPath@:$PATH"
bscpkgsdir=$(readlink -f "$1")
garlic_sandbox=$(nix show-config |\
grep extra-sandbox-paths |\
grep -o '/garlic=[^ ]*' || true)
if [ -z "$garlic_sandbox" ]; then
msg "Missing extra-sandbox-paths /garlic mountpoint"
msg "Check the ~/.config/nix/nix.conf file"
exit 1
fi
mountdir_rel=$(echo "$garlic_sandbox" | sed 's@^/garlic=@@g')
mountdir=$(readlink -f "$mountdir_rel")
run="$mountdir/run"
completed="$mountdir/completed"
for fifo in "$run" "$completed"; do
if [ ! -e "$fifo" ]; then
mkfifo "$fifo"
# FIXME: Use more resctrictive permissions
chmod 666 "$fifo"
fi
done
cd "$bscpkgsdir"
while true; do
msg "Waiting for experiments ..."
read -r tre < "$run"
msg "Attempting to run: $tre"
msg "Copying files to MN4..."
# It fails if the user doesn't have nix-store, but is already copied
# with the post build hook
nix copy --to ssh://mn1 $tre || true
msg "Launching the experiment..."
garlic -R "$tre"
msg "Fetching results..."
results=$(garlic -Fv "$tre")
msg "results=\"$results\""
msg "Searching drv..."
drv=$(nix-store -q --deriver $results)
msg "drv = \"$drv\""
if [ -z "$drv" ]; then
msg "Something failed, drv is empty. Check the logs."
exit 1
fi
echo -n "$drv" >> "$completed"
msg "execution completed :-)"
done