| Take bb from the flake, so a checkout needs nix and nothing else 270bee0 nandi 16d ago | 1 | #!/bin/sh |
| 2 | # babashka, which the scripts here are written in. |
| 3 | # |
| 4 | # A build script wants the things a shell is bad at — reading deps.edn, hashing |
| 5 | # a file set, holding a path in a variable without quoting it three times — and |
| 6 | # Clojure is already the language this repo is written in. |
| 7 | # |
| 8 | # This used to be a DotSlash manifest, pinning a release of babashka the way |
| Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago | 9 | # the desktop libraries were pinned. It is the flake's now, for the reason the |
| Take bb from the flake, so a checkout needs nix and nothing else 270bee0 nandi 16d ago | 10 | # flake exists: a bb from `nixpkgs` is one this tree already names a version |
| Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago | 11 | # of, so a checkout needs nix and nothing else. Nothing is fetched by digest |
| 12 | # here any more — the libraries a run loads are the flake's too, and the only |
| 13 | # release pins left are the APK's, in nix/android.nix. |
| Take bb from the flake, so a checkout needs nix and nothing else 270bee0 nandi 16d ago | 14 | # |
| 15 | # Three answers, in order: |
| 16 | # |
| 17 | # bb on PATH the dev shell puts one there, and so does a machine that |
| Ask the bb on PATH who it is before handing it a script 57c6de2 nandi 16d ago | 18 | # has its own; either is what the caller meant — as long as |
| 19 | # it is babashka. `bb` is also what bazel's own launcher |
| 20 | # calls itself, and a host with one of those ahead of the |
| 21 | # shell's answered every recipe here with "Command |
| 22 | # 'scripts/tui.bb' not found. Try 'bb help'", which reads as |
| 23 | # a missing script rather than the wrong program |
| Take bb from the flake, so a checkout needs nix and nothing else 270bee0 nandi 16d ago | 24 | # the flake built once and kept alive by the symlink under build/, |
| 25 | # which is a gc root as well as a cache |
| 26 | # the container nix is not on every host this runs on — see CLAUDE.md — |
| 27 | # so a host without one re-enters this script where nix is, |
| 28 | # which is where the scripts want to be anyway |
| 29 | set -e |
| Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago | 30 | |
| Take bb from the flake, so a checkout needs nix and nothing else 270bee0 nandi 16d ago | 31 | root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) |
| 32 | |
| Ask the bb on PATH who it is before handing it a script 57c6de2 nandi 16d ago | 33 | # Asking it who it is, rather than trusting the name: the version line is the |
| 34 | # cheapest question babashka answers and the one nothing else answers the same |
| 35 | # way. |
| 36 | if command -v bb >/dev/null 2>&1 && bb --version 2>/dev/null | grep -qi '^babashka'; then |
| Take bb from the flake, so a checkout needs nix and nothing else 270bee0 nandi 16d ago | 37 | exec bb "$@" |
| 38 | fi |
| 39 | |
| 40 | link="$root/build/bb" |
| 41 | |
| 42 | if command -v nix >/dev/null 2>&1; then |
| 43 | # --out-link rather than --no-link: the path has to survive a gc, and the |
| 44 | # symlink is what roots it. Rebuilt only when it is gone or dangling, so |
| 45 | # the usual case is one readlink. |
| 46 | [ -x "$link/bin/bb" ] || nix build "$root#bb" --out-link "$link" >&2 |
| 47 | exec "$link/bin/bb" "$@" |
| 48 | fi |
| 49 | |
| 50 | if [ -n "$FRQ_BB_REENTERED" ]; then |
| 51 | echo "scripts/bb: no bb and no nix, inside the container too." >&2 |
| 52 | echo "Install babashka, or put a nix on this machine." >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
| 56 | exec distrobox enter arch -- bash -lc \ |
| 57 | "cd $root && FRQ_BB_REENTERED=1 exec scripts/bb \"\$@\"" -- "$@" |