| 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 |
| 9 | # the native libraries are pinned. It is the flake's now, for the reason the |
| 10 | # flake exists: a bb from `nixpkgs` is one this tree already names a version |
| 11 | # of, so a checkout needs nix and nothing else. DotSlash still answers for the |
| 12 | # desktop libraries — those are jolt-native's releases, which no nixpkgs has — |
| 13 | # but nothing has to be installed to reach *them* any more either, because the |
| 14 | # script that fetches them starts here. |
| 15 | # |
| 16 | # Three answers, in order: |
| 17 | # |
| 18 | # bb on PATH the dev shell puts one there, and so does a machine that |
| 19 | # has its own; either is what the caller meant |
| 20 | # the flake built once and kept alive by the symlink under build/, |
| 21 | # which is a gc root as well as a cache |
| 22 | # the container nix is not on every host this runs on — see CLAUDE.md — |
| 23 | # so a host without one re-enters this script where nix is, |
| 24 | # which is where the scripts want to be anyway |
| 25 | set -e |
| Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago | 26 | |
| Take bb from the flake, so a checkout needs nix and nothing else 270bee0 nandi 16d ago | 27 | root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) |
| 28 | |
| 29 | if command -v bb >/dev/null 2>&1; then |
| 30 | exec bb "$@" |
| 31 | fi |
| 32 | |
| 33 | link="$root/build/bb" |
| 34 | |
| 35 | if command -v nix >/dev/null 2>&1; then |
| 36 | # --out-link rather than --no-link: the path has to survive a gc, and the |
| 37 | # symlink is what roots it. Rebuilt only when it is gone or dangling, so |
| 38 | # the usual case is one readlink. |
| 39 | [ -x "$link/bin/bb" ] || nix build "$root#bb" --out-link "$link" >&2 |
| 40 | exec "$link/bin/bb" "$@" |
| 41 | fi |
| 42 | |
| 43 | if [ -n "$FRQ_BB_REENTERED" ]; then |
| 44 | echo "scripts/bb: no bb and no nix, inside the container too." >&2 |
| 45 | echo "Install babashka, or put a nix on this machine." >&2 |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | exec distrobox enter arch -- bash -lc \ |
| 50 | "cd $root && FRQ_BB_REENTERED=1 exec scripts/bb \"\$@\"" -- "$@" |