Package t3tui itself as a flake output (packages.t3tui / apps.t3tui)

Builds one self-contained binary with `bun build --compile`. npm deps
come from a fixed-output derivation (this nixpkgs has no bun fetcher);
the vendored t3code submodule is grafted from a pinned flake input
(same commit as the submodule) because git flake sources don't include
submodule contents. The binary is a Bun SEA, so strip/patchelf are
disabled on the package. link-vendor now chmods copied vendor files
writable before patching (nix store sources are read-only).

Verified: nix build .#t3tui -> bin/t3tui version prints 0.2.0.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
venomadeandmistral-vibe Bot committed 2026-11-24 01:42:25 +00:00
1 parent 9d1f6d8bc9
commit c5311a763f
3 files changed
+129 -6

No files matched your search

Generated
+19 -1
View File
@@ -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"
}
}
},
+104 -3
View File
@@ -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: {
+6 -2
View File
@@ -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