nandi/frqpublic Fork 0
6ca9b5afd76b4bf644416d5a93edd1fd2f4ea41e
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.

flake.nix · 967 lines · 48.9 KBNix Blame HistoryRaw
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago1{
2 # frq is Jolt source, so "building" it is three things, not one:
3 #
4 # jolt the runtime that reads it (github:jolt-lang/jolt)
5 # jolt-native libvidya and libjoltmoq, in Rust (gitlab:nandithebull/jolt-native)
6 # frq this tree, with its deps resolved to store paths
7 #
8 # Jolt resolves deps.edn by running git at startup, which a build sandbox has
9 # no network for — so every dep is fetched by Nix instead and handed back as
10 # a :local/root through -Sdeps.
11 #
12 # nix build .#frq && ./result/bin/frq
13 #
14 # On a machine that is not NixOS the GL driver is the host's and the loader
15 # will not find it, so the window never opens ("GL display: argument does not
Find the host's GL driver when the store's is not the system's 633faad nandi 19d ago16 # name a valid config"). The launcher handles that itself: off NixOS it hands
17 # the process to nixGL, which puts the host's driver ahead of the store's.
18 # Nothing extra to type, and a distrobox/container Arch is the same case as
19 # a bare one.
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago20 description = "frq a freeq client in jolt";
21
22 inputs = {
23 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
Take jolt and jolt-native as flakes, off my own fork aaa560d nandi 13d ago24 # `git+https` with `?submodules=1` rather than the github scheme: Jolt's
25 # own flake declares `self.submodules`, which this Nix rejects when the
26 # flake is fetched as `github:`. Its outputs are not what we take — the
27 # runtime is built here, by joltFrom — but it is a flake all the same, so
28 # its own inputs are locked with ours rather than left to float, and
29 # `vendor/` comes along as the submodule the build needs.
30 #
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago31 # The fork rather than jolt-lang/jolt, and unpinned: the desktop follows
32 # the fork's main. It used to be paired with a second, pinned input for
33 # the APK's boot image; there is no jolt APK now, so there is one runtime
34 # and one rev.
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago35 jolt-src = {
Take jolt and jolt-native as flakes, off my own fork aaa560d nandi 13d ago36 url = "git+https://gitlab.com/nandithebull/jolt?submodules=1";
37 inputs.nixpkgs.follows = "nixpkgs";
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago38 };
39
Take the Android objects from jolt-native's CI, always the latest 472e179 nandi 11d ago40 # The source half of jolt-native: the Jolt code under glimmer-backends/ that
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago41 # binds the native objects, and the flake that builds them. This input is
42 # what `just run` builds against.
Take the jolt-native ahead of the release, since a run can build it 36f6c77 nandi 17d ago43 #
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago44 # It carries both backends that are left — glimmer-cosmic over
45 # libjoltcosmic for the window, glimmer-tui over libjolttui for the
46 # terminal — and no longer jvui or vidya, which were experiments.
Stop building the media plane frq no longer loads 231b9d3 nandi 9d ago47 #
Pin jolt-native at the merge rather than at the branch 3d7c428 nandi 9d ago48 # Pinned all the same, and pinned to a rev, because an
Pin the native half to the release the rest of the tree names cb7f9f1 nandi 17d ago49 # unpinned `main` is a build whose native half is free to sit at a
50 # different commit from the tree that talks to it. It did, and what the
51 # drift cost was silence: the Jolt half sent a reaction pill's hover card
52 # to a libvidya with no handler for one, and the pill said nothing.
Merge origin/main, and let one jolt-native answer for both backends 1e8b590 nandi 16d ago53 # It also carries the terminal backend — crates/jolt-tui, the same tree ABI
54 # over a grid of cells, and jolt/glimmer-tui beside glimmer-vidya. That was
55 # a second input at a second rev while it lived on a branch, which is the
56 # drift this comment warns about wearing a different hat: one input, and
57 # the window and the terminal are the same library either way.
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago58 jolt-native = {
Move the pin to the jolt-native that knows about a ceiling 3b05705 nandi 7d ago59 url = "git+https://gitlab.com/nandithebull/jolt-native?rev=5ba95e0164dfaf9110357b5e041001f98d4f13a9";
Take jolt and jolt-native as flakes, off my own fork aaa560d nandi 13d ago60 inputs.nixpkgs.follows = "nixpkgs";
Paint the same screens into a terminal ab83b42 nandi 17d ago61 };
62
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago63 # The sha deps.edn pins, on the fork with the reconciler fixes.
64 glimmer = {
65 url = "git+https://gitlab.com/nandithebull/glimmer?rev=399df371c790d690fb6e4560c3d4d7f838502857";
66 flake = false;
67 };
Find the host's GL driver when the store's is not the system's 633faad nandi 19d ago68
69 # Only ever used off NixOS, to put the host GL driver on the loader path.
70 nixgl = {
71 url = "github:nix-community/nixGL";
72 inputs.nixpkgs.follows = "nixpkgs";
73 };
Bundle the closure into one file the AppImage runtime mounts f82b93f nandi 18d ago74
75 # Wraps a closure into a single self-extracting file. Only the `appimage`
76 # output evaluates it.
77 nix-appimage = {
78 url = "github:ralismark/nix-appimage";
79 inputs.nixpkgs.follows = "nixpkgs";
80 };
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago81 };
82
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago83 outputs = { self, nixpkgs, jolt-src, jolt-native, glimmer, nixgl, nix-appimage }:
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago84 let
85 systems = [ "x86_64-linux" "aarch64-linux" ];
86 forEachSystem = f:
87 nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
Run this tree on a native half the builders made a32699e nandi 17d ago88
89 # Mesa, despite the name: it covers Intel and AMD alike. The NVIDIA
90 # wrappers are the ones that need --impure (they read the host kernel
91 # module's version), which is why this only ever reaches for Intel.
Stop carrying the 32-bit GL stack and half of git 040f2c1 nandi 16d ago92 #
93 # Built from nixGL's default.nix rather than taken from its flake
94 # outputs, for the one argument the flake hardcodes on: `enable32bits`,
95 # which on x86_64 puts a second, i686 copy of mesa, its LLVM, and
96 # intel-media-driver into the wrapper. frq is 64-bit on both halves —
97 # the Rust cdylibs and the Chez runtime — so nothing here ever opens the
98 # 32-bit driver, and carrying it is most of the dev shell's closure.
99 nixGLFor = pkgs: (import nixgl {
100 inherit pkgs;
101 enable32bits = false;
102 }).nixGLIntel;
Run this tree on a native half the builders made a32699e nandi 17d ago103
Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 7d ago104 # The Android SDK wants two things `nixpkgs.legacyPackages` cannot give:
105 # `allowUnfree`, because the SDK's own licence is not free, and
106 # `android_sdk.accept_license`, which is how you say so in a file rather
107 # than at a prompt a build has no terminal for. Neither can be set on a
108 # legacyPackages attribute after the fact, so this is a second import of
109 # the same locked nixpkgs rather than a second nixpkgs.
110 #
111 # This used to live in `just apk` as a `nix build --impure --expr` with
112 # `builtins.getFlake "github:NixOS/nixpkgs/nixos-unstable"` inside it —
113 # which fetched whatever nixos-unstable was that morning, not what
114 # flake.lock pins, so the SDK under the APK and the nixpkgs under
115 # everything else were free to drift apart. Here they are the same rev.
116 androidPkgsFor = system: import nixpkgs {
117 inherit system;
118 config = {
119 allowUnfree = true;
120 android_sdk.accept_license = true;
121 };
122 };
123
124 # Only the floor Gradle stands on. It installs build-tools and a platform
125 # into ANDROID_HOME itself as it goes — see `just apk` for why that means
126 # a writable copy — so composing more of them here buys nothing.
127 #
128 # includeNDK = false deliberately: the app is Dart and path_provider is
129 # platform channels, so there is no native code to need one, and asking
130 # for it is a few hundred megabytes and a Gradle fetch of that exact NDK.
131 androidSdkFor = system:
132 let android = androidPkgsFor system; in
133 (android.androidenv.composeAndroidPackages {
134 cmdLineToolsVersion = "13.0";
135 buildToolsVersions = [ "34.0.0" ];
136 platformVersions = [ "35" "34" ];
137 includeNDK = false;
138 }).androidsdk;
139
Run this tree on a native half the builders made a32699e nandi 17d ago140 # egui reaches for these with dlopen rather than linking them, so being
141 # in the cdylib's buildInputs is not enough — whatever starts frq has to
Follow the xorg renames, and stop wrapping nix in distrobox a400a00 nandi 16d ago142 # put them on the loader path itself. Without libx11 here, vidya reports
Run this tree on a native half the builders made a32699e nandi 17d ago143 # "X11 unavailable", falls back to Wayland, and winit refuses to build a
144 # second event loop after the failed first one.
145 #
146 # Out here rather than beside the package that first needed them: the
147 # dev shell starts frq too, on this tree's source rather than the store's
148 # copy of it, and a second copy of this list is a second chance for the
149 # two ways of running to disagree about what the window needs.
150 runtimeLibsFor = pkgs: with pkgs; [
151 libGL
152 libxkbcommon
153 wayland
Follow the xorg renames, and stop wrapping nix in distrobox a400a00 nandi 16d ago154 libx11
155 libxcursor
156 libxi
157 libxrandr
Run this tree on a native half the builders made a32699e nandi 17d ago158 vulkan-loader
159 ];
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago160 in
161 {
162 packages = forEachSystem (pkgs:
163 let
164 inherit (pkgs) lib;
165
Run this tree on a native half the builders made a32699e nandi 17d ago166 nixGL = nixGLFor pkgs;
Find the host's GL driver when the store's is not the system's 633faad nandi 19d ago167
Take the native objects from their own flake rather than rebuilding them 0ee8bba nandi 13d ago168 # libvidya (the retained-tree ABI glimmer-vidya binds, on egui),
169 # libjolttui (the same tree over a grid of cells) and libjoltmoq (the
170 # AV media plane) — one workspace, three cdylibs, taken from
171 # jolt-native's own flake rather than rebuilt here.
172 #
173 # This used to be a rustPlatform.buildRustPackage over the same
174 # source, which meant restating upstream's build: the seven git deps
175 # hashed by hand in `cargoLock.outputHashes` and re-hashed whenever
176 # its Cargo.lock moved, the linuxHeaders path v4l2r's bindgen wants,
177 # and a postPatch dropping the .cargo/config.toml that pointed the
178 # build at DotSlash. Upstream's flake says all of that itself now,
179 # and says it once. It also builds cpal with the `pipewire` feature,
180 # which the restatement did not — so device names in a call are
181 # PipeWire's rather than raw ALSA PCMs.
Paint frq with jvui, and take the last Rust out of the window 77963dc nandi 9d ago182 # libjolttui only. Not libjoltmoq, whose job `frq.av.plane` does
183 # now, and no longer libvidya either: the window is jvui on SDL,
184 # so the only object left out of that Cargo workspace is the
185 # terminal backend, and only `just tui` loads it.
Switch frq.av onto the jolt media plane, and stop shipping libjoltmoq b33f288 nandi 9d ago186 #
187 # This makes the closure smaller and the APK smaller. It does NOT
188 # make the build shorter, and it is worth being exact about why:
189 # jolt-native compiles its external crates ONCE, in a
190 # `buildDepsOnly` derivation shared by all three objects, so
191 # asking for two of them still builds every dependency the third
192 # has — the 440 crates that are jolt-moq's alone. Getting those
193 # out of the build is a change in jolt-native, not here: either
194 # jolt-moq leaves that workspace, or its deps artifact stops
195 # being workspace-wide.
196 native =
197 let np = jolt-native.packages.${pkgs.stdenv.hostPlatform.system};
198 in pkgs.symlinkJoin {
199 name = "jolt-native-ui";
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago200 # Both backends there are. libjoltcosmic is the window —
201 # libcosmic behind the same retained-tree ABI — and libjolttui
202 # is the terminal. Neither is libvidya and neither is jvui:
203 # those were experiments and are gone from this tree entirely.
204 paths = [ np.libjolttui np.libjoltcosmic ];
Switch frq.av onto the jolt media plane, and stop shipping libjoltmoq b33f288 nandi 9d ago205 };
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago206
Fetch libmoq_ffi again, and keep the codecs out of Rust f518938 nandi 9d ago207 # libmoq_ffi — MoQ over QUIC behind UniFFI's C ABI, FETCHED rather
208 # than built. This is the object `frq.moq.raw` is generated from.
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago209 #
Fetch libmoq_ffi again, and keep the codecs out of Rust f518938 nandi 9d ago210 # Fetched because building it is the thing this whole exercise is
211 # about: moq-ffi pulls moq-native, iroh, quinn, rustls and aws-lc-sys
212 # behind it, which is 440 crates that nothing else in this tree
213 # needs. Upstream already publishes the object for both Linux
214 # architectures, so we take those bytes.
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago215 #
Fetch libmoq_ffi again, and keep the codecs out of Rust f518938 nandi 9d ago216 # Pinned to a release and to a hash, and the hashes below are
217 # upstream's own published .sha256 files rather than ones observed
218 # here — a `nix-prefetch` of whatever the URL serves today would
219 # record that it downloaded something, not that it downloaded the
220 # right thing.
221 #
222 # WHAT THIS BUILD IS NOT: moq-ffi's `audio` and `video` features are
223 # on by default upstream and are OFF in these artifacts, so there is
224 # no publish_audio/publish_video and no moqaudio*/moqvideo* here —
225 # 206 functions where the Apple artifact has 230. That is why the
226 # bindings are generated from the object (`just gen-moq`) and not
227 # from the C header the release ships, which describes the Apple one.
228 moqFfi =
229 let
230 version = "0.3.17";
231 target = {
232 "x86_64-linux" = "x86_64-unknown-linux-gnu";
233 "aarch64-linux" = "aarch64-unknown-linux-gnu";
234 }.${pkgs.stdenv.hostPlatform.system};
235 hash = {
236 "x86_64-linux" = "sha256-dzQXpV4JgdtD+g33WX51FFAQdfCUXkNsx1xPbobPfUI=";
237 "aarch64-linux" = "sha256-PdzRwbJFqOZWRgI0HHX2XUH+Ljh4V3jvQ9asfvCuIPA=";
238 }.${pkgs.stdenv.hostPlatform.system};
239 in
240 pkgs.stdenv.mkDerivation {
241 pname = "libmoq-ffi";
242 inherit version;
243 src = pkgs.fetchurl {
244 url = "https://github.com/kixelated/moq/releases/download/moq-ffi-v${version}/moq-ffi-${version}-${target}-libmoq_ffi.so";
245 inherit hash;
246 };
247 dontUnpack = true;
248 # It carries no RUNPATH and needs libgcc_s, libm and libc — the
249 # host's on an ordinary distro, and nothing at all on NixOS
250 # unless they are bound here.
251 nativeBuildInputs = [ pkgs.autoPatchelfHook ];
252 buildInputs = [ pkgs.stdenv.cc.cc.lib ];
253 installPhase = ''
254 mkdir -p $out/lib
255 cp $src $out/lib/libmoq_ffi.so
256 chmod +w $out/lib/libmoq_ffi.so
257 '';
258 };
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago259
260 # One directory for the loader to look in. jolt resolves every
261 # :jolt/native name against JOLT_NATIVE_LIB, and the objects now come
262 # from two places — jolt-native's flake, and the moq-ffi release — so
263 # they are joined rather than the path being made a list, which the
264 # loader does not take.
Bind the C libraries a call actually needs 87e5be9 nandi 9d ago265 # The C codecs, from nixpkgs. libmoq_ffi carries the transport and
266 # nothing else — moq-ffi's `audio` and `video` features would have
267 # brought Opus and H.264 with them, at the price of compiling a
268 # 1062-crate workspace — so the codecs are linked here instead,
269 # where they have always lived.
270 #
271 # Named in :jolt/native, so the loader resolves them the same way it
272 # resolves libvidya: by name, out of one directory.
273 # A flat C face for openh264, because openh264 has none. Its
274 # `ISVCEncoder` is `const ISVCEncoderVtbl*` — every method is a
275 # function pointer in a vtable — and jolt.ffi cannot call one: Chez
276 # fixes a foreign procedure's types when it compiles it, and the
277 # target must be a literal C symbol name. So the vtable is walked in
278 # c/frq_h264.c and jolt binds the five plain symbols it exports.
279 #
280 # One translation unit against a library nixpkgs already has. It is
281 # a calling convention adapter, not a second media plane, and the
282 # distinction from the moq-ffi build it replaces is the whole point:
283 # this compiles one .c file, not a 1062-crate workspace.
284 frqH264 = pkgs.stdenv.mkDerivation {
285 pname = "frq-h264";
286 version = "0.1";
287 src = ./c;
288 nativeBuildInputs = [ pkgs.pkg-config ];
289 buildInputs = [ pkgs.openh264 ];
290 buildPhase = ''
291 $CC -O2 -fPIC -shared frq_h264.c -o libfrqh264.so \
292 $(pkg-config --cflags --libs openh264)
293 '';
294 installPhase = ''
295 mkdir -p $out/lib && cp libfrqh264.so $out/lib/
296 '';
297 };
298
299 # openh264 is here for frqH264's DT_NEEDED; alsa-lib for capture
300 # and playback. V4L2 needs nothing: it is ioctls against libc and
301 # the kernel, so there is no library to name.
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago302 # No SDL any more: it was jvui's, declared in jvui's own
303 # :jolt/native and dlopened by soname. libcosmic paints through wgpu
304 # and takes what it needs from `runtimeLibs` instead.
305 codecs = [ pkgs.libopus pkgs.openh264 frqH264 pkgs.alsa-lib ];
Bind the C libraries a call actually needs 87e5be9 nandi 9d ago306
Let the plane take real devices, not only test thunks 596dc29 nandi 9d ago307 # ALSA's PipeWire plugin, which is how `default` resolves to
308 # anything on a machine running PipeWire — and every machine frq
309 # targets does. Without it alsa-lib fails to dlopen
310 # libasound_module_pcm_pipewire.so and the only devices that open
311 # are raw hardware ones, which PipeWire is already holding.
312 #
313 # An environment variable rather than a library in the join:
314 # alsa-lib looks plugins up by directory, not by soname.
315 alsaPluginDir = "${pkgs.pipewire}/lib/alsa-lib";
316
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago317 nativeAll = pkgs.symlinkJoin {
318 name = "frq-native";
Bind the C libraries a call actually needs 87e5be9 nandi 9d ago319 paths = [ native moqFfi ] ++ codecs;
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago320 };
321
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago322 # Jolt itself: Clojure on Chez, built the way its own flake builds it.
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago323 #
324 # Still a function taking its source, though there is only one of
325 # them now: the second was the Bionic-addrinfo fork the APK's boot
326 # image carried, and there is no jolt APK any more — the phone is
327 # ClojureDart and Flutter, and jolt does not run there at all.
Build the APK from the flake, and from nothing 6aa2a6b nandi 18d ago328 joltFrom = src: pkgs.stdenv.mkDerivation {
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago329 pname = "jolt";
330 version = "dev";
Build the APK from the flake, and from nothing 6aa2a6b nandi 18d ago331 inherit src;
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago332
333 strictDeps = true;
334 nativeBuildInputs = with pkgs; [ chez makeWrapper pkg-config xxd ];
335 buildInputs = with pkgs; [ lz4 zlib ncurses openssl libuuid ];
336
337 JOLT_VERSION = "dev";
338 dontConfigure = true;
339
340 buildPhase = ''
341 runHook preBuild
342 scheme --script host/chez/build-jolt.ss release target/release/jolt
343 runHook postBuild
344 '';
345
346 installPhase = ''
347 runHook preInstall
348 mkdir -p "$out/bin"
349 install -m755 target/release/jolt "$out/bin/jolt"
350 runHook postInstall
351 '';
352
353 # jolt.deps shells out to git and unzip, and jolt.mvn-http dlopens
Stop carrying the 32-bit GL stack and half of git 040f2c1 nandi 16d ago354 # OpenSSL through the JOLT_OPENSSL_LIBDIR seam. gitMinimal rather
355 # than git: all jolt.deps asks for is clone/fetch/rev-parse, and
356 # the full package carries Perl and Python for the subcommands
357 # written in them — a quarter of a gigabyte for git-send-email.
Read the clock in the reader's zone when /etc/localtime is a file bffe879 nandi 18d ago358 #
359 # TZDIR so a zone *name* resolves wherever this runs: frq.clock
360 # hands one to tzset, and glibc then looks for the tzfile under
361 # /usr/share/zoneinfo unless told otherwise — which a NixOS host
362 # does not have. The store's own tzdata is there on both kinds of
363 # machine. --set-default, so a TZDIR the user set still wins.
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago364 postFixup = ''
365 wrapProgram "$out/bin/jolt" \
Stop carrying the 32-bit GL stack and half of git 040f2c1 nandi 16d ago366 --prefix PATH : "${pkgs.lib.makeBinPath [ pkgs.gitMinimal pkgs.unzip ]}" \
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago367 --set-default JOLT_OPENSSL_LIBDIR "${pkgs.lib.makeLibraryPath [ pkgs.openssl ]}" \
Read the clock in the reader's zone when /etc/localtime is a file bffe879 nandi 18d ago368 --set-default TZDIR "${pkgs.tzdata}/share/zoneinfo" \
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago369 --set-default SSL_CERT_FILE "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
370 '';
371 };
372
Build the APK from the flake, and from nothing 6aa2a6b nandi 18d ago373 joltRuntime = joltFrom jolt-src;
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago374
375 # The backends' Clojure halves, which live inside the jolt-native
376 # checkout beside the objects they bind. Their own deps.edn asks for
377 # glimmer by git — the top-level override below answers for both.
378 glimmerCosmic = "${jolt-native}/glimmer-backends/glimmer-cosmic";
Take the Android objects from jolt-native's CI, always the latest 472e179 nandi 11d ago379 glimmerTui = "${jolt-native}/glimmer-backends/glimmer-tui";
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago380
Run this tree on a native half the builders made a32699e nandi 17d ago381 runtimeLibs = runtimeLibsFor pkgs;
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago382
383 # The project as jolt sees it: source, deps.edn, nothing else.
384 frqSource = pkgs.runCommand "frq-source" { } ''
385 mkdir -p "$out"
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago386 cp -r ${self}/common ${self}/src ${self}/deps.edn "$out/"
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago387 '';
388
389 # Jolt resolves deps.edn from the working directory, so the launcher
390 # runs from the store copy. Its .jolt/cpcache write lands on a
391 # read-only directory and jolt treats that as a quiet cache miss, so
392 # the only cost is re-resolving the (already local) graph per start.
393 frqScript = pkgs.writeShellScript "frq" ''
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago394 export LD_LIBRARY_PATH="${nativeAll}/lib:${lib.makeLibraryPath runtimeLibs}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
Let the plane take real devices, not only test thunks 596dc29 nandi 9d ago395 export ALSA_PLUGIN_DIR="${alsaPluginDir}"
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago396 cd ${frqSource}
Find the host's GL driver when the store's is not the system's 633faad nandi 19d ago397
398 # On NixOS the store's Mesa is the system's and the window opens.
399 # Anywhere else the real driver is the host's, so defer to nixGL
400 # it prepends the host driver, which has to win over ours.
401 runner=""
402 [ -e /run/current-system ] || runner="${nixGL}/bin/nixGLIntel"
403
404 exec ''${runner} ${joltRuntime}/bin/jolt \
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago405 -Sdeps '{:deps {jolt-lang/glimmer {:local/root "${glimmer}"} nandi/glimmer-cosmic {:local/root "${glimmerCosmic}"}}}' \
406 -m frq.cosmic "$@"
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago407 '';
408
Paint the same screens into a terminal ab83b42 nandi 17d ago409 # The same source, the other backend. No GL, no nixGL and no X11 —
410 # a terminal is the one surface that needs nothing from the host but
411 # a terminal, which is the reason this output exists.
412 tuiScript = pkgs.writeShellScript "frq-tui" ''
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago413 export LD_LIBRARY_PATH="${nativeAll}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
Let the plane take real devices, not only test thunks 596dc29 nandi 9d ago414 export ALSA_PLUGIN_DIR="${alsaPluginDir}"
Paint the same screens into a terminal ab83b42 nandi 17d ago415 cd ${frqSource}
416
417 exec ${joltRuntime}/bin/jolt \
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago418 -Sdeps '{:deps {jolt-lang/glimmer {:local/root "${glimmer}"} nandi/glimmer-tui {:local/root "${glimmerTui}"}}}' \
Paint the same screens into a terminal ab83b42 nandi 17d ago419 -m frq.tui "$@"
420 '';
421
422 tui = pkgs.runCommand "frq-tui-0.1.0"
423 {
424 meta = {
425 description = "frq's screens in a terminal";
426 mainProgram = "frq-tui";
427 platforms = systems;
428 };
429 }
430 ''
431 mkdir -p "$out/bin"
432 ln -s ${tuiScript} "$out/bin/frq-tui"
433 '';
434
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago435 frq = pkgs.runCommand "frq-0.1.0"
436 {
437 meta = {
438 description = "A freeq client in jolt";
439 mainProgram = "frq";
440 platforms = systems;
441 };
442 }
443 ''
444 mkdir -p "$out/bin"
445 ln -s ${frqScript} "$out/bin/frq"
446 '';
447 in
448 {
Bind the C libraries a call actually needs 87e5be9 nandi 9d ago449 inherit native moqFfi frqH264 nativeAll frq;
Let the plane take real devices, not only test thunks 596dc29 nandi 9d ago450 inherit (pkgs) pipewire;
Merge origin/main, and let one jolt-native answer for both backends 1e8b590 nandi 16d ago451 inherit tui;
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago452 jolt = joltRuntime;
453 default = frq;
Bundle the closure into one file the AppImage runtime mounts f82b93f nandi 18d ago454
Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 7d ago455 # The Android SDK `just apk` copies into flutter/.home. A package
456 # rather than something the recipe evaluates inline, so that
457 # `nix build .#android-sdk` is how you pre-warm it and `nix flake
458 # show` admits it exists.
459 android-sdk = androidSdkFor pkgs.stdenv.hostPlatform.system;
460
Bundle the closure into one file the AppImage runtime mounts f82b93f nandi 18d ago461 # frq and everything it loads, squashed into one runnable file for
462 # hosts without Nix. The whole closure rides along — Mesa included,
463 # which is not waste: off NixOS the launcher goes through nixGL, and
464 # nixGL needs a store Mesa to put the host's driver in front of.
465 appimage =
466 nix-appimage.bundlers.${pkgs.stdenv.hostPlatform.system}.default frq;
Build the Flutter desktop GUI with nix, sandbox and all 6ca9b5a nandi 7d ago467
468 # Everything `clojure -M:cljd compile` would otherwise reach the
469 # network for, fetched once and hashed.
470 #
471 # The compile needs three caches, and the reason this is one
472 # derivation rather than three is that only one of them is obvious.
473 # Maven and gitlibs are the ordinary tools.deps pair. The third is
474 # ClojureDart's own: `ensure-cljd-analyzer!` writes a *second*, whole
475 # pub project to `.clojuredart/cache/<cljd sha>/cljd_helper`, runs
476 # `pub add analyzer` in it, and then runs `bin/analyzer.dart` out of
477 # it for the duration of the compile — so a sandbox needs that
478 # project already resolved, not just the app's dependencies.
479 #
480 # Fixed-output, so it is allowed the network the rest of the build is
481 # not. What that costs is a hash to maintain, and the thing worth
482 # being exact about is *when*: this derivation never sees frq's
483 # source. It compiles a three-line throwaway project against the same
484 # `flutter/deps.edn` and the same `flutter/pubspec.yaml`, so the hash
485 # moves when a dependency moves and not when a screen changes. A
486 # stub, rather than `-P` and a hand-built analyzer dir, because
487 # running the real compiler once is the only way to be sure the
488 # caches are the ones it actually wants.
489 #
490 # PUB_CACHE lands in $out on purpose. The package_config.json inside
491 # cljd_helper carries absolute paths to whatever resolved it, so
492 # resolving into a build directory would bake in paths that stop
493 # existing the moment this derivation finishes. Pointed at $out they
494 # are store paths, and still true.
495 cljd-deps =
496 let
497 flutterPkg = pkgs.flutter;
498 in
499 pkgs.stdenvNoCC.mkDerivation {
500 name = "frq-cljd-deps";
501 dontUnpack = true;
502
503 nativeBuildInputs = [
504 pkgs.clojure
505 pkgs.jdk17
506 flutterPkg
507 pkgs.git
508 pkgs.cacert
509 ];
510
511 buildCommand = ''
512 export HOME="$NIX_BUILD_TOP/home"
513 # Resolved in the build directory and copied to $out at the
514 # end, never written there directly. A fixed-output derivation
515 # may not reference a store path and its own output is a store
516 # path, so pub writing its cache's absolute location into its
517 # own metadata is enough to fail the check.
518 cache="$NIX_BUILD_TOP/cache"
519 export PUB_CACHE="$cache/pub-cache"
520 export GITLIBS="$cache/gitlibs"
521 export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
522 mkdir -p "$HOME" "$PUB_CACHE" "$GITLIBS" "$cache/m2"
523
524 # The stub: our dependency files, nothing of our source. `:paths`
525 # still names ../common, so that has to exist for tools.deps to
526 # build a classpath empty is enough.
527 proj="$NIX_BUILD_TOP/stub"
528 mkdir -p "$proj/src/stub" "$NIX_BUILD_TOP/common"
529 cp ${./flutter/deps.edn} "$proj/deps.edn"
530 cp ${./flutter/pubspec.yaml} "$proj/pubspec.yaml"
531 chmod u+w "$proj/deps.edn" "$proj/pubspec.yaml"
532 cat > "$proj/src/stub/main.cljd" <<'EOF'
533 (ns stub.main)
534 (defn main [] nil)
535 EOF
536
537 cd "$proj"
538 # `:main` has to name the stub, or the compiler goes looking for
539 # frq.main in a tree that is not here.
540 sed -i 's/:main frq\.main/:main stub.main/' deps.edn
541
542 flutter config --no-analytics &>/dev/null || true
543 flutter config --enable-linux-desktop >/dev/null || true
544
545 clojure -Sdeps '{:mvn/local-repo "'"$cache"'/m2"}' -M:cljd compile
546
547 # What the compile left behind, and only that. The analyzer
548 # project is keyed by the ClojureDart sha, so the directory
549 # under cache/ is copied wholesale rather than named here.
550 mkdir -p "$out/clojuredart"
551 cp -r .clojuredart/cache "$out/clojuredart/cache"
552 cp -r "$cache/m2" "$out/m2"
553 cp -r "$cache/gitlibs" "$out/gitlibs"
554 cp -r "$PUB_CACHE" "$out/pub-cache"
555
556 # A fixed-output derivation may not reference a store path, and
557 # a resolved pub project is nothing but store paths:
558 # package_config.json names the Flutter SDK and every package
559 # in the cache by absolute path. So the analyzer project ships
560 # *unresolved* its pubspec and its analyzer.dart and nothing
561 # else and `flutter pub get --offline` re-resolves it against
562 # this cache at build time, where naming the store is allowed.
563 find "$out" \( -name '.dart_tool' -o -name '.flutter-plugins' \
564 -o -name '.flutter-plugins-dependencies' \) -prune -exec rm -rf {} +
565 find "$out" -name '.packages' -delete
566
567
568 # A fixed-output hash is a promise that two runs agree, so
569 # everything a tool writes *about* a run rather than about a
570 # dependency has to go: pub's log carries timestamps, Maven
571 # rewrites its resolution metadata on every resolve, and
572 # tools.gitlibs keeps bare clones it only needs in order to
573 # make a checkout. None of it is read offline.
574 rm -rf "$out/pub-cache/log" "$out/pub-cache/_temp" \
575 "$out/pub-cache/git" "$out/pub-cache/global_packages" \
576 "$out/pub-cache/bin"
577
578 # tools.gitlibs keeps a bare clone per URL under _repos/, and a
579 # bare clone is packfiles which two runs of the same fetch do
580 # not have to produce byte for byte. It cannot simply be
581 # deleted, because `procure` calls `ensure-git-dir` before it
582 # looks at anything else and would clone it again, over a
583 # network this has and the build that uses it does not.
584 #
585 # It does not need the objects, though. `procure` finds the sha
586 # with `match-exact` against the checkout already in libs/, so
587 # the bare repo only has to exist. Emptied and re-initialised,
588 # it is a fixed handful of files from the pinned git and the
589 # same on every run.
590 find "$out/gitlibs/_repos" -name HEAD | while read -r head; do
591 repo="$(dirname "$head")"
592 rm -rf "$repo"
593 git init --bare -q "$repo"
594 # The sample hooks are shell scripts, so they carry a
595 # `#!/nix/store/.../bash` line which is exactly the kind of
596 # store reference a fixed-output derivation may not hold. An
597 # empty bare repo nothing ever runs has no use for them.
598 rm -rf "$repo/hooks"
599 done
600 # pub's version listings, which record when they were fetched.
601 # This is the one that actually moved between two runs of this
602 # derivation: the package sources under hosted/ were identical
603 # and the listings beside them were not. Nothing offline reads
604 # them a resolution that already has every package on disk
605 # never asks pub.dev what versions exist.
606 find "$out/pub-cache" -name '.cache' -type d -prune -exec rm -rf {} +
607 find "$out/m2" \( -name '*.lastUpdated' -o -name '_remote.repositories' \
608 -o -name 'resolver-status.properties' -o -name '*.part' \
609 -o -name 'maven-metadata-*.xml*' \) -delete
610 find "$out" \( -name '.DS_Store' -o -name '*.log' -o -name '.git' \) \
611 -prune -exec rm -rf {} +
612 find "$out" -type d -empty -delete
613 chmod -R u+w "$out"
614
615 # Last, after every cleanup above: anything still naming the
616 # store fails the fixed-output check, and the error names one
617 # path out of thousands of files. This names the files.
618 if refs="$(grep -rlI /nix/store "$out" 2>/dev/null)" && [ -n "$refs" ]; then
619 echo "cljd-deps: these still reference the store:" >&2
620 echo "$refs" | head -20 >&2
621 fi
622
623 # If two runs disagree, this says which half to look in. Cheap,
624 # and the alternative is a hash mismatch with nothing attached.
625 for d in "$out"/*; do
626 echo "cljd-deps subtree $(basename "$d") $( (cd "$d" && find . -type f \
627 -exec sha256sum {} + | sort -k2 | sha256sum) )" >&2
628 done
629 for d in "$out"/pub-cache/*/*; do
630 [ -d "$d" ] || continue
631 echo "cljd-deps pub $(basename "$d") $( (cd "$d" && find . -type f \
632 -exec sha256sum {} + | sort -k2 | sha256sum) )" >&2
633 done
634 '';
635
636 outputHashMode = "recursive";
637 outputHashAlgo = "sha256";
638 # Moves when flutter/deps.edn or flutter/pubspec.yaml move, and
639 # not when frq's own source does — see the stub above.
640 outputHash = "sha256-gfJGlKCPaJsKcXfCWOJY1089XEfzTndEx0LVf3JOXfs=";
641 };
642
643 # The Flutter desktop GUI, built rather than run out of the tree.
644 #
645 # `just flutter-desktop` is the working-tree loop and this is its
646 # opposite number, the same way `nix build .#frq` is `just run`'s: the
647 # source is the flake's, the output is a store path, and the build is
648 # a sandbox with no network. It is the first thing here that builds
649 # purely — the APK cannot, because Gradle fetches as it goes.
650 #
651 # Two stages, because the Dart does not exist until ClojureDart writes
652 # it. `preBuild` runs the compiler over `flutter/src` and `common/`
653 # with `--offline`, out of the caches `cljd-deps` fetched; everything
654 # after that is an ordinary Flutter application as far as nixpkgs is
655 # concerned.
656 #
657 # The caches are copied in rather than used where they lie. Maven,
658 # tools.gitlibs and pub all expect to be able to write to their own
659 # cache — a lock file, a resolved marker — and the store is read-only,
660 # so pointing them at $out of a fixed-output derivation fails in three
661 # different ways at three different depths.
662 #
663 # `src` is the whole tree and not `flutter/`: `flutter/deps.edn` puts
664 # `../common` on the classpath, which is the entire point of that
665 # directory, and a source root of `flutter/` would leave the screens
666 # outside it.
667 flutter-desktop-unwrapped = pkgs.flutter.buildFlutterApplication rec {
668 pname = "frq-flutter";
669 version = "0.1.0";
670
671 src = lib.cleanSourceWith {
672 src = ./.;
673 # Build trees and caches, which are large, machine-specific and
674 # would make every one of them a new store path.
675 filter = path: type:
676 let base = baseNameOf path; in
677 !(builtins.elem base [
678 "build" ".home" ".clojuredart" ".cpcache" "cljd-out"
679 ".dart_tool" "result" ".git" ".jolt" "buck-out"
680 ]);
681 };
682 sourceRoot = "source/flutter";
683
684 # Read at eval time, so the lock in git is the lock that is built.
685 autoPubspecLock = ./flutter/pubspec.lock;
686
687 # git, because tools.deps resolves the ClojureDart dependency through
688 # tools.gitlibs even when every byte of it is already on disk — see
689 # the _repos note in cljd-deps.
690 nativeBuildInputs = [ pkgs.clojure pkgs.jdk17 pkgs.git ];
691
692 preBuild = ''
693 export PUB_CACHE="$NIX_BUILD_TOP/pub-cache"
694 export GITLIBS="$NIX_BUILD_TOP/gitlibs"
695 cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/pub-cache "$PUB_CACHE"
696 cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/gitlibs "$GITLIBS"
697 cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/m2 "$NIX_BUILD_TOP/m2"
698 mkdir -p .clojuredart
699 cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/clojuredart/cache .clojuredart/cache
700 chmod -R u+w "$PUB_CACHE" "$GITLIBS" "$NIX_BUILD_TOP/m2" .clojuredart
701
702 # Resolve the analyzer project here rather than in cljd-deps,
703 # which was not allowed to name the store. Offline, out of the
704 # cache that derivation did fetch. ClojureDart only reaches for
705 # the network when `bin/analyzer.dart` is missing, and it is not.
706 for helper in .clojuredart/cache/*/cljd_helper; do
707 ( cd "$helper" && flutter pub get --offline )
708 done
709
710 # --offline is what keeps `pub get` out of a sandbox that has no
711 # network; the analyzer project it would otherwise resolve is
712 # already in .clojuredart, put there by cljd-deps.
713 clojure -Sdeps "{:mvn/local-repo \"$NIX_BUILD_TOP/m2\"}" \
714 -M:cljd compile --offline
715 '';
716
717 meta = {
718 description = "frq's screens on Flutter's Linux target (no GL launcher)";
719 mainProgram = "frq";
720 platforms = systems;
721 };
722 };
723
724 # The same shape as `frq` above: a launcher, and a package that is a
725 # symlink to it. The reason is the same one `frqScript` gives — on
726 # NixOS the store's Mesa is the system's and the window opens, and
727 # anywhere else the real driver is the host's, so the process is
728 # handed to nixGL. Without it the store build dies on a distrobox
729 # Arch with "No provider of eglGetPlatformDisplayEXT found", which is
730 # that failure wearing an EGL hat.
731 #
732 # A wrapper *around* the built application rather than a `postFixup`
733 # inside it, because buildFlutterApplication's own dartFixupHook runs
734 # after postFixup and rewrites `bin/frq` — so anything done to that
735 # path from inside is undone on the way out.
736 flutter-desktop =
737 let
738 unwrapped =
739 self.packages.${pkgs.stdenv.hostPlatform.system}.flutter-desktop-unwrapped;
740 script = pkgs.writeShellScript "frq" ''
741 runner=""
742 [ -e /run/current-system ] || runner="${nixGLFor pkgs}/bin/nixGLIntel"
743 exec ''${runner} ${unwrapped}/bin/frq "$@"
744 '';
745 in
746 pkgs.runCommand "frq-flutter-0.1.0"
747 {
748 meta = {
749 description = "frq's screens on Flutter's Linux target";
750 mainProgram = "frq";
751 platforms = systems;
752 };
753 }
754 ''
755 mkdir -p "$out/bin"
756 ln -s ${script} "$out/bin/frq"
757 '';
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago758 });
759
Run this tree on a native half the builders made a32699e nandi 17d ago760 # Where `just run` runs, and — because entering it realises what it
761 # names — what builds the half of frq that is not this working tree.
762 #
763 # The two halves, and the split is the whole point of the shell. The frq
764 # source is the files on disk, uncommitted edits and all. Everything
765 # under it — jolt, glimmer, glimmer-vidya, both native objects — is the
766 # flake's, at the revs flake.lock names, so a run says what it ran
767 # against and both halves of glimmer-vidya move together. That is the
768 # drift the `jolt-native` input's comment is about, and a pin frq can
769 # answer for is worth more here than the convenience of a checkout.
770 #
Take the native objects from their own flake rather than rebuilding them 0ee8bba nandi 13d ago771 # `native` is jolt-native's own flake output. It was a buck2 graph when
772 # this comment was first written and a cargo build restated here when it
773 # was second: buck2 fetches its rustc, zig and every third-party crate as
774 # it goes and writes buck-out into the tree it builds, so a sandbox with
775 # no network and a read-only store was the one place it could not run.
776 # Upstream builds with nix now, so the thing its CI runs and the thing
777 # this shell hands a builder are the same derivation.
Run this tree on a native half the builders made a32699e nandi 17d ago778 #
779 # Nothing here says "nixbuild", though: it is a plain derivation, and
Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago780 # where it gets built is the machine's business. The `run` recipe asks for
Run this tree on a native half the builders made a32699e nandi 17d ago781 # the shell with --max-jobs 0, which is what sends it to the `builders`
782 # entry rather than compiling egui on a laptop.
783 devShells = forEachSystem (pkgs:
784 let
785 inherit (pkgs) lib;
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago786 inherit (self.packages.${pkgs.stdenv.hostPlatform.system}) jolt native nativeAll;
Run this tree on a native half the builders made a32699e nandi 17d ago787 in
788 {
789 default = pkgs.mkShellNoCC {
790 name = "frq";
791
792 # jolt, because the runtime frq is run by should be the flake's
793 # too. nixGL for the same reason the launcher reaches for it — see
Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago794 # frqScript. just so the recipe runner comes from here too rather
795 # than the host — `nix develop` and then `just run` is the whole of
796 # what a machine with nix needs.
797 packages = [ jolt pkgs.just (nixGLFor pkgs) ];
798
799 # Read by the recipes rather than baked into a wrapper: the frq
Run this tree on a native half the builders made a32699e nandi 17d ago800 # source `just run` runs is the working tree, so the launcher has
Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago801 # to live in that tree and the shell has to hand it its answers.
802 # Naming these is also what makes the shell build them.
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago803 JOLT_NATIVE_LIB = "${nativeAll}/lib";
Let the plane take real devices, not only test thunks 596dc29 nandi 9d ago804 # Spelled out rather than shared with the packages block, which
805 # is a different `let`. See `alsaPluginDir` there for why.
806 ALSA_PLUGIN_DIR = "${pkgs.pipewire}/lib/alsa-lib";
Run this tree on a native half the builders made a32699e nandi 17d ago807 GLIMMER_SRC = glimmer;
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago808 GLIMMER_COSMIC_SRC = "${jolt-native}/glimmer-backends/glimmer-cosmic";
Take the Android objects from jolt-native's CI, always the latest 472e179 nandi 11d ago809 GLIMMER_TUI_SRC = "${jolt-native}/glimmer-backends/glimmer-tui";
Run this tree on a native half the builders made a32699e nandi 17d ago810 FRQ_LIB_PATH = lib.makeLibraryPath (runtimeLibsFor pkgs);
811 NIXGL = "${nixGLFor pkgs}/bin/nixGLIntel";
Take the jolt-native beside this one when there is one e10e1c1 nandi 9d ago812
813 # A checkout of jolt-native beside this one, in place of the pin.
814 #
815 # The pin is a rev on a server, so the loop for a change to the
816 # terminal backend was commit, push, re-pin, re-lock — four steps
817 # and an upload for a line of Rust. With a working copy beside this
818 # one the loop is `cargo build` and `just tui`, and the shell finds
819 # that copy itself: ../jolt-native from the checkout this was run
820 # in, which is where it is on the machines this is developed on.
821 # A worktree under .claude/worktrees counts as the same checkout —
822 # the sibling is the main one's, not the worktree's.
823 #
824 # Found rather than named, but not silently: it says which tree it
825 # took on the way in, because `just tui` running something other
826 # than the pin is the sort of thing you have to be able to see.
827 #
828 # It has to be a built one. A checkout with no target/release/
829 # libjolttui.so in it would mean the Jolt half of the backend from
830 # the working copy and the shared object from the pin — two halves
831 # of two different libraries, which fail in ways that look like
832 # neither. So an unbuilt sibling is left alone and the pin stands.
833 #
834 # FRQ_JOLT_NATIVE overrides the search, and is taken even unbuilt
835 # (with a word about what to run): naming a tree is asking for it.
836 # Empty is how you say the pin, on a machine that has a sibling and
837 # wants what everyone else is running.
838 #
839 # Only the sources and libjolttui move either way. Everything else
840 # on the library path — libopus, libmoq_ffi, the ALSA plugins —
841 # stays the pin's, since a checkout has no build of those to offer.
842 shellHook = ''
843 frq_named=1
844 if [ -z "''${FRQ_JOLT_NATIVE+named}" ]; then
845 frq_named=
846 frq_git="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null || true)"
847 frq_near="''${frq_git:+$(dirname "$(dirname "$frq_git")")/jolt-native}"
848 if [ -n "$frq_near" ] && [ -e "$frq_near/target/release/libjolttui.so" ]; then
849 FRQ_JOLT_NATIVE="$frq_near"
850 else
851 FRQ_JOLT_NATIVE=""
852 fi
853 fi
854 if [ -n "$FRQ_JOLT_NATIVE" ]; then
855 if [ -d "$FRQ_JOLT_NATIVE/crates/jolt-tui" ]; then
856 FRQ_JOLT_NATIVE="$(cd "$FRQ_JOLT_NATIVE" && pwd)"
857 export FRQ_JOLT_NATIVE
858 export GLIMMER_TUI_SRC="$FRQ_JOLT_NATIVE/glimmer-backends/glimmer-tui"
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago859 export GLIMMER_COSMIC_SRC="$FRQ_JOLT_NATIVE/glimmer-backends/glimmer-cosmic"
Take the jolt-native beside this one when there is one e10e1c1 nandi 9d ago860 # First, so a cargo build wins over the pin's copy of the
861 # same object. The rest of the pin's lib directory is still
862 # behind it.
863 export JOLT_NATIVE_LIB="$FRQ_JOLT_NATIVE/target/release:$JOLT_NATIVE_LIB"
864 echo "frq: jolt-native from $FRQ_JOLT_NATIVE, not the pin (FRQ_JOLT_NATIVE= for the pin)" >&2
865 if [ ! -e "$FRQ_JOLT_NATIVE/target/release/libjolttui.so" ]; then
866 echo "frq: no libjolttui.so there yet cargo build --release --features terminal -p jolt-tui" >&2
867 fi
868 elif [ -n "$frq_named" ]; then
869 echo "frq: FRQ_JOLT_NATIVE=$FRQ_JOLT_NATIVE is not a jolt-native checkout; using the pin" >&2
870 fi
871 fi
872 unset frq_named frq_git frq_near
873 '';
Run this tree on a native half the builders made a32699e nandi 17d ago874 };
Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 7d ago875
876 # The APK toolchain, which the default shell deliberately does not
877 # carry: Flutter brings its own Dart, Gradle and a JDK's worth of
878 # closure, and a desktop build has no use for any of it.
879 #
880 # `just apk` used to name these as `nix shell nixpkgs#clojure
881 # nixpkgs#jdk17 nixpkgs#flutter`, which is the flake registry's
882 # nixpkgs and not this flake's — so the Flutter under the APK
883 # floated while everything else was locked. Same three packages,
884 # from flake.lock now.
885 #
886 # JDK 17 and not newer on purpose: the Flutter template's Gradle
887 # plugin pins a Gradle that rejects a JDK it was released before,
888 # and the failure reads as an unsupported class file version rather
889 # than as a version mismatch.
890 flutter = pkgs.mkShellNoCC {
891 name = "frq-flutter";
892 packages = [ pkgs.clojure pkgs.jdk17 pkgs.flutter pkgs.just ];
893
894 # Where the recipe copies from. Naming it here is also what makes
895 # entering the shell build it, so the first `just apk` does not
896 # stop for a few hundred megabytes of SDK with nothing said about
897 # why.
898 FRQ_ANDROID_SDK =
899 "${androidSdkFor pkgs.stdenv.hostPlatform.system}/libexec/android-sdk";
900 };
Paint the desktop with Flutter too, beside libcosmic fc5f63c nandi 7d ago901
902 # The other desktop GUI. Same ClojureDart half as the APK — one
903 # `clojure -M:cljd compile`, one flutter/src — over Flutter's Linux
904 # target instead of its Android one, so `flutter/linux/` is the
905 # runner and CMake and Ninja are the build rather than Gradle.
906 #
907 # A separate shell from `flutter` rather than one that carries both,
908 # because the halves are disjoint: this wants GTK and a C++ toolchain
909 # and no JDK, and the APK wants a JDK and an SDK and no GTK. Sharing
910 # them would mean every desktop build paying for a few hundred
911 # megabytes of Android SDK it never opens, which is the same argument
912 # that keeps Flutter out of the default shell.
913 #
914 # mkShell and not mkShellNoCC, unlike every other shell here: this is
915 # the one that actually compiles C++. stdenv brings the compiler, and
916 # gtk3 in buildInputs is what puts its .pc file where the runner's
917 # `pkg_check_modules(GTK gtk+-3.0)` can find it.
918 flutter-desktop = pkgs.mkShell {
919 name = "frq-flutter-desktop";
920
921 # clojure and flutter are the APK shell's, and deliberately the
922 # same two: the Dart that runs here is generated by the same
923 # compiler from the same source, and a second Flutter version
924 # under it would be a second set of engine artifacts and a second
925 # answer to "does the phone build match the desktop one".
926 nativeBuildInputs = [
927 pkgs.clojure
928 pkgs.flutter
929 pkgs.just
930 pkgs.cmake
931 pkgs.ninja
932 pkgs.pkg-config
933 ];
934
935 # gtk3 is the runner's own dependency; the rest are url_launcher's
936 # Linux implementation, which is a GTK plugin compiled into the
937 # bundle. path_provider needs nothing here — its Linux half is
938 # pure Dart over the XDG directories.
939 buildInputs = [ pkgs.gtk3 pkgs.glib ];
940
941 # Same reason `just run` reaches for it: Flutter paints through
942 # GL, and off NixOS the driver that can do that is the host's, not
943 # the store's. The recipe reads this exactly as `run` does.
944 NIXGL = "${nixGLFor pkgs}/bin/nixGLIntel";
945
946 # The recipe's re-entry test, the way JOLT_NATIVE_LIB is the
947 # default shell's. Nothing else sets it, so `just flutter-desktop`
948 # outside the shell re-enters and lands back on the same recipe —
949 # no flag to forget, and no second code path for someone who runs
950 # `nix develop .#flutter-desktop --command just flutter-desktop`
951 # by hand.
952 FRQ_FLUTTER_DESKTOP = "1";
953 };
Run this tree on a native half the builders made a32699e nandi 17d ago954 });
955
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago956 apps = forEachSystem (pkgs: {
957 default = {
958 type = "app";
959 program = "${self.packages.${pkgs.stdenv.hostPlatform.system}.frq}/bin/frq";
960 };
Paint the same screens into a terminal ab83b42 nandi 17d ago961 tui = {
962 type = "app";
963 program = "${self.packages.${pkgs.stdenv.hostPlatform.system}.tui}/bin/frq-tui";
964 };
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago965 });
966 };
967}