From d127d7a6284c6c5fc089ef2fe0ab9a10f19cb225 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Fri, 3 Apr 2026 10:40:09 -0400 Subject: [PATCH 1/2] nix build --- flake.lock | 61 +++++++++++++++++++++++++++++++ flake.nix | 84 +++++++++++++++++++++++++++++++++++++++++++ scripts/build-cli.mjs | 17 ++++++--- 3 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..03cb250 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1775036866, + "narHash": "sha256-ZojAnPuCdy657PbTq5V0Y+AHKhZAIwSIT2cb8UgAz/U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6201e203d09599479a3b3450ed24fa81537ebc4e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..300a111 --- /dev/null +++ b/flake.nix @@ -0,0 +1,84 @@ +{ + description = "Nix flake for building the Claude Code source build"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + + nodejs = pkgs.nodejs_22; + + buildCli = pkgs.writeShellApplication { + name = "build-claude-code"; + runtimeInputs = [ + nodejs + pkgs.bun + ]; + text = '' + set -euo pipefail + + if [ ! -f ./scripts/build-cli.mjs ]; then + echo "Run this from the repository root so ./scripts/build-cli.mjs is available." >&2 + exit 1 + fi + + exec node ./scripts/build-cli.mjs "$@" + ''; + }; + in + { + packages.default = buildCli; + packages.build-cli = buildCli; + + apps.default = { + type = "app"; + program = "${buildCli}/bin/build-claude-code"; + }; + + apps.build = { + type = "app"; + program = "${buildCli}/bin/build-claude-code"; + }; + + apps.build-dev = { + type = "app"; + program = "${pkgs.writeShellApplication { + name = "build-claude-code-dev"; + runtimeInputs = [ + nodejs + pkgs.bun + ]; + text = '' + set -euo pipefail + + if [ ! -f ./scripts/build-cli.mjs ]; then + echo "Run this from the repository root so ./scripts/build-cli.mjs is available." >&2 + exit 1 + fi + + exec node ./scripts/build-cli.mjs --no-minify "$@" + ''; + }}/bin/build-claude-code-dev"; + }; + + devShells.default = pkgs.mkShell { + packages = [ + nodejs + pkgs.bun + ]; + + shellHook = '' + echo "Tooling loaded: node $(node --version), npm $(npm --version), bun $(bun --version)" + echo "Build with: node scripts/build-cli.mjs" + echo "Or via flake app: nix run .#build" + ''; + }; + }); +} diff --git a/scripts/build-cli.mjs b/scripts/build-cli.mjs index 1ba18bd..d089663 100644 --- a/scripts/build-cli.mjs +++ b/scripts/build-cli.mjs @@ -190,15 +190,24 @@ function main() { generateWorkspaceAugmentations(); const buildResult = runBunBuild(); + if (buildResult.error) { + const message = buildResult.error.message || String(buildResult.error); + console.error(`Failed to start bun: ${message}`); + process.exit(buildResult.status ?? 1); + } if (buildResult.status === 0) { finalizeBuild(); return; } - const changed = reconcileBuildErrors(buildResult.stderr); + const changed = reconcileBuildErrors(buildResult.stderr ?? ''); if (!changed) { - process.stdout.write(buildResult.stdout); - process.stderr.write(buildResult.stderr); + if (buildResult.stdout) { + process.stdout.write(buildResult.stdout); + } + if (buildResult.stderr) { + process.stderr.write(buildResult.stderr); + } process.exit(buildResult.status ?? 1); } } @@ -689,7 +698,7 @@ function finalizeBuild() { } -function reconcileBuildErrors(stderrText) { +function reconcileBuildErrors(stderrText = '') { let changed = false; for (const match of stderrText.matchAll( From d149e98259fc23c6835efd5117d25150f090bfd6 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Fri, 3 Apr 2026 10:40:13 -0400 Subject: [PATCH 2/2] nix build --- Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8ecaed6 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +.PHONY: help build dev build-dev test run clean clean-workspace rebuild rebuild-dev nix-build nix-build-dev nix-develop + +NODE ?= node +NIX ?= nix +BUILD_SCRIPT := scripts/build-cli.mjs +DIST_ENTRY := dist/cli.js +PREPARED_MARKER := .cache/workspace/.prepared.json + +help: ## Show available workflow targets + @printf "Available targets:\n" + @awk 'BEGIN {FS = ":.*## "}; /^[a-zA-Z0-9_-]+:.*## / {printf " %-14s %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +build: ## Build the production bundle with the flake-managed Node/Bun toolchain + $(NIX) run path:.#build + +dev: ## Build an unminified development bundle with the flake-managed toolchain + $(NIX) run path:.#build-dev + +build-dev: ## Alias for the development build + $(NIX) run path:.#build-dev + +test: build ## Build and smoke-test the generated CLI + test -f $(DIST_ENTRY) + $(NIX) develop path:. --command node $(DIST_ENTRY) --help >/dev/null + +run: ## Run the built CLI from dist/cli.js with the local Node binary + $(NODE) $(DIST_ENTRY) + +clean: ## Remove build output + rm -rf dist + +clean-workspace: ## Remove cached extracted workspace and output + rm -rf .cache/workspace dist + +rebuild: clean build ## Clean dist and rebuild production bundle + +rebuild-dev: ## Force workspace regeneration and rebuild unminified bundle + rm -f $(PREPARED_MARKER) + $(NIX) run path:.#build-dev + +nix-build: ## Build through the flake app + $(NIX) run path:.#build + +nix-build-dev: ## Development build through the flake app + $(NIX) run path:.#build-dev + +nix-develop: ## Enter the flake dev shell + $(NIX) develop path:.