nandi/frqpublic Fork 0
dcb50e077aee4cdf092d90a52641c82cfbe153d4
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 · 676 lines · 33.5 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 client with Nix, not just a shell for it ca3afbe nandi 19d ago467 });
468
Run this tree on a native half the builders made a32699e nandi 17d ago469 # Where `just run` runs, and — because entering it realises what it
470 # names — what builds the half of frq that is not this working tree.
471 #
472 # The two halves, and the split is the whole point of the shell. The frq
473 # source is the files on disk, uncommitted edits and all. Everything
474 # under it — jolt, glimmer, glimmer-vidya, both native objects — is the
475 # flake's, at the revs flake.lock names, so a run says what it ran
476 # against and both halves of glimmer-vidya move together. That is the
477 # drift the `jolt-native` input's comment is about, and a pin frq can
478 # answer for is worth more here than the convenience of a checkout.
479 #
Take the native objects from their own flake rather than rebuilding them 0ee8bba nandi 13d ago480 # `native` is jolt-native's own flake output. It was a buck2 graph when
481 # this comment was first written and a cargo build restated here when it
482 # was second: buck2 fetches its rustc, zig and every third-party crate as
483 # it goes and writes buck-out into the tree it builds, so a sandbox with
484 # no network and a read-only store was the one place it could not run.
485 # Upstream builds with nix now, so the thing its CI runs and the thing
486 # this shell hands a builder are the same derivation.
Run this tree on a native half the builders made a32699e nandi 17d ago487 #
488 # Nothing here says "nixbuild", though: it is a plain derivation, and
Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago489 # 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 ago490 # the shell with --max-jobs 0, which is what sends it to the `builders`
491 # entry rather than compiling egui on a laptop.
492 devShells = forEachSystem (pkgs:
493 let
494 inherit (pkgs) lib;
Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago495 inherit (self.packages.${pkgs.stdenv.hostPlatform.system}) jolt native nativeAll;
Run this tree on a native half the builders made a32699e nandi 17d ago496 in
497 {
498 default = pkgs.mkShellNoCC {
499 name = "frq";
500
501 # jolt, because the runtime frq is run by should be the flake's
502 # too. nixGL for the same reason the launcher reaches for it — see
Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago503 # frqScript. just so the recipe runner comes from here too rather
504 # than the host — `nix develop` and then `just run` is the whole of
505 # what a machine with nix needs.
506 packages = [ jolt pkgs.just (nixGLFor pkgs) ];
507
508 # 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 ago509 # source `just run` runs is the working tree, so the launcher has
Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago510 # to live in that tree and the shell has to hand it its answers.
511 # 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 ago512 JOLT_NATIVE_LIB = "${nativeAll}/lib";
Let the plane take real devices, not only test thunks 596dc29 nandi 9d ago513 # Spelled out rather than shared with the packages block, which
514 # is a different `let`. See `alsaPluginDir` there for why.
515 ALSA_PLUGIN_DIR = "${pkgs.pipewire}/lib/alsa-lib";
Run this tree on a native half the builders made a32699e nandi 17d ago516 GLIMMER_SRC = glimmer;
Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago517 GLIMMER_COSMIC_SRC = "${jolt-native}/glimmer-backends/glimmer-cosmic";
Take the Android objects from jolt-native's CI, always the latest 472e179 nandi 11d ago518 GLIMMER_TUI_SRC = "${jolt-native}/glimmer-backends/glimmer-tui";
Run this tree on a native half the builders made a32699e nandi 17d ago519 FRQ_LIB_PATH = lib.makeLibraryPath (runtimeLibsFor pkgs);
520 NIXGL = "${nixGLFor pkgs}/bin/nixGLIntel";
Take the jolt-native beside this one when there is one e10e1c1 nandi 9d ago521
522 # A checkout of jolt-native beside this one, in place of the pin.
523 #
524 # The pin is a rev on a server, so the loop for a change to the
525 # terminal backend was commit, push, re-pin, re-lock — four steps
526 # and an upload for a line of Rust. With a working copy beside this
527 # one the loop is `cargo build` and `just tui`, and the shell finds
528 # that copy itself: ../jolt-native from the checkout this was run
529 # in, which is where it is on the machines this is developed on.
530 # A worktree under .claude/worktrees counts as the same checkout —
531 # the sibling is the main one's, not the worktree's.
532 #
533 # Found rather than named, but not silently: it says which tree it
534 # took on the way in, because `just tui` running something other
535 # than the pin is the sort of thing you have to be able to see.
536 #
537 # It has to be a built one. A checkout with no target/release/
538 # libjolttui.so in it would mean the Jolt half of the backend from
539 # the working copy and the shared object from the pin — two halves
540 # of two different libraries, which fail in ways that look like
541 # neither. So an unbuilt sibling is left alone and the pin stands.
542 #
543 # FRQ_JOLT_NATIVE overrides the search, and is taken even unbuilt
544 # (with a word about what to run): naming a tree is asking for it.
545 # Empty is how you say the pin, on a machine that has a sibling and
546 # wants what everyone else is running.
547 #
548 # Only the sources and libjolttui move either way. Everything else
549 # on the library path — libopus, libmoq_ffi, the ALSA plugins —
550 # stays the pin's, since a checkout has no build of those to offer.
551 shellHook = ''
552 frq_named=1
553 if [ -z "''${FRQ_JOLT_NATIVE+named}" ]; then
554 frq_named=
555 frq_git="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null || true)"
556 frq_near="''${frq_git:+$(dirname "$(dirname "$frq_git")")/jolt-native}"
557 if [ -n "$frq_near" ] && [ -e "$frq_near/target/release/libjolttui.so" ]; then
558 FRQ_JOLT_NATIVE="$frq_near"
559 else
560 FRQ_JOLT_NATIVE=""
561 fi
562 fi
563 if [ -n "$FRQ_JOLT_NATIVE" ]; then
564 if [ -d "$FRQ_JOLT_NATIVE/crates/jolt-tui" ]; then
565 FRQ_JOLT_NATIVE="$(cd "$FRQ_JOLT_NATIVE" && pwd)"
566 export FRQ_JOLT_NATIVE
567 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 ago568 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 ago569 # First, so a cargo build wins over the pin's copy of the
570 # same object. The rest of the pin's lib directory is still
571 # behind it.
572 export JOLT_NATIVE_LIB="$FRQ_JOLT_NATIVE/target/release:$JOLT_NATIVE_LIB"
573 echo "frq: jolt-native from $FRQ_JOLT_NATIVE, not the pin (FRQ_JOLT_NATIVE= for the pin)" >&2
574 if [ ! -e "$FRQ_JOLT_NATIVE/target/release/libjolttui.so" ]; then
575 echo "frq: no libjolttui.so there yet cargo build --release --features terminal -p jolt-tui" >&2
576 fi
577 elif [ -n "$frq_named" ]; then
578 echo "frq: FRQ_JOLT_NATIVE=$FRQ_JOLT_NATIVE is not a jolt-native checkout; using the pin" >&2
579 fi
580 fi
581 unset frq_named frq_git frq_near
582 '';
Run this tree on a native half the builders made a32699e nandi 17d ago583 };
Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 7d ago584
585 # The APK toolchain, which the default shell deliberately does not
586 # carry: Flutter brings its own Dart, Gradle and a JDK's worth of
587 # closure, and a desktop build has no use for any of it.
588 #
589 # `just apk` used to name these as `nix shell nixpkgs#clojure
590 # nixpkgs#jdk17 nixpkgs#flutter`, which is the flake registry's
591 # nixpkgs and not this flake's — so the Flutter under the APK
592 # floated while everything else was locked. Same three packages,
593 # from flake.lock now.
594 #
595 # JDK 17 and not newer on purpose: the Flutter template's Gradle
596 # plugin pins a Gradle that rejects a JDK it was released before,
597 # and the failure reads as an unsupported class file version rather
598 # than as a version mismatch.
599 flutter = pkgs.mkShellNoCC {
600 name = "frq-flutter";
601 packages = [ pkgs.clojure pkgs.jdk17 pkgs.flutter pkgs.just ];
602
603 # Where the recipe copies from. Naming it here is also what makes
604 # entering the shell build it, so the first `just apk` does not
605 # stop for a few hundred megabytes of SDK with nothing said about
606 # why.
607 FRQ_ANDROID_SDK =
608 "${androidSdkFor pkgs.stdenv.hostPlatform.system}/libexec/android-sdk";
609 };
Paint the desktop with Flutter too, beside libcosmic fc5f63c nandi 7d ago610
611 # The other desktop GUI. Same ClojureDart half as the APK — one
612 # `clojure -M:cljd compile`, one flutter/src — over Flutter's Linux
613 # target instead of its Android one, so `flutter/linux/` is the
614 # runner and CMake and Ninja are the build rather than Gradle.
615 #
616 # A separate shell from `flutter` rather than one that carries both,
617 # because the halves are disjoint: this wants GTK and a C++ toolchain
618 # and no JDK, and the APK wants a JDK and an SDK and no GTK. Sharing
619 # them would mean every desktop build paying for a few hundred
620 # megabytes of Android SDK it never opens, which is the same argument
621 # that keeps Flutter out of the default shell.
622 #
623 # mkShell and not mkShellNoCC, unlike every other shell here: this is
624 # the one that actually compiles C++. stdenv brings the compiler, and
625 # gtk3 in buildInputs is what puts its .pc file where the runner's
626 # `pkg_check_modules(GTK gtk+-3.0)` can find it.
627 flutter-desktop = pkgs.mkShell {
628 name = "frq-flutter-desktop";
629
630 # clojure and flutter are the APK shell's, and deliberately the
631 # same two: the Dart that runs here is generated by the same
632 # compiler from the same source, and a second Flutter version
633 # under it would be a second set of engine artifacts and a second
634 # answer to "does the phone build match the desktop one".
635 nativeBuildInputs = [
636 pkgs.clojure
637 pkgs.flutter
638 pkgs.just
639 pkgs.cmake
640 pkgs.ninja
641 pkgs.pkg-config
642 ];
643
644 # gtk3 is the runner's own dependency; the rest are url_launcher's
645 # Linux implementation, which is a GTK plugin compiled into the
646 # bundle. path_provider needs nothing here — its Linux half is
647 # pure Dart over the XDG directories.
648 buildInputs = [ pkgs.gtk3 pkgs.glib ];
649
650 # Same reason `just run` reaches for it: Flutter paints through
651 # GL, and off NixOS the driver that can do that is the host's, not
652 # the store's. The recipe reads this exactly as `run` does.
653 NIXGL = "${nixGLFor pkgs}/bin/nixGLIntel";
654
655 # The recipe's re-entry test, the way JOLT_NATIVE_LIB is the
656 # default shell's. Nothing else sets it, so `just flutter-desktop`
657 # outside the shell re-enters and lands back on the same recipe —
658 # no flag to forget, and no second code path for someone who runs
659 # `nix develop .#flutter-desktop --command just flutter-desktop`
660 # by hand.
661 FRQ_FLUTTER_DESKTOP = "1";
662 };
Run this tree on a native half the builders made a32699e nandi 17d ago663 });
664
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago665 apps = forEachSystem (pkgs: {
666 default = {
667 type = "app";
668 program = "${self.packages.${pkgs.stdenv.hostPlatform.system}.frq}/bin/frq";
669 };
Paint the same screens into a terminal ab83b42 nandi 17d ago670 tui = {
671 type = "app";
672 program = "${self.packages.${pkgs.stdenv.hostPlatform.system}.tui}/bin/frq-tui";
673 };
Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago674 });
675 };
676}