| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 1 | { |
| 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 ago | 16 | # 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 ago | 20 | 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 12d ago | 24 | # `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 ago | 31 | # 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 ago | 35 | jolt-src = { |
| Take jolt and jolt-native as flakes, off my own fork aaa560d nandi 12d ago | 36 | 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 ago | 38 | }; |
| 39 | |
| Take the Android objects from jolt-native's CI, always the latest 472e179 nandi 10d ago | 40 | # 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 ago | 41 | # binds the native objects, and the flake that builds them. This input is |
| Name the libcosmic recipe for its backend: `just cosmic run` 5ba9382 nandi 6d ago | 42 | # what `just cosmic run` builds against. |
| Take the jolt-native ahead of the release, since a run can build it 36f6c77 nandi 16d ago | 43 | # |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 44 | # 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 8d ago | 47 | # |
| Pin jolt-native at the merge rather than at the branch 3d7c428 nandi 8d ago | 48 | # 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 16d ago | 49 | # 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 ago | 53 | # 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 ago | 58 | jolt-native = { |
| Take the jolt-native that opens a room where it means to f218f2a nandi 6d ago | 59 | url = "git+https://gitlab.com/nandithebull/jolt-native?rev=8e8cd5192dc161b423c0ee5dd41a7a058b24b409"; |
| Take jolt and jolt-native as flakes, off my own fork aaa560d nandi 12d ago | 60 | inputs.nixpkgs.follows = "nixpkgs"; |
| Paint the same screens into a terminal ab83b42 nandi 16d ago | 61 | }; |
| 62 | |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 63 | # 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 ago | 68 | |
| 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 17d ago | 74 | |
| 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 ago | 81 | }; |
| 82 | |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 83 | 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 ago | 84 | 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 16d ago | 88 | |
| 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 ago | 92 | # |
| 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 16d ago | 103 | |
| Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 6d ago | 104 | # 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 16d ago | 140 | # 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 ago | 142 | # put them on the loader path itself. Without libx11 here, vidya reports |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 143 | # "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 ago | 154 | libx11 |
| 155 | libxcursor |
| 156 | libxi |
| 157 | libxrandr |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 158 | vulkan-loader |
| 159 | ]; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 160 | 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 16d ago | 166 | nixGL = nixGLFor pkgs; |
| Find the host's GL driver when the store's is not the system's 633faad nandi 19d ago | 167 | |
| Take the native objects from their own flake rather than rebuilding them 0ee8bba nandi 12d ago | 168 | # 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 8d ago | 182 | # 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 8d ago | 186 | # |
| 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 ago | 200 | # 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 8d ago | 205 | }; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 206 | |
| Fetch libmoq_ffi again, and keep the codecs out of Rust f518938 nandi 8d ago | 207 | # 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 8d ago | 209 | # |
| Fetch libmoq_ffi again, and keep the codecs out of Rust f518938 nandi 8d ago | 210 | # 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 8d ago | 215 | # |
| Fetch libmoq_ffi again, and keep the codecs out of Rust f518938 nandi 8d ago | 216 | # 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 8d ago | 259 | |
| 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 8d ago | 265 | # 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 ago | 302 | # 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 8d ago | 306 | |
| Let the plane take real devices, not only test thunks 596dc29 nandi 8d ago | 307 | # 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 8d ago | 317 | nativeAll = pkgs.symlinkJoin { |
| 318 | name = "frq-native"; |
| Bind the C libraries a call actually needs 87e5be9 nandi 8d ago | 319 | paths = [ native moqFfi ] ++ codecs; |
| Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 8d ago | 320 | }; |
| 321 | |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 322 | # 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 ago | 323 | # |
| 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 ago | 328 | joltFrom = src: pkgs.stdenv.mkDerivation { |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 329 | pname = "jolt"; |
| 330 | version = "dev"; |
| Build the APK from the flake, and from nothing 6aa2a6b nandi 18d ago | 331 | inherit src; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 332 | |
| 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 ago | 354 | # 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 17d ago | 358 | # |
| 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 ago | 364 | postFixup = '' |
| 365 | wrapProgram "$out/bin/jolt" \ |
| Stop carrying the 32-bit GL stack and half of git 040f2c1 nandi 16d ago | 366 | --prefix PATH : "${pkgs.lib.makeBinPath [ pkgs.gitMinimal pkgs.unzip ]}" \ |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 367 | --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 17d ago | 368 | --set-default TZDIR "${pkgs.tzdata}/share/zoneinfo" \ |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 369 | --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 ago | 373 | joltRuntime = joltFrom jolt-src; |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 374 | |
| 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 10d ago | 379 | glimmerTui = "${jolt-native}/glimmer-backends/glimmer-tui"; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 380 | |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 381 | runtimeLibs = runtimeLibsFor pkgs; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 382 | |
| 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 ago | 386 | cp -r ${self}/common ${self}/src ${self}/deps.edn "$out/" |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 387 | ''; |
| 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 8d ago | 394 | 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 8d ago | 395 | export ALSA_PLUGIN_DIR="${alsaPluginDir}" |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 396 | cd ${frqSource} |
| Find the host's GL driver when the store's is not the system's 633faad nandi 19d ago | 397 | |
| 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 ago | 405 | -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 ago | 407 | ''; |
| 408 | |
| Paint the same screens into a terminal ab83b42 nandi 16d ago | 409 | # 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 8d ago | 413 | export LD_LIBRARY_PATH="${nativeAll}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" |
| Let the plane take real devices, not only test thunks 596dc29 nandi 8d ago | 414 | export ALSA_PLUGIN_DIR="${alsaPluginDir}" |
| Paint the same screens into a terminal ab83b42 nandi 16d ago | 415 | cd ${frqSource} |
| 416 | |
| 417 | exec ${joltRuntime}/bin/jolt \ |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 418 | -Sdeps '{:deps {jolt-lang/glimmer {:local/root "${glimmer}"} nandi/glimmer-tui {:local/root "${glimmerTui}"}}}' \ |
| Paint the same screens into a terminal ab83b42 nandi 16d ago | 419 | -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 ago | 435 | 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 8d ago | 449 | inherit native moqFfi frqH264 nativeAll frq; |
| Let the plane take real devices, not only test thunks 596dc29 nandi 8d ago | 450 | inherit (pkgs) pipewire; |
| Merge origin/main, and let one jolt-native answer for both backends 1e8b590 nandi 16d ago | 451 | inherit tui; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 452 | jolt = joltRuntime; |
| 453 | default = frq; |
| Bundle the closure into one file the AppImage runtime mounts f82b93f nandi 17d ago | 454 | |
| Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 6d ago | 455 | # 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 17d ago | 461 | # 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 6d ago | 467 | |
| 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 | |
| Make ../common a dependency rather than a path 95d91a2 nandi 6d ago | 524 | # The stub: our dependency files, nothing of our source. |
| 525 | # ../common is a :local/root dependency now, so it has to exist |
| 526 | # *and* carry a deps.edn for tools.deps to resolve — an empty |
| 527 | # directory with that one file in it is enough. |
| Build the Flutter desktop GUI with nix, sandbox and all 6ca9b5a nandi 6d ago | 528 | proj="$NIX_BUILD_TOP/stub" |
| 529 | mkdir -p "$proj/src/stub" "$NIX_BUILD_TOP/common" |
| Make ../common a dependency rather than a path 95d91a2 nandi 6d ago | 530 | cp ${./common/deps.edn} "$NIX_BUILD_TOP/common/deps.edn" |
| Build the Flutter desktop GUI with nix, sandbox and all 6ca9b5a nandi 6d ago | 531 | cp ${./flutter/deps.edn} "$proj/deps.edn" |
| 532 | cp ${./flutter/pubspec.yaml} "$proj/pubspec.yaml" |
| 533 | chmod u+w "$proj/deps.edn" "$proj/pubspec.yaml" |
| 534 | cat > "$proj/src/stub/main.cljd" <<'EOF' |
| 535 | (ns stub.main) |
| 536 | (defn main [] nil) |
| 537 | EOF |
| 538 | |
| 539 | cd "$proj" |
| 540 | # `:main` has to name the stub, or the compiler goes looking for |
| 541 | # frq.main in a tree that is not here. |
| 542 | sed -i 's/:main frq\.main/:main stub.main/' deps.edn |
| 543 | |
| 544 | flutter config --no-analytics &>/dev/null || true |
| 545 | flutter config --enable-linux-desktop >/dev/null || true |
| 546 | |
| 547 | clojure -Sdeps '{:mvn/local-repo "'"$cache"'/m2"}' -M:cljd compile |
| 548 | |
| 549 | # What the compile left behind, and only that. The analyzer |
| 550 | # project is keyed by the ClojureDart sha, so the directory |
| 551 | # under cache/ is copied wholesale rather than named here. |
| 552 | mkdir -p "$out/clojuredart" |
| 553 | cp -r .clojuredart/cache "$out/clojuredart/cache" |
| 554 | cp -r "$cache/m2" "$out/m2" |
| 555 | cp -r "$cache/gitlibs" "$out/gitlibs" |
| 556 | cp -r "$PUB_CACHE" "$out/pub-cache" |
| 557 | |
| 558 | # A fixed-output derivation may not reference a store path, and |
| 559 | # a resolved pub project is nothing but store paths: |
| 560 | # package_config.json names the Flutter SDK and every package |
| 561 | # in the cache by absolute path. So the analyzer project ships |
| 562 | # *unresolved* — its pubspec and its analyzer.dart and nothing |
| 563 | # else — and `flutter pub get --offline` re-resolves it against |
| 564 | # this cache at build time, where naming the store is allowed. |
| 565 | find "$out" \( -name '.dart_tool' -o -name '.flutter-plugins' \ |
| 566 | -o -name '.flutter-plugins-dependencies' \) -prune -exec rm -rf {} + |
| 567 | find "$out" -name '.packages' -delete |
| 568 | |
| 569 | |
| 570 | # A fixed-output hash is a promise that two runs agree, so |
| 571 | # everything a tool writes *about* a run rather than about a |
| 572 | # dependency has to go: pub's log carries timestamps, Maven |
| 573 | # rewrites its resolution metadata on every resolve, and |
| 574 | # tools.gitlibs keeps bare clones it only needs in order to |
| 575 | # make a checkout. None of it is read offline. |
| 576 | rm -rf "$out/pub-cache/log" "$out/pub-cache/_temp" \ |
| 577 | "$out/pub-cache/git" "$out/pub-cache/global_packages" \ |
| 578 | "$out/pub-cache/bin" |
| 579 | |
| 580 | # tools.gitlibs keeps a bare clone per URL under _repos/, and a |
| 581 | # bare clone is packfiles — which two runs of the same fetch do |
| 582 | # not have to produce byte for byte. It cannot simply be |
| 583 | # deleted, because `procure` calls `ensure-git-dir` before it |
| 584 | # looks at anything else and would clone it again, over a |
| 585 | # network this has and the build that uses it does not. |
| 586 | # |
| 587 | # It does not need the objects, though. `procure` finds the sha |
| 588 | # with `match-exact` against the checkout already in libs/, so |
| 589 | # the bare repo only has to exist. Emptied and re-initialised, |
| 590 | # it is a fixed handful of files from the pinned git and the |
| 591 | # same on every run. |
| 592 | find "$out/gitlibs/_repos" -name HEAD | while read -r head; do |
| 593 | repo="$(dirname "$head")" |
| 594 | rm -rf "$repo" |
| 595 | git init --bare -q "$repo" |
| 596 | # The sample hooks are shell scripts, so they carry a |
| 597 | # `#!/nix/store/.../bash` line — which is exactly the kind of |
| 598 | # store reference a fixed-output derivation may not hold. An |
| 599 | # empty bare repo nothing ever runs has no use for them. |
| 600 | rm -rf "$repo/hooks" |
| 601 | done |
| 602 | # pub's version listings, which record when they were fetched. |
| 603 | # This is the one that actually moved between two runs of this |
| 604 | # derivation: the package sources under hosted/ were identical |
| 605 | # and the listings beside them were not. Nothing offline reads |
| 606 | # them — a resolution that already has every package on disk |
| 607 | # never asks pub.dev what versions exist. |
| 608 | find "$out/pub-cache" -name '.cache' -type d -prune -exec rm -rf {} + |
| 609 | find "$out/m2" \( -name '*.lastUpdated' -o -name '_remote.repositories' \ |
| 610 | -o -name 'resolver-status.properties' -o -name '*.part' \ |
| 611 | -o -name 'maven-metadata-*.xml*' \) -delete |
| 612 | find "$out" \( -name '.DS_Store' -o -name '*.log' -o -name '.git' \) \ |
| 613 | -prune -exec rm -rf {} + |
| 614 | find "$out" -type d -empty -delete |
| 615 | chmod -R u+w "$out" |
| 616 | |
| 617 | # Last, after every cleanup above: anything still naming the |
| 618 | # store fails the fixed-output check, and the error names one |
| 619 | # path out of thousands of files. This names the files. |
| 620 | if refs="$(grep -rlI /nix/store "$out" 2>/dev/null)" && [ -n "$refs" ]; then |
| 621 | echo "cljd-deps: these still reference the store:" >&2 |
| 622 | echo "$refs" | head -20 >&2 |
| 623 | fi |
| 624 | |
| 625 | # If two runs disagree, this says which half to look in. Cheap, |
| 626 | # and the alternative is a hash mismatch with nothing attached. |
| 627 | for d in "$out"/*; do |
| 628 | echo "cljd-deps subtree $(basename "$d") $( (cd "$d" && find . -type f \ |
| 629 | -exec sha256sum {} + | sort -k2 | sha256sum) )" >&2 |
| 630 | done |
| 631 | for d in "$out"/pub-cache/*/*; do |
| 632 | [ -d "$d" ] || continue |
| 633 | echo "cljd-deps pub $(basename "$d") $( (cd "$d" && find . -type f \ |
| 634 | -exec sha256sum {} + | sort -k2 | sha256sum) )" >&2 |
| 635 | done |
| 636 | ''; |
| 637 | |
| 638 | outputHashMode = "recursive"; |
| 639 | outputHashAlgo = "sha256"; |
| 640 | # Moves when flutter/deps.edn or flutter/pubspec.yaml move, and |
| 641 | # not when frq's own source does — see the stub above. |
| 642 | outputHash = "sha256-gfJGlKCPaJsKcXfCWOJY1089XEfzTndEx0LVf3JOXfs="; |
| 643 | }; |
| 644 | |
| 645 | # The Flutter desktop GUI, built rather than run out of the tree. |
| 646 | # |
| 647 | # `just flutter-desktop` is the working-tree loop and this is its |
| Name the libcosmic recipe for its backend: `just cosmic run` 5ba9382 nandi 6d ago | 648 | # opposite number, the same way `nix build .#frq` is `just cosmic |
| 649 | # run`'s: the source is the flake's, the output is a store path, and the build is |
| Build the Flutter desktop GUI with nix, sandbox and all 6ca9b5a nandi 6d ago | 650 | # a sandbox with no network. It is the first thing here that builds |
| 651 | # purely — the APK cannot, because Gradle fetches as it goes. |
| 652 | # |
| 653 | # Two stages, because the Dart does not exist until ClojureDart writes |
| 654 | # it. `preBuild` runs the compiler over `flutter/src` and `common/` |
| 655 | # with `--offline`, out of the caches `cljd-deps` fetched; everything |
| 656 | # after that is an ordinary Flutter application as far as nixpkgs is |
| 657 | # concerned. |
| 658 | # |
| 659 | # The caches are copied in rather than used where they lie. Maven, |
| 660 | # tools.gitlibs and pub all expect to be able to write to their own |
| 661 | # cache — a lock file, a resolved marker — and the store is read-only, |
| 662 | # so pointing them at $out of a fixed-output derivation fails in three |
| 663 | # different ways at three different depths. |
| 664 | # |
| 665 | # `src` is the whole tree and not `flutter/`: `flutter/deps.edn` puts |
| 666 | # `../common` on the classpath, which is the entire point of that |
| 667 | # directory, and a source root of `flutter/` would leave the screens |
| 668 | # outside it. |
| 669 | flutter-desktop-unwrapped = pkgs.flutter.buildFlutterApplication rec { |
| 670 | pname = "frq-flutter"; |
| 671 | version = "0.1.0"; |
| 672 | |
| 673 | src = lib.cleanSourceWith { |
| 674 | src = ./.; |
| 675 | # Build trees and caches, which are large, machine-specific and |
| 676 | # would make every one of them a new store path. |
| 677 | filter = path: type: |
| 678 | let base = baseNameOf path; in |
| 679 | !(builtins.elem base [ |
| 680 | "build" ".home" ".clojuredart" ".cpcache" "cljd-out" |
| 681 | ".dart_tool" "result" ".git" ".jolt" "buck-out" |
| 682 | ]); |
| 683 | }; |
| 684 | sourceRoot = "source/flutter"; |
| 685 | |
| 686 | # Read at eval time, so the lock in git is the lock that is built. |
| 687 | autoPubspecLock = ./flutter/pubspec.lock; |
| 688 | |
| 689 | # git, because tools.deps resolves the ClojureDart dependency through |
| 690 | # tools.gitlibs even when every byte of it is already on disk — see |
| 691 | # the _repos note in cljd-deps. |
| 692 | nativeBuildInputs = [ pkgs.clojure pkgs.jdk17 pkgs.git ]; |
| 693 | |
| 694 | preBuild = '' |
| 695 | export PUB_CACHE="$NIX_BUILD_TOP/pub-cache" |
| 696 | export GITLIBS="$NIX_BUILD_TOP/gitlibs" |
| 697 | cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/pub-cache "$PUB_CACHE" |
| 698 | cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/gitlibs "$GITLIBS" |
| 699 | cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/m2 "$NIX_BUILD_TOP/m2" |
| 700 | mkdir -p .clojuredart |
| 701 | cp -r ${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}/clojuredart/cache .clojuredart/cache |
| 702 | chmod -R u+w "$PUB_CACHE" "$GITLIBS" "$NIX_BUILD_TOP/m2" .clojuredart |
| 703 | |
| 704 | # Resolve the analyzer project here rather than in cljd-deps, |
| 705 | # which was not allowed to name the store. Offline, out of the |
| 706 | # cache that derivation did fetch. ClojureDart only reaches for |
| 707 | # the network when `bin/analyzer.dart` is missing, and it is not. |
| 708 | for helper in .clojuredart/cache/*/cljd_helper; do |
| 709 | ( cd "$helper" && flutter pub get --offline ) |
| 710 | done |
| 711 | |
| 712 | # --offline is what keeps `pub get` out of a sandbox that has no |
| 713 | # network; the analyzer project it would otherwise resolve is |
| 714 | # already in .clojuredart, put there by cljd-deps. |
| 715 | clojure -Sdeps "{:mvn/local-repo \"$NIX_BUILD_TOP/m2\"}" \ |
| 716 | -M:cljd compile --offline |
| 717 | ''; |
| 718 | |
| 719 | meta = { |
| 720 | description = "frq's screens on Flutter's Linux target (no GL launcher)"; |
| 721 | mainProgram = "frq"; |
| 722 | platforms = systems; |
| 723 | }; |
| 724 | }; |
| 725 | |
| 726 | # The same shape as `frq` above: a launcher, and a package that is a |
| 727 | # symlink to it. The reason is the same one `frqScript` gives — on |
| 728 | # NixOS the store's Mesa is the system's and the window opens, and |
| 729 | # anywhere else the real driver is the host's, so the process is |
| 730 | # handed to nixGL. Without it the store build dies on a distrobox |
| 731 | # Arch with "No provider of eglGetPlatformDisplayEXT found", which is |
| 732 | # that failure wearing an EGL hat. |
| 733 | # |
| 734 | # A wrapper *around* the built application rather than a `postFixup` |
| 735 | # inside it, because buildFlutterApplication's own dartFixupHook runs |
| 736 | # after postFixup and rewrites `bin/frq` — so anything done to that |
| 737 | # path from inside is undone on the way out. |
| 738 | flutter-desktop = |
| 739 | let |
| 740 | unwrapped = |
| 741 | self.packages.${pkgs.stdenv.hostPlatform.system}.flutter-desktop-unwrapped; |
| 742 | script = pkgs.writeShellScript "frq" '' |
| 743 | runner="" |
| 744 | [ -e /run/current-system ] || runner="${nixGLFor pkgs}/bin/nixGLIntel" |
| 745 | exec ''${runner} ${unwrapped}/bin/frq "$@" |
| 746 | ''; |
| 747 | in |
| 748 | pkgs.runCommand "frq-flutter-0.1.0" |
| 749 | { |
| 750 | meta = { |
| 751 | description = "frq's screens on Flutter's Linux target"; |
| 752 | mainProgram = "frq"; |
| 753 | platforms = systems; |
| 754 | }; |
| 755 | } |
| 756 | '' |
| 757 | mkdir -p "$out/bin" |
| 758 | ln -s ${script} "$out/bin/frq" |
| 759 | ''; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 760 | }); |
| 761 | |
| Name the libcosmic recipe for its backend: `just cosmic run` 5ba9382 nandi 6d ago | 762 | # Where `just cosmic run` runs, and — because entering it realises what it |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 763 | # names — what builds the half of frq that is not this working tree. |
| 764 | # |
| 765 | # The two halves, and the split is the whole point of the shell. The frq |
| 766 | # source is the files on disk, uncommitted edits and all. Everything |
| 767 | # under it — jolt, glimmer, glimmer-vidya, both native objects — is the |
| 768 | # flake's, at the revs flake.lock names, so a run says what it ran |
| 769 | # against and both halves of glimmer-vidya move together. That is the |
| 770 | # drift the `jolt-native` input's comment is about, and a pin frq can |
| 771 | # answer for is worth more here than the convenience of a checkout. |
| 772 | # |
| Take the native objects from their own flake rather than rebuilding them 0ee8bba nandi 12d ago | 773 | # `native` is jolt-native's own flake output. It was a buck2 graph when |
| 774 | # this comment was first written and a cargo build restated here when it |
| 775 | # was second: buck2 fetches its rustc, zig and every third-party crate as |
| 776 | # it goes and writes buck-out into the tree it builds, so a sandbox with |
| 777 | # no network and a read-only store was the one place it could not run. |
| 778 | # Upstream builds with nix now, so the thing its CI runs and the thing |
| 779 | # this shell hands a builder are the same derivation. |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 780 | # |
| 781 | # Nothing here says "nixbuild", though: it is a plain derivation, and |
| Name the libcosmic recipe for its backend: `just cosmic run` 5ba9382 nandi 6d ago | 782 | # where it gets built is the machine's business. The `cosmic` recipe asks for |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 783 | # the shell with --max-jobs 0, which is what sends it to the `builders` |
| 784 | # entry rather than compiling egui on a laptop. |
| 785 | devShells = forEachSystem (pkgs: |
| 786 | let |
| 787 | inherit (pkgs) lib; |
| Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 8d ago | 788 | inherit (self.packages.${pkgs.stdenv.hostPlatform.system}) jolt native nativeAll; |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 789 | in |
| 790 | { |
| 791 | default = pkgs.mkShellNoCC { |
| 792 | name = "frq"; |
| 793 | |
| 794 | # jolt, because the runtime frq is run by should be the flake's |
| 795 | # too. nixGL for the same reason the launcher reaches for it — see |
| Inline the babashka scripts into the justfile 76dcc6c nandi 10d ago | 796 | # frqScript. just so the recipe runner comes from here too rather |
| Name the libcosmic recipe for its backend: `just cosmic run` 5ba9382 nandi 6d ago | 797 | # than the host — `nix develop` and then `just cosmic run` is the |
| 798 | # whole of what a machine with nix needs. |
| Inline the babashka scripts into the justfile 76dcc6c nandi 10d ago | 799 | packages = [ jolt pkgs.just (nixGLFor pkgs) ]; |
| 800 | |
| 801 | # Read by the recipes rather than baked into a wrapper: the frq |
| Name the libcosmic recipe for its backend: `just cosmic run` 5ba9382 nandi 6d ago | 802 | # source `just cosmic run` runs is the working tree, so the |
| 803 | # launcher has to live in that tree and the shell has to hand it its answers. |
| Inline the babashka scripts into the justfile 76dcc6c nandi 10d ago | 804 | # 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 8d ago | 805 | JOLT_NATIVE_LIB = "${nativeAll}/lib"; |
| Let the plane take real devices, not only test thunks 596dc29 nandi 8d ago | 806 | # Spelled out rather than shared with the packages block, which |
| 807 | # is a different `let`. See `alsaPluginDir` there for why. |
| 808 | ALSA_PLUGIN_DIR = "${pkgs.pipewire}/lib/alsa-lib"; |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 809 | GLIMMER_SRC = glimmer; |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 810 | GLIMMER_COSMIC_SRC = "${jolt-native}/glimmer-backends/glimmer-cosmic"; |
| Take the Android objects from jolt-native's CI, always the latest 472e179 nandi 10d ago | 811 | GLIMMER_TUI_SRC = "${jolt-native}/glimmer-backends/glimmer-tui"; |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 812 | FRQ_LIB_PATH = lib.makeLibraryPath (runtimeLibsFor pkgs); |
| 813 | NIXGL = "${nixGLFor pkgs}/bin/nixGLIntel"; |
| Take the jolt-native beside this one when there is one e10e1c1 nandi 8d ago | 814 | |
| 815 | # A checkout of jolt-native beside this one, in place of the pin. |
| 816 | # |
| 817 | # The pin is a rev on a server, so the loop for a change to the |
| 818 | # terminal backend was commit, push, re-pin, re-lock — four steps |
| 819 | # and an upload for a line of Rust. With a working copy beside this |
| 820 | # one the loop is `cargo build` and `just tui`, and the shell finds |
| 821 | # that copy itself: ../jolt-native from the checkout this was run |
| 822 | # in, which is where it is on the machines this is developed on. |
| 823 | # A worktree under .claude/worktrees counts as the same checkout — |
| 824 | # the sibling is the main one's, not the worktree's. |
| 825 | # |
| 826 | # Found rather than named, but not silently: it says which tree it |
| 827 | # took on the way in, because `just tui` running something other |
| 828 | # than the pin is the sort of thing you have to be able to see. |
| 829 | # |
| 830 | # It has to be a built one. A checkout with no target/release/ |
| 831 | # libjolttui.so in it would mean the Jolt half of the backend from |
| 832 | # the working copy and the shared object from the pin — two halves |
| 833 | # of two different libraries, which fail in ways that look like |
| 834 | # neither. So an unbuilt sibling is left alone and the pin stands. |
| 835 | # |
| 836 | # FRQ_JOLT_NATIVE overrides the search, and is taken even unbuilt |
| 837 | # (with a word about what to run): naming a tree is asking for it. |
| 838 | # Empty is how you say the pin, on a machine that has a sibling and |
| 839 | # wants what everyone else is running. |
| 840 | # |
| 841 | # Only the sources and libjolttui move either way. Everything else |
| 842 | # on the library path — libopus, libmoq_ffi, the ALSA plugins — |
| 843 | # stays the pin's, since a checkout has no build of those to offer. |
| 844 | shellHook = '' |
| 845 | frq_named=1 |
| 846 | if [ -z "''${FRQ_JOLT_NATIVE+named}" ]; then |
| 847 | frq_named= |
| 848 | frq_git="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null || true)" |
| 849 | frq_near="''${frq_git:+$(dirname "$(dirname "$frq_git")")/jolt-native}" |
| 850 | if [ -n "$frq_near" ] && [ -e "$frq_near/target/release/libjolttui.so" ]; then |
| 851 | FRQ_JOLT_NATIVE="$frq_near" |
| 852 | else |
| 853 | FRQ_JOLT_NATIVE="" |
| 854 | fi |
| 855 | fi |
| 856 | if [ -n "$FRQ_JOLT_NATIVE" ]; then |
| 857 | if [ -d "$FRQ_JOLT_NATIVE/crates/jolt-tui" ]; then |
| 858 | FRQ_JOLT_NATIVE="$(cd "$FRQ_JOLT_NATIVE" && pwd)" |
| 859 | export FRQ_JOLT_NATIVE |
| 860 | 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 ago | 861 | export GLIMMER_COSMIC_SRC="$FRQ_JOLT_NATIVE/glimmer-backends/glimmer-cosmic" |
| Take the jolt-native beside this one when there is one e10e1c1 nandi 8d ago | 862 | # First, so a cargo build wins over the pin's copy of the |
| 863 | # same object. The rest of the pin's lib directory is still |
| 864 | # behind it. |
| 865 | export JOLT_NATIVE_LIB="$FRQ_JOLT_NATIVE/target/release:$JOLT_NATIVE_LIB" |
| 866 | echo "frq: jolt-native from $FRQ_JOLT_NATIVE, not the pin (FRQ_JOLT_NATIVE= for the pin)" >&2 |
| 867 | if [ ! -e "$FRQ_JOLT_NATIVE/target/release/libjolttui.so" ]; then |
| 868 | echo "frq: no libjolttui.so there yet — cargo build --release --features terminal -p jolt-tui" >&2 |
| 869 | fi |
| 870 | elif [ -n "$frq_named" ]; then |
| 871 | echo "frq: FRQ_JOLT_NATIVE=$FRQ_JOLT_NATIVE is not a jolt-native checkout; using the pin" >&2 |
| 872 | fi |
| 873 | fi |
| 874 | unset frq_named frq_git frq_near |
| 875 | ''; |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 876 | }; |
| Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 6d ago | 877 | |
| 878 | # The APK toolchain, which the default shell deliberately does not |
| 879 | # carry: Flutter brings its own Dart, Gradle and a JDK's worth of |
| 880 | # closure, and a desktop build has no use for any of it. |
| 881 | # |
| 882 | # `just apk` used to name these as `nix shell nixpkgs#clojure |
| 883 | # nixpkgs#jdk17 nixpkgs#flutter`, which is the flake registry's |
| 884 | # nixpkgs and not this flake's — so the Flutter under the APK |
| 885 | # floated while everything else was locked. Same three packages, |
| 886 | # from flake.lock now. |
| 887 | # |
| 888 | # JDK 17 and not newer on purpose: the Flutter template's Gradle |
| 889 | # plugin pins a Gradle that rejects a JDK it was released before, |
| 890 | # and the failure reads as an unsupported class file version rather |
| 891 | # than as a version mismatch. |
| 892 | flutter = pkgs.mkShellNoCC { |
| 893 | name = "frq-flutter"; |
| Seed the ClojureDart caches out of the flake f2e12af nandi 6d ago | 894 | |
| 895 | # git, because tools.deps resolves the ClojureDart dependency |
| 896 | # through tools.gitlibs even when every byte of it is already in |
| 897 | # the seeded cache — the same reason flutter-desktop-unwrapped |
| 898 | # names it. The host's git has always been there to answer; naming |
| 899 | # it means the shell does not depend on that. |
| 900 | packages = [ pkgs.clojure pkgs.jdk17 pkgs.flutter pkgs.just pkgs.git ]; |
| Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 6d ago | 901 | |
| 902 | # Where the recipe copies from. Naming it here is also what makes |
| 903 | # entering the shell build it, so the first `just apk` does not |
| 904 | # stop for a few hundred megabytes of SDK with nothing said about |
| 905 | # why. |
| 906 | FRQ_ANDROID_SDK = |
| 907 | "${androidSdkFor pkgs.stdenv.hostPlatform.system}/libexec/android-sdk"; |
| Seed the ClojureDart caches out of the flake f2e12af nandi 6d ago | 908 | |
| 909 | # The Maven, gitlibs and pub caches the ClojureDart compile would |
| 910 | # otherwise fetch, plus the analyzer project it writes under |
| 911 | # .clojuredart. Here for both of FRQ_ANDROID_SDK's reasons: it is |
| 912 | # where the recipe copies from, and naming it is what makes |
| 913 | # entering the shell build it. |
| 914 | # |
| 915 | # The compile still runs online. These are a warm start and not a |
| 916 | # pin — `--offline` would be, and would turn adding a line to |
| 917 | # flutter/deps.edn into a re-hash of cljd-deps before anything |
| 918 | # compiled again. The sandbox build takes that trade because it |
| 919 | # has no network; the loop someone edits in should not. |
| 920 | FRQ_CLJD_DEPS = "${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}"; |
| Build the APK from the flake, at the rev flake.lock pins 77d4bec nandi 6d ago | 921 | }; |
| Paint the desktop with Flutter too, beside libcosmic fc5f63c nandi 6d ago | 922 | |
| 923 | # The other desktop GUI. Same ClojureDart half as the APK — one |
| 924 | # `clojure -M:cljd compile`, one flutter/src — over Flutter's Linux |
| 925 | # target instead of its Android one, so `flutter/linux/` is the |
| 926 | # runner and CMake and Ninja are the build rather than Gradle. |
| 927 | # |
| 928 | # A separate shell from `flutter` rather than one that carries both, |
| 929 | # because the halves are disjoint: this wants GTK and a C++ toolchain |
| 930 | # and no JDK, and the APK wants a JDK and an SDK and no GTK. Sharing |
| 931 | # them would mean every desktop build paying for a few hundred |
| 932 | # megabytes of Android SDK it never opens, which is the same argument |
| 933 | # that keeps Flutter out of the default shell. |
| 934 | # |
| 935 | # mkShell and not mkShellNoCC, unlike every other shell here: this is |
| 936 | # the one that actually compiles C++. stdenv brings the compiler, and |
| 937 | # gtk3 in buildInputs is what puts its .pc file where the runner's |
| 938 | # `pkg_check_modules(GTK gtk+-3.0)` can find it. |
| 939 | flutter-desktop = pkgs.mkShell { |
| 940 | name = "frq-flutter-desktop"; |
| 941 | |
| 942 | # clojure and flutter are the APK shell's, and deliberately the |
| 943 | # same two: the Dart that runs here is generated by the same |
| 944 | # compiler from the same source, and a second Flutter version |
| 945 | # under it would be a second set of engine artifacts and a second |
| 946 | # answer to "does the phone build match the desktop one". |
| 947 | nativeBuildInputs = [ |
| 948 | pkgs.clojure |
| 949 | pkgs.flutter |
| 950 | pkgs.just |
| 951 | pkgs.cmake |
| 952 | pkgs.ninja |
| 953 | pkgs.pkg-config |
| 954 | ]; |
| 955 | |
| 956 | # gtk3 is the runner's own dependency; the rest are url_launcher's |
| 957 | # Linux implementation, which is a GTK plugin compiled into the |
| 958 | # bundle. path_provider needs nothing here — its Linux half is |
| 959 | # pure Dart over the XDG directories. |
| 960 | buildInputs = [ pkgs.gtk3 pkgs.glib ]; |
| 961 | |
| Name the libcosmic recipe for its backend: `just cosmic run` 5ba9382 nandi 6d ago | 962 | # Same reason `just cosmic run` reaches for it: Flutter paints |
| 963 | # through GL, and off NixOS the driver that can do that is the |
| 964 | # host's, not the store's. The recipe reads this exactly as |
| 965 | # `cosmic` does. |
| Paint the desktop with Flutter too, beside libcosmic fc5f63c nandi 6d ago | 966 | NIXGL = "${nixGLFor pkgs}/bin/nixGLIntel"; |
| 967 | |
| Seed the ClojureDart caches out of the flake f2e12af nandi 6d ago | 968 | # The `flutter` shell's, deliberately the same one and for the |
| 969 | # same reason clojure and flutter are: the ClojureDart half of |
| 970 | # both builds is one compile over one deps.edn, so a second set of |
| 971 | # caches would be a second answer to what it resolved against. |
| 972 | # This recipe reads the variable directly — it is inside this |
| 973 | # shell before it does any of the work — where `just apk` reaches |
| 974 | # for the flake output itself. |
| 975 | FRQ_CLJD_DEPS = "${self.packages.${pkgs.stdenv.hostPlatform.system}.cljd-deps}"; |
| 976 | |
| Paint the desktop with Flutter too, beside libcosmic fc5f63c nandi 6d ago | 977 | # The recipe's re-entry test, the way JOLT_NATIVE_LIB is the |
| 978 | # default shell's. Nothing else sets it, so `just flutter-desktop` |
| 979 | # outside the shell re-enters and lands back on the same recipe — |
| 980 | # no flag to forget, and no second code path for someone who runs |
| 981 | # `nix develop .#flutter-desktop --command just flutter-desktop` |
| 982 | # by hand. |
| 983 | FRQ_FLUTTER_DESKTOP = "1"; |
| 984 | }; |
| Run this tree on a native half the builders made a32699e nandi 16d ago | 985 | }); |
| 986 | |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 987 | apps = forEachSystem (pkgs: { |
| 988 | default = { |
| 989 | type = "app"; |
| 990 | program = "${self.packages.${pkgs.stdenv.hostPlatform.system}.frq}/bin/frq"; |
| 991 | }; |
| Paint the same screens into a terminal ab83b42 nandi 16d ago | 992 | tui = { |
| 993 | type = "app"; |
| 994 | program = "${self.packages.${pkgs.stdenv.hostPlatform.system}.tui}/bin/frq-tui"; |
| 995 | }; |
| Build the client with Nix, not just a shell for it ca3afbe nandi 19d ago | 996 | }); |
| 997 | }; |
| 998 | } |