| Write the build in babashka, and pin the babashka 34832a8 nandi 19d ago | 1 | #!/bin/sh |
| 2 | #_( |
| 3 | exec "$(dirname "$0")/bb" "$0" "$@" |
| 4 | ) |
| 5 | |
| Run the app the way it is built: nix run 35e7155 nandi 18d ago | 6 | ;; The app. |
| 7 | ;; |
| 8 | ;; run.bb [args...] |
| 9 | ;; |
| 10 | ;; `nix run .#frq`, which is the whole build: the native libraries, the jolt |
| 11 | ;; runtime, the dependency graph, and a launcher that puts nixGL in front off |
| 12 | ;; NixOS so the window opens. Nothing here needs `just lib` first. |
| 13 | ;; |
| 14 | ;; Nix is not on every host that has this checkout — on the developer's it |
| 15 | ;; lives in the Arch distrobox — so a host without it is not an error, it is |
| 16 | ;; the same command run one layer in. The worktree path is the same inside the |
| 17 | ;; container as outside, which is what lets the `cd` be this path verbatim. |
| 18 | (require '[babashka.classpath :as cp]) |
| 19 | (cp/add-classpath (str (babashka.fs/parent *file*))) |
| 20 | (require '[frq.paths :as paths] |
| 21 | '[babashka.fs :as fs] |
| 22 | '[babashka.process :as p] |
| 23 | '[clojure.string :as str]) |
| Write the build in babashka, and pin the babashka 34832a8 nandi 19d ago | 24 | |
| 25 | (def root (str (fs/canonicalize (fs/path (fs/parent *file*) "..")))) |
| Run the app the way it is built: nix run 35e7155 nandi 18d ago | 26 | (def box (paths/env "FRQ_DISTROBOX" "arch")) |
| 27 | |
| 28 | (defn quote-arg |
| 29 | "One argument, safe for a shell that will read the whole line as a string." |
| 30 | [s] |
| 31 | (str "'" (str/replace (str s) "'" "'\\''") "'")) |
| 32 | |
| 33 | ;; `--` and then the args: everything past it is the app's, not nix's. |
| 34 | (def nix-args |
| 35 | (concat ["nix" "run" ".#frq"] |
| 36 | (when (seq *command-line-args*) (cons "--" *command-line-args*)))) |
| 37 | |
| 38 | (def command |
| 39 | (if (fs/which "nix") |
| 40 | (cons {:dir root} nix-args) |
| 41 | (do |
| 42 | (when-not (fs/which "distrobox") |
| 43 | (paths/die "no nix and no distrobox — install nix, or set FRQ_DISTROBOX" |
| 44 | "to a container that has it.")) |
| 45 | [{} "distrobox" "enter" box "--" |
| 46 | "bash" "-lc" (str "cd " (quote-arg root) " && " |
| 47 | (str/join " " (map quote-arg nix-args)))]))) |
| Write the build in babashka, and pin the babashka 34832a8 nandi 19d ago | 48 | |
| 49 | (System/exit |
| Run the app the way it is built: nix run 35e7155 nandi 18d ago | 50 | (:exit @(apply p/process (assoc (first command) :inherit true) |
| 51 | (rest command)))) |