urbit/nix/lib/boot-fake-ship.nix

73 lines
1.6 KiB
Nix
Raw Normal View History

2022-04-04 18:43:12 +03:00
{ lib, stdenvNoCC, curl }:
2023-01-18 22:19:54 +03:00
{ arvo ? null, pill, ship, arguments ? [ "-l" ] }:
let
args = arguments ++ [ "-d" "-F" "${ship}" "-B" "${pill}" ]
++ lib.optionals (arvo != null) [ "-A" "${arvo}" ];
in stdenvNoCC.mkDerivation {
name = "fake-${ship}";
2023-01-18 22:19:54 +03:00
buildInputs = [ curl ];
phases = [ "buildPhase" "installPhase " ];
buildPhase = ''
set -xeuo pipefail
2023-03-15 15:20:09 +03:00
${arvo}/vere.jam ${lib.concatStringsSep " " args} -c ./pier
cleanup () {
if [ -f ./pier/.vere.lock ]; then
kill $(< ./pier/.vere.lock) || true
fi
set +x
}
trap cleanup EXIT
2022-04-04 18:43:12 +03:00
port=$(cat ./pier/.http.ports | grep loopback | tr -s ' ' '\n' | head -n 1)
lensd() {
curl -f -s \
--data "{\"source\":{\"dojo\":\"$1\"},\"sink\":{\"stdout\":null}}" \
"http://localhost:$port" | xargs printf %s | sed 's/\\n/\n/g'
}
lensa() {
curl -f -s \
--data "{\"source\":{\"dojo\":\"$2\"},\"sink\":{\"app\":\"$1\"}}" \
"http://localhost:$port" | xargs printf %s | sed 's/\\n/\n/g'
}
check () {
2022-04-04 18:43:12 +03:00
[ 3 -eq "$(lensd 3)" ]
}
if check && sleep 10 && check; then
header "boot success"
2022-04-04 18:43:12 +03:00
lensa hood '+hood/exit'
while [ -f ./pier/.vere.lock ]; do
echo "waiting for pier to shut down"
sleep 5
done
else
header "boot failure"
kill $(< ./pier/.vere.lock) || true
2022-04-04 18:43:12 +03:00
set +x
exit 1
fi
2022-04-04 18:43:12 +03:00
set +x
'';
installPhase = ''
ls
ls -a ./pier
mv ./pier $out
'';
}