1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#!/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 desktop libraries were 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. Nothing is fetched by digest
# here any more — the libraries a run loads are the flake's too, and the only
# release pins left are the APK's, in nix/android.nix.
#
# 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 \"\$@\"" -- "$@"
|