{ lib, stdenv, fetchurl, autoPatchelfHook, versionCheckHook, }: let version = "0.75.5"; # jcode is a large Rust workspace, but every release ships prebuilt binaries, # so we install those rather than paying for a full cargo build. Hashes were # cross-checked against the release's own SHA256SUMS. # # The Linux tarballs contain two files: the ELF (.bin) plus a launcher # shell script that only exists to put its own directory on LD_LIBRARY_PATH. # Nothing ships alongside the ELF, and autoPatchelfHook writes a real RPATH, # so the launcher is dropped and the ELF installed directly. The macOS # tarballs ship the bare binary with no launcher and no .bin suffix. sources = { x86_64-linux = { asset = "jcode-linux-x86_64"; binary = "jcode-linux-x86_64.bin"; hash = "sha256-HDrk3JsObqqYI4NZxEEQ49w0fJbXNpOag5NH6VqRRZ4="; }; aarch64-linux = { asset = "jcode-linux-aarch64"; binary = "jcode-linux-aarch64.bin"; hash = "sha256-xmE8Qed02pK1Lb+wrRNmKrBm7JlIaAXK0Dd1Z+XlhxI="; }; x86_64-darwin = { asset = "jcode-macos-x86_64"; binary = "jcode-macos-x86_64"; hash = "sha256-jsJwLlevJvmDbkrZnPRX5ryyDA9mmo9qsigN9t8qb/k="; }; aarch64-darwin = { asset = "jcode-macos-aarch64"; binary = "jcode-macos-aarch64"; hash = "sha256-1v7sL5Tt8Dq6ybZTJh30+4DfpRAG2P1V0/mo+mLvzfI="; }; }; source = sources.${stdenv.hostPlatform.system} or (throw "nix-bin/jcode.nix: no prebuilt jcode release for ${stdenv.hostPlatform.system}"); in stdenv.mkDerivation { pname = "jcode"; inherit version; src = fetchurl { url = "https://github.com/1jehuang/jcode/releases/download/v${version}/${source.asset}.tar.gz"; inherit (source) hash; }; # The tarball has no top-level directory. sourceRoot = "."; nativeBuildInputs = [ versionCheckHook ] ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]; # The ELF needs libgcc_s.so.1; everything else it pulls in is glibc. buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.cc.lib ]; installPhase = '' runHook preInstall install -Dm755 ${source.binary} $out/bin/jcode runHook postInstall ''; doInstallCheck = true; versionCheckProgramArg = "--version"; meta = { description = "RAM-efficient AI coding agent harness"; homepage = "https://github.com/1jehuang/jcode"; license = lib.licenses.mit; mainProgram = "jcode"; sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; platforms = builtins.attrNames sources; }; }