#!/bin/sh # babashka, which the scripts here are written in. # # A build script wants the things a shell is bad at — reading deps.edn, hashing # a file set, holding a path in a variable without quoting it three times — and # Clojure is already the language this repo is written in. # # This used to be a DotSlash manifest, pinning a release of babashka the way # the native libraries are pinned. It is the flake's now, for the reason the # flake exists: a bb from `nixpkgs` is one this tree already names a version # of, so a checkout needs nix and nothing else. DotSlash still answers for the # desktop libraries — those are jolt-native's releases, which no nixpkgs has — # but nothing has to be installed to reach *them* any more either, because the # script that fetches them starts here. # # Three answers, in order: # # bb on PATH the dev shell puts one there, and so does a machine that # has its own; either is what the caller meant — as long as # it is babashka. `bb` is also what bazel's own launcher # calls itself, and a host with one of those ahead of the # shell's answered every recipe here with "Command # 'scripts/tui.bb' not found. Try 'bb help'", which reads as # a missing script rather than the wrong program # the flake built once and kept alive by the symlink under build/, # which is a gc root as well as a cache # the container nix is not on every host this runs on — see CLAUDE.md — # so a host without one re-enters this script where nix is, # which is where the scripts want to be anyway set -e root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) # Asking it who it is, rather than trusting the name: the version line is the # cheapest question babashka answers and the one nothing else answers the same # way. if command -v bb >/dev/null 2>&1 && bb --version 2>/dev/null | grep -qi '^babashka'; then exec bb "$@" fi link="$root/build/bb" if command -v nix >/dev/null 2>&1; then # --out-link rather than --no-link: the path has to survive a gc, and the # symlink is what roots it. Rebuilt only when it is gone or dangling, so # the usual case is one readlink. [ -x "$link/bin/bb" ] || nix build "$root#bb" --out-link "$link" >&2 exec "$link/bin/bb" "$@" fi if [ -n "$FRQ_BB_REENTERED" ]; then echo "scripts/bb: no bb and no nix, inside the container too." >&2 echo "Install babashka, or put a nix on this machine." >&2 exit 1 fi exec distrobox enter arch -- bash -lc \ "cd $root && FRQ_BB_REENTERED=1 exec scripts/bb \"\$@\"" -- "$@"