diff --git a/FORK.md b/FORK.md index 1d074bf329d..d258322a529 100644 --- a/FORK.md +++ b/FORK.md @@ -23,6 +23,11 @@ This repository is a fork of `pingdotgg/t3code`. Keep this file focused on fork - Fork release jobs use GitHub-hosted runners where upstream private runners are unavailable. - Web dist release archives are built as hosted static apps and carry the release channel. +### Nix Package + +- The fork exposes the server and web bundle as an `x86_64-linux` flake package. +- The package version follows the server manifest by default and supports the generated nightly version override. + ### Desktop Updater Channels - Stable builds use `latest`; nightly builds use `nightly`. diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..c06115a1e8e --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1785090369, + "narHash": "sha256-m0pDuRJG7EDo9ri+4Ksu83VsI+PlxNC9lNBfydejce4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "624af665418d3c65d544145b4d34ad696439570e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..b61075c442c --- /dev/null +++ b/flake.nix @@ -0,0 +1,20 @@ +{ + description = "T3 Code"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = + { nixpkgs, self }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + in + { + packages.${system} = rec { + t3code = pkgs.callPackage ./nix/package.nix { src = self; }; + default = t3code; + }; + + formatter.${system} = pkgs.nixfmt; + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 00000000000..431ee503f58 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,110 @@ +{ + cacert, + fetchPnpmDeps, + lib, + makeBinaryWrapper, + node-gyp, + nodejs_24, + pnpm_11, + pnpmConfigHook, + python3, + src, + stdenv, + version ? null, + writableTmpDirAsHomeHook, +}: + +let + nodejs = nodejs_24; + pnpm = pnpm_11; + sourceVersion = (builtins.fromJSON (builtins.readFile "${src}/apps/server/package.json")).version; +in +stdenv.mkDerivation (finalAttrs: { + pname = "t3code"; + version = if version == null then sourceVersion else version; + inherit src; + strictDeps = true; + + pnpmWorkspaces = [ + "@t3tools/monorepo" + "t3..." + "@t3tools/web..." + "@t3tools/scripts..." + ]; + + pnpmDeps = fetchPnpmDeps { + inherit (finalAttrs) + pname + version + src + pnpmWorkspaces + ; + inherit pnpm; + fetcherVersion = 4; + hash = "sha256-/FRJ6duN5A0x2wiMc9zBX+/Zkse8duCKSrHENlmD4Gk="; + }; + + postPatch = lib.optionalString (finalAttrs.version != sourceVersion) '' + substituteInPlace \ + apps/desktop/package.json \ + apps/server/package.json \ + apps/web/package.json \ + packages/contracts/package.json \ + --replace-fail '"version": "${sourceVersion}"' \ + '"version": "${finalAttrs.version}"' + ''; + + nativeBuildInputs = [ + makeBinaryWrapper + node-gyp + nodejs + pnpm + pnpmConfigHook + python3 + writableTmpDirAsHomeHook + ]; + + dontPatchELF = true; + noAuditTmpdir = true; + SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + + preBuild = '' + export npm_config_nodedir=${nodejs} + export ELECTRON_SKIP_BINARY_DOWNLOAD=1 + pnpm rebuild --pending "''${pnpmInstallFlags[@]}" --filter '!@t3tools/monorepo' + ''; + + buildPhase = '' + runHook preBuild + + pnpm --filter @t3tools/web build + pnpm --filter t3 build:bundle + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir --parents "$out"/libexec/t3code/apps/server + cp --recursive --no-preserve=mode node_modules "$out"/libexec/t3code + cp --recursive --no-preserve=mode packages "$out"/libexec/t3code + cp --recursive --no-preserve=mode apps/server/{node_modules,dist} "$out"/libexec/t3code/apps/server + cp --recursive --no-preserve=mode apps/web/dist "$out"/libexec/t3code/apps/server/dist/client + + find "$out"/libexec/t3code -xtype l -delete + + makeWrapper ${lib.getExe nodejs} "$out"/bin/t3 \ + --add-flags "$out"/libexec/t3code/apps/server/dist/bin.mjs + + runHook postInstall + ''; + + meta = { + description = "Remote control for coding agents"; + homepage = "https://github.com/tarik02/t3code"; + license = lib.licenses.mit; + mainProgram = "t3"; + platforms = [ "x86_64-linux" ]; + }; +})