diff --git a/flake.lock b/flake.lock index 1e4f700..253f4cc 100644 --- a/flake.lock +++ b/flake.lock @@ -18,7 +18,25 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "t3code": "t3code" + } + }, + "t3code": { + "flake": false, + "locked": { + "lastModified": 1795472381, + "narHash": "sha256-DdmR8buUDxTosw2ZKe2wnHtuLKX7DJoaPFsmWWyFf+E=", + "owner": "pingdotgg", + "repo": "t3code", + "rev": "42c9107983d8f65c38117501cbcde1ee5c82ef14", + "type": "github" + }, + "original": { + "owner": "pingdotgg", + "repo": "t3code", + "rev": "42c9107983d8f65c38117501cbcde1ee5c82ef14", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 41e9a2b..f9e7938 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,19 @@ { - description = "t3tui local development dependencies (bun) and the headless T3 Code server (t3)"; + description = "t3tui, a terminal client for T3 Code (packages: t3tui binary, t3 headless server)"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + # The vendored T3 Code contracts/runtime. The git submodule under vendor/t3code is the + # source of truth for local development; this input pins the same commit for flake + # builds, where git submodule contents are not part of the fetched tree. + t3code = { + url = "github:pingdotgg/t3code/42c9107983d8f65c38117501cbcde1ee5c82ef14"; + flake = false; + }; + }; outputs = - { nixpkgs, ... }: + { self, nixpkgs, t3code, ... }: let systems = [ "x86_64-linux" @@ -76,10 +85,102 @@ runHook postInstall ''; }; + # t3tui itself, compiled to one self-contained binary with `bun build --compile`. + # npm dependencies come from a fixed-output derivation (this nixpkgs has no bun + # fetcher), so the real build is offline. The version comes from package.json. + mkT3tui = + pkgs: + let + version = (pkgs.lib.importJSON ./package.json).version; + compileTarget = { + "x86_64-linux" = "linux-x64"; + "aarch64-linux" = "linux-arm64"; + "aarch64-darwin" = "darwin-arm64"; + }.${pkgs.system}; + # Flake sources from git don't include the submodule's contents, so graft the + # pinned t3code input in place of vendor/t3code. + src = pkgs.runCommand "t3tui-src-${version}" { } '' + cp -r ${./.} "$out" + chmod -R u+w "$out" + rm -rf "$out/vendor/t3code" + # Copied, not symlinked: module resolution must find the project's + # node_modules above vendor/, and a symlink would resolve to the store. + cp -r ${t3code} "$out/vendor/t3code" + ''; + deps = pkgs.stdenvNoCC.mkDerivation { + pname = "t3tui-deps"; + inherit version src; + nativeBuildInputs = [ + pkgs.bun + pkgs.cacert + ]; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = "sha256-aLJSI2zpF2lh4sZwul4xD2edHcWiqq/BxJXLltaE5jE="; + dontFixup = true; + dontConfigure = true; + buildPhase = '' + runHook preBuild + export HOME=$TMPDIR + chmod -R u+w . + bun install --frozen-lockfile + runHook postBuild + ''; + installPhase = '' + runHook preInstall + mkdir "$out" + cp -r node_modules "$out/node_modules" + runHook postInstall + ''; + }; + in + pkgs.stdenv.mkDerivation { + pname = "t3tui"; + inherit version src; + nativeBuildInputs = [ pkgs.bun ]; + dontConfigure = true; + # The binary is a Bun SEA: stripping or patching its ELF corrupts the embedded app. + dontStrip = true; + dontPatchELF = true; + dontPatchShebangs = true; + buildPhase = '' + runHook preBuild + export HOME=$TMPDIR + chmod -R u+w . + cp -r ${deps}/node_modules . + chmod -R u+w node_modules + bun run compile ${compileTarget} + runHook postBuild + ''; + installPhase = '' + runHook preInstall + install -Dm755 "release/t3tui-${compileTarget}" "$out/bin/t3tui" + runHook postInstall + ''; + meta = { + description = "A terminal client for T3 Code"; + homepage = "https://git.venomade.com/venomade/t3tui"; + license = pkgs.lib.licenses.mit; + mainProgram = "t3tui"; + }; + }; in { packages = forAllSystems (pkgs: { t3 = mkT3 pkgs; + t3tui = mkT3tui pkgs; + default = mkT3tui pkgs; + }); + + apps = forAllSystems (pkgs: { + t3tui = { + type = "app"; + program = "${self.packages.${pkgs.system}.t3tui}/bin/t3tui"; + }; + default = { + type = "app"; + program = "${self.packages.${pkgs.system}.t3tui}/bin/t3tui"; + }; }); devShells = forAllSystems (pkgs: { diff --git a/scripts/link-vendor.ts b/scripts/link-vendor.ts index e3dfc2e..03e436f 100644 --- a/scripts/link-vendor.ts +++ b/scripts/link-vendor.ts @@ -2,7 +2,7 @@ // their package export maps resolve. They are TypeScript sources Bun runs as-is. // The packages are copied (not symlinked) so the small set of classic-tsc // false positives below can be patched in the copy; vendor/ itself stays pristine. -import { cp, lstat, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises"; +import { chmod, cp, lstat, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises"; import { join } from "node:path"; const root = join(import.meta.dir, ".."); @@ -30,7 +30,11 @@ const tscPatches: ReadonlyArray<{ file: string; from: string; to: string }> = [ for (const { file, from, to } of tscPatches) { const path = join(scopeDir, file); const source = await readFile(path, "utf8"); - if (source.includes(from)) await writeFile(path, source.replace(from, to)); + // Copies keep the source's mode; a read-only store path (nix flake input) must be writable here. + if (source.includes(from)) { + await chmod(path, 0o644); + await writeFile(path, source.replace(from, to)); + } } // Upstream resolves "@pierre/words/core" and "@pierre/words/wasm" through its web app's