Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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, ... }:
Expand Down
4 changes: 1 addition & 3 deletions modules/home/dev-package-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions modules/home/pi-opencode-netns-wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 7 additions & 105 deletions packages/pi-coding-agent.nix
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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";
};
}
})
Loading