diff --git a/flake.lock b/flake.lock index b14830f..29c423b 100644 --- a/flake.lock +++ b/flake.lock @@ -189,22 +189,6 @@ "type": "github" } }, - "pi-src": { - "flake": false, - "locked": { - "lastModified": 1784538015, - "narHash": "sha256-eCOyo0h5WlO6iwEZXmeH1ulDIqmpXzTmUWezPqD1DT0=", - "owner": "earendil-works", - "repo": "pi", - "rev": "8b9373707845631ad286580b1d2c3f938e5c263f", - "type": "github" - }, - "original": { - "owner": "earendil-works", - "repo": "pi", - "type": "github" - } - }, "root": { "inputs": { "herdr": "herdr", @@ -213,7 +197,6 @@ "nix-darwin": "nix-darwin", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", - "pi-src": "pi-src", "scatterer-src": "scatterer-src" } }, diff --git a/flake.nix b/flake.nix index c02ef57..d077501 100644 --- a/flake.nix +++ b/flake.nix @@ -22,12 +22,6 @@ nix-darwin.url = "github:nix-darwin/nix-darwin/nix-darwin-26.05"; nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; - # Track Pi directly so `nix flake update` can advance it independently of - # the version packaged in nixpkgs-unstable. - pi-src = { - url = "github:earendil-works/pi"; - flake = false; - }; }; outputs = inputs@{ self, nixpkgs, home-manager, nix-darwin, ... }: diff --git a/modules/home/dev-package-list.nix b/modules/home/dev-package-list.nix index 6bded96..da1d605 100644 --- a/modules/home/dev-package-list.nix +++ b/modules/home/dev-package-list.nix @@ -6,9 +6,7 @@ let system = pkgs.stdenv.hostPlatform.system; config = pkgs.config; }; - piCodingAgent = unstable.callPackage ../../packages/pi-coding-agent.nix { - src = inputs.pi-src; - }; + piCodingAgent = unstable.callPackage ../../packages/pi-coding-agent.nix { }; availableAgentPackages = { # The nixpkgs Rust build currently pulls livekit-libwebrtc, which fails to # build on aarch64-darwin. Use OpenAI's npm binary distribution instead. diff --git a/modules/home/pi-opencode-netns-wrapper.nix b/modules/home/pi-opencode-netns-wrapper.nix index 7313d4f..b024fa0 100644 --- a/modules/home/pi-opencode-netns-wrapper.nix +++ b/modules/home/pi-opencode-netns-wrapper.nix @@ -2,9 +2,11 @@ let cfg = config.my.piNetnsWrapper; - piCodingAgent = pkgs.callPackage ../../packages/pi-coding-agent.nix { - src = dotfilesInputs.pi-src; + unstable = import dotfilesInputs.nixpkgs-unstable { + system = pkgs.stdenv.hostPlatform.system; + config = pkgs.config; }; + piCodingAgent = unstable.callPackage ../../packages/pi-coding-agent.nix { }; realPi = "${piCodingAgent}/bin/pi"; piWrapper = pkgs.writeShellScriptBin "pi" '' set -euo pipefail diff --git a/packages/pi-coding-agent.nix b/packages/pi-coding-agent.nix index 9ed0a89..fce3842 100644 --- a/packages/pi-coding-agent.nix +++ b/packages/pi-coding-agent.nix @@ -1,82 +1,10 @@ -{ - lib, - buildNpmPackage, - importNpmLock, - makeBinaryWrapper, - stdenvNoCC, - versionCheckHook, - writableTmpDirAsHomeHook, - ripgrep, - fd, - src, -}: +{ pi-coding-agent }: -let - packageJson = builtins.fromJSON (builtins.readFile "${src}/packages/coding-agent/package.json"); -in -buildNpmPackage { - pname = "pi-coding-agent"; - version = packageJson.version; - - inherit src; - - npmDeps = importNpmLock { npmRoot = src; }; - npmConfigHook = importNpmLock.npmConfigHook; - - npmWorkspace = "packages/coding-agent"; - - # Skip native module rebuild for unneeded workspaces (e.g. canvas from web-ui). - npmRebuildFlags = [ "--ignore-scripts" ]; - - nativeBuildInputs = [ - makeBinaryWrapper - ]; - - # Build workspace dependencies in order, then the coding-agent. - # We invoke tsgo directly for workspace deps to skip pi-ai's - # generate-models script which requires network access - # (models.generated.ts is committed to the repo). - buildPhase = '' - runHook preBuild - - npx tsgo -p packages/ai/tsconfig.build.json - npx tsgo -p packages/tui/tsconfig.build.json - npx tsgo -p packages/agent/tsconfig.build.json - npm run build --workspace=packages/coding-agent - - runHook postBuild - ''; - - # npm workspace symlinks in the output point into packages/ which - # doesn't exist there. Replace runtime deps with built content and - # delete the rest. - postInstall = '' - local nm="$out/lib/node_modules/pi-monorepo/node_modules" - - # Replace workspace deps needed at runtime with real copies. - for ws in @earendil-works/pi-ai:packages/ai \ - @earendil-works/pi-agent-core:packages/agent \ - @earendil-works/pi-tui:packages/tui; do - IFS=: read -r pkg ws_src <<< "$ws" - rm "$nm/$pkg" - cp -r "$ws_src" "$nm/$pkg" - done - - # Delete remaining workspace symlinks. - find "$nm" -type l -lname '*/packages/*' -delete - - # Clean up now-dangling .bin symlinks. - find "$nm/.bin" -xtype l -delete - '' - + lib.optionalString stdenvNoCC.hostPlatform.isDarwin '' - # Remove foreign Linux binaries that make audit-tmpdir try to inspect ELF - # RPATHs with patchelf. - rm -rf \ - "$nm/@anthropic-ai/sandbox-runtime/dist/vendor/seccomp" \ - "$nm/@anthropic-ai/sandbox-runtime/vendor/seccomp" - ''; - - postFixup = '' +# Track Pi through nixpkgs' release package instead of building arbitrary +# commits from upstream main. Upstream main can contain generated TypeScript +# whose runtime JSON data is only produced during the networked release build. +pi-coding-agent.overrideAttrs (oldAttrs: { + postFixup = (oldAttrs.postFixup or "") + '' node <<'NODE' const fs = require("fs"); @@ -125,31 +53,5 @@ buildNpmPackage { ` contextEntries.push(stripAssistantUsageForCompactionContext(entry));`, ); NODE - - wrapProgram $out/bin/pi --prefix PATH : ${ - lib.makeBinPath [ - ripgrep - fd - ] - } ''; - - doInstallCheck = true; - nativeInstallCheckInputs = [ - writableTmpDirAsHomeHook - versionCheckHook - ]; - versionCheckKeepEnvironment = [ "HOME" ]; - versionCheckProgram = "${placeholder "out"}/bin/pi"; - versionCheckProgramArg = "--version"; - - meta = { - description = "Coding agent CLI with read, bash, edit, write tools and session management"; - homepage = "https://pi.dev/"; - downloadPage = "https://www.npmjs.com/package/@earendil-works/pi-coding-agent"; - changelog = "https://github.com/earendil-works/pi/blob/main/packages/coding-agent/CHANGELOG.md"; - license = lib.licenses.mit; - maintainers = with lib.maintainers; [ munksgaard ]; - mainProgram = "pi"; - }; -} +})