nandi/frqpublic Fork 0
ac6c46a13c5a85cee364b2826ff4d7dab4d8403f
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

apk.bb · 83 lines · 3.5 KBBlitzBasic Blame HistoryRaw
Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago1#!/bin/sh
2#_(
3exec "$(dirname "$0")/bb" "$0" "$@"
4)
5
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago6;; The APK, out of the flake.
Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago7;;
8;; apk.bb [build|install|run|log]
9;;
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago10;; The build itself is nix/android.nix, reached as `.#apk`; this only asks nix
11;; for the file and then does what was asked with it. Nothing here names an
12;; Android SDK, an NDK, a Chez cross target or an OpenSSL: the derivation
13;; builds or fetches every one of them, which is the difference between this
14;; and the buck2 graph it replaces — that one was handed four hand-built paths
15;; from the machine and stopped if any was missing.
16;;
17;; The APK is signed with a debug key generated inside the derivation, so the
18;; output is installable and not reproducible; anything meant for a store gets
19;; signed from `.#apk-unsigned` instead. See nix/android.nix.
20;;
21;; FRQ_NIX_STORE builds the whole graph somewhere else rather than here —
22;;
23;; FRQ_NIX_STORE=ssh-ng://eu.nixbuild.net scripts/apk.bb
24;;
25;; which is the shape android.nix asks for: with a `builders` entry instead,
26;; nix copies every remotely-built output back, and androidenv's NDK is both
27;; `preferLocalBuild` and absent from cache.nixos.org, so 3.1 GB of toolchain
28;; is built here and uploaded. With the remote as the *store* only .drv files
29;; go up. An install then needs the file here, so it is fetched back at the
30;; end — one APK rather than the closure that made it.
Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago31(require '[babashka.classpath :as cp])
32(cp/add-classpath (str (babashka.fs/parent *file*)))
33(require '[frq.paths :as paths]
34 '[babashka.fs :as fs]
35 '[babashka.process :as p]
36 '[clojure.string :as str])
37
38(def root (str (fs/canonicalize (fs/path (fs/parent *file*) ".."))))
39(def action (or (first *command-line-args*) "build"))
40(def adb (paths/env "ADB" (str (fs/path (fs/home) ".local" "share" "android-sdk"
41 "platform-tools" "adb"))))
42(def package "uk.nandi.frq")
43
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago44;; --eval-store auto goes with a remote store and only with one: evaluation
45;; wants this tree, which is here.
46(def store
47 (when-let [s (paths/env "FRQ_NIX_STORE" nil)]
48 ["--store" s "--eval-store" "auto"]))
49
50;; Built without a `result` symlink: the path is what the caller wants, and a
51;; symlink into a store that may not be this one is not a useful thing to leave
52;; in the tree.
53(defn build []
54 (let [out (->> (paths/nix root (concat ["nix" "build" (str root "#apk")
55 "--no-link" "--print-out-paths"]
56 store))
57 (apply paths/out)
58 str/split-lines
59 (filter #(str/starts-with? % "/nix/store/"))
60 last)]
61 (when-not out
62 (paths/die "nix build printed no store path"))
63 out))
64
65;; Off a remote store the path names a file on the builder, so adb has nothing
66;; to open. `nix copy --no-check-sigs --from` brings just that one path here.
67(defn local-file []
68 (let [out (build)]
69 (when store
70 (apply p/shell (paths/nix root (concat ["nix" "copy" "--no-check-sigs"
71 "--from" (paths/env "FRQ_NIX_STORE" nil)
72 out]))))
73 out))
Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago74
75(case action
Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago76 "build" (println (build))
77 "install" (p/shell adb "install" "-r" (local-file))
78 "run" (let [file (local-file)]
Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago79 (p/shell adb "install" "-r" file)
80 (p/shell adb "shell" "am" "force-stop" package)
81 (p/shell adb "shell" "am" "start" "-n" (str package "/.FrqActivity")))
82 "log" (p/shell adb "logcat" "-s" "VidyaJolt" "Vidya")
83 (paths/die "usage: apk.bb [build|install|run|log]"))