amp-cli: switch to binaries from npm

Amp now ships binaries instead of being an NPM package. We switch to
directly downloading those binaries.

We use the same postPathelf code path used by the bun derivation since
this binary produced by bun.

Tested on x86_64-linux and aarch64-darwin.
This commit is contained in:
Keegan Carruthers-Smith
2026-05-18 12:06:08 +02:00
parent cae91756d2
commit 1d1f55b868
3 changed files with 91 additions and 316 deletions
-246
View File
@@ -1,246 +0,0 @@
{
"name": "amp-cli",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@sourcegraph/amp": "^0.0.1778343260-gb9a37d"
}
},
"node_modules/@napi-rs/keyring": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring/-/keyring-1.1.10.tgz",
"integrity": "sha512-PTMyX7FVZGP4s0LcjgrFonek7Sr9ZTdi0TgpR4/4RQmC2TiDcjpdZOXxRMe2aP+5N89Ix9RG9QWclgqRHLk/Xw==",
"license": "MIT",
"engines": {
"node": ">= 10"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/Brooooooklyn"
},
"optionalDependencies": {
"@napi-rs/keyring-darwin-arm64": "1.1.10",
"@napi-rs/keyring-darwin-x64": "1.1.10",
"@napi-rs/keyring-freebsd-x64": "1.1.10",
"@napi-rs/keyring-linux-arm-gnueabihf": "1.1.10",
"@napi-rs/keyring-linux-arm64-gnu": "1.1.10",
"@napi-rs/keyring-linux-arm64-musl": "1.1.10",
"@napi-rs/keyring-linux-riscv64-gnu": "1.1.10",
"@napi-rs/keyring-linux-x64-gnu": "1.1.10",
"@napi-rs/keyring-linux-x64-musl": "1.1.10",
"@napi-rs/keyring-win32-arm64-msvc": "1.1.10",
"@napi-rs/keyring-win32-ia32-msvc": "1.1.10",
"@napi-rs/keyring-win32-x64-msvc": "1.1.10"
}
},
"node_modules/@napi-rs/keyring-darwin-arm64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-darwin-arm64/-/keyring-darwin-arm64-1.1.10.tgz",
"integrity": "sha512-qdXBVypPNgTzso5F/YXWy5dOfFEb9eo43uROMlvwlhj7Aw137iwqwHiqlxR0teFKA33cWnem+ZKeVSIPoobtNA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-darwin-x64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-darwin-x64/-/keyring-darwin-x64-1.1.10.tgz",
"integrity": "sha512-53DgSzhTAJwxR3KCyggHWcLwp+cw2v1zAhBiqNn1P8XwSJSba7HzFwsei6zZMn7bn3UY1ngIHEtaA74UUJVJyw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-freebsd-x64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-freebsd-x64/-/keyring-freebsd-x64-1.1.10.tgz",
"integrity": "sha512-pI6lect/Dp8NnV+g3w1hmYLt69FbSwKFAHn77vjeUaIT5H9C0ikAgwLk89Sd8/Ei/AHHldGkrLeWkNjnIiHfoQ==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-linux-arm-gnueabihf": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-linux-arm-gnueabihf/-/keyring-linux-arm-gnueabihf-1.1.10.tgz",
"integrity": "sha512-w4psOx5m1ltvNLABT/BpIzP5roVcglR1kDhzZgSEOIIrf2i4FKPQqUIo5UQtjsu+AqhhYwnlnketKDf4h+D06g==",
"cpu": [
"arm"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-linux-arm64-gnu": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-linux-arm64-gnu/-/keyring-linux-arm64-gnu-1.1.10.tgz",
"integrity": "sha512-YMC+ZLj3RldGD2Q5wzlZbc8vTh5Fteln+FpB2lw7EbDib3mmIribNH1NG21E4SwculFRDkVJqYGzwIhafloT8Q==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-linux-arm64-musl": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-linux-arm64-musl/-/keyring-linux-arm64-musl-1.1.10.tgz",
"integrity": "sha512-X/Gr5q2vJW7HMpcWRKj7eXer00a1PYb3zt3xsEG/VbcEo5A973pJANTBhYuoW098O/b7ORkunFt9WSbCgenw2A==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-linux-riscv64-gnu": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-linux-riscv64-gnu/-/keyring-linux-riscv64-gnu-1.1.10.tgz",
"integrity": "sha512-vA3R4NVBlU0TVDHavwr5hSqePSs9OwTzzzFlTbZzqgh9s7OqcSwNT096nbr5dRjuQfG9o4/xvjfvVJ4v5z0Egg==",
"cpu": [
"riscv64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-linux-x64-gnu": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-linux-x64-gnu/-/keyring-linux-x64-gnu-1.1.10.tgz",
"integrity": "sha512-qbKE72UeVOrIoiYYHh7joTpDIgQCZpW5OJHG4Ir19GHLdQwNZGKLfFxrTT2DvZ5EXwFJWbOp4Dew4OvvQ0E63g==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-linux-x64-musl": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-linux-x64-musl/-/keyring-linux-x64-musl-1.1.10.tgz",
"integrity": "sha512-niLWyjD/JxQwlOTPeldIx8Xnf03Mp4ooorpWJMWbMuVz/6hSyLVghY/BDYu2Oaxhc+XlTEjmqwhoTWYhmti5eA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-win32-arm64-msvc": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-win32-arm64-msvc/-/keyring-win32-arm64-msvc-1.1.10.tgz",
"integrity": "sha512-VBlqZ0MF5ksc/Z+yxoL2+p6TDu2rqBOcgZ+HwXzSfgFnfnuPds7xOVdFwwaiJbj9CsCrgnByr1jtHRvfEQ6Iiw==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-win32-ia32-msvc": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-win32-ia32-msvc/-/keyring-win32-ia32-msvc-1.1.10.tgz",
"integrity": "sha512-0AvwivxgtjdpTCZCFAQUCxFA45DNKXOsdZYXBCIDfPIpUPgLxhIAsg6q7NJK00r1M24StwwfD+AzZDu14J1PKQ==",
"cpu": [
"ia32"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@napi-rs/keyring-win32-x64-msvc": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@napi-rs/keyring-win32-x64-msvc/-/keyring-win32-x64-msvc-1.1.10.tgz",
"integrity": "sha512-T02DfUUvp3epOJ5lC7hcM5ff6xaLhIfymBf0LEa0oQMi+yCVoDrgjeKeGCUGwtVJWfphu58Tf9twX+hRiAD0dg==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@sourcegraph/amp": {
"version": "0.0.1778343260-gb9a37d",
"resolved": "https://registry.npmjs.org/@sourcegraph/amp/-/amp-0.0.1778343260-gb9a37d.tgz",
"integrity": "sha512-TY4lL2lqwt+NtBa3ngKZSYfY5Z1qBAOd4UQMCT0nsUKatQGtSOIMec+zQSv6tr0L+z2jrDUzD0cpRkBDkLQjsQ==",
"license": "Amp Commercial License",
"dependencies": {
"@napi-rs/keyring": "1.1.10"
},
"bin": {
"amp": "dist/main.js"
},
"engines": {
"node": ">=20"
}
}
}
}
+77 -61
View File
@@ -1,90 +1,106 @@
{
stdenvNoCC,
lib,
buildNpmPackage,
fetchzip,
ripgrep,
fetchurl,
autoPatchelfHook,
gzip,
makeWrapper,
testers,
ripgrep,
versionCheckHook,
writableTmpDirAsHomeHook,
cctools,
darwin,
rcodesign,
}:
buildNpmPackage (finalAttrs: {
pname = "amp-cli";
version = "0.0.1778343260-gb9a37d";
src = fetchzip {
url = "https://registry.npmjs.org/@sourcegraph/amp/-/amp-${finalAttrs.version}.tgz";
hash = "sha256-48FyPDniLNQoeZ+SaheTvzLCYL3r95e9VDCW4Y5gMq8=";
let
platforms = {
# Upstream also publishes linux-x64, which is optimized for AVX2. Use the
# baseline build for nixpkgs so the x86_64-linux package works on all
# supported x86_64 CPUs instead of depending on the build user's CPU flags.
x86_64-linux = "linux-x64-baseline";
aarch64-linux = "linux-arm64";
x86_64-darwin = "darwin-x64";
aarch64-darwin = "darwin-arm64";
};
postPatch = ''
cp ${./package-lock.json} package-lock.json
in
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "amp-cli";
version = "0.0.1779094967-g3f6594";
# Create a minimal package.json with just the dependency we need (without devDependencies)
cat > package.json <<EOF
{
"name": "amp-cli",
"version": "0.0.0",
"license": "UNLICENSED",
"dependencies": {
"@sourcegraph/amp": "${finalAttrs.version}"
},
"bin": {
"amp": "./bin/amp-wrapper.js"
}
}
EOF
# Create wrapper bin directory
mkdir -p bin
# Create a wrapper script that will be installed by npm
cat > bin/amp-wrapper.js << EOF
#!/usr/bin/env node
import('@sourcegraph/amp/dist/main.js')
EOF
chmod +x bin/amp-wrapper.js
'';
npmDepsHash = "sha256-Ce7TaJuSrha+NcFmppMm/byAFosBR2I/zMY4KA5JXuE=";
propagatedBuildInputs = [
ripgrep
];
src = finalAttrs.passthru.sources.${stdenvNoCC.hostPlatform.system};
nativeBuildInputs = [
gzip
makeWrapper
];
]
++ lib.optionals stdenvNoCC.hostPlatform.isLinux [ autoPatchelfHook ];
strictDeps = true;
npmFlags = [
"--no-audit"
"--no-fund"
"--ignore-scripts"
];
dontUnpack = true;
dontStrip = true;
dontFixup = !stdenvNoCC.hostPlatform.isLinux;
# Disable build and prune steps
dontNpmBuild = true;
installPhase = ''
runHook preInstall
postInstall = ''
wrapProgram $out/bin/amp \
--prefix PATH : ${lib.makeBinPath [ ripgrep ]} \
--set AMP_SKIP_UPDATE_CHECK 1
mkdir -p $out/bin $out/libexec/amp-cli
gunzip -c $src > $out/libexec/amp-cli/amp
chmod +x $out/libexec/amp-cli/amp
makeWrapper $out/libexec/amp-cli/amp $out/bin/amp \
--set AMP_SKIP_UPDATE_CHECK 1 \
--prefix PATH : ${lib.makeBinPath [ ripgrep ]}
runHook postInstall
'';
passthru.updateScript = ./update.sh;
passthru.tests.version = testers.testVersion {
package = finalAttrs.finalPackage;
command = "HOME=$(mktemp -d) amp --version";
postPhases = lib.optionals stdenvNoCC.hostPlatform.isDarwin [ "postPatchelf" ];
postPatchelf = lib.optionalString stdenvNoCC.hostPlatform.isDarwin ''
'${lib.getExe' cctools "${cctools.targetPrefix}install_name_tool"}' $out/libexec/amp-cli/amp \
-change /usr/lib/libicucore.A.dylib '${lib.getLib darwin.ICU}/lib/libicucore.A.dylib'
'${lib.getExe rcodesign}' sign --code-signature-flags linker-signed $out/libexec/amp-cli/amp
'';
doInstallCheck = stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform;
nativeInstallCheckInputs = [
writableTmpDirAsHomeHook
versionCheckHook
];
versionCheckProgram = "${placeholder "out"}/bin/amp";
versionCheckProgramArg = "--version";
versionCheckKeepEnvironment = [ "HOME" ];
passthru = {
sources = lib.mapAttrs (
system': platform:
fetchurl {
url = "https://static.ampcode.com/cli/${finalAttrs.version}/amp-${platform}.gz";
hash =
{
x86_64-linux = "sha256-ZBqt8UWDY0SlYOOrJZib+UXdZ1cQxyRNp3T7fr+gcNs=";
aarch64-linux = "sha256-qztHMb4EJBOuEQh0OZ33dqx/MUy5LEPgLry6h+rmwVo=";
x86_64-darwin = "sha256-meedgFtc+DA4NoR0XJuLSX/gmiMKCZLACfPBbk6wfLk=";
aarch64-darwin = "sha256-0v3yM9zQ6ToWBHyPvrmPTP0lfPb1tCoAd6eNgHs3ZkM=";
}
.${system'};
}
) platforms;
updateScript = ./update.sh;
};
meta = {
description = "CLI for Amp, an agentic coding agent in research preview from Sourcegraph";
homepage = "https://ampcode.com/";
downloadPage = "https://www.npmjs.com/package/@sourcegraph/amp";
downloadPage = "https://ampcode.com/install";
license = lib.licenses.unfree;
maintainers = with lib.maintainers; [
keegancsmith
burmudar
];
mainProgram = "amp";
platforms = builtins.attrNames platforms;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
};
})
+14 -9
View File
@@ -1,15 +1,20 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nodejs nix-update
#!nix-shell -i bash -p curl common-updater-scripts
set -euo pipefail
version=$(npm view @sourcegraph/amp version)
version=$(curl -fsSL https://static.ampcode.com/cli/cli-version.txt)
# Generate updated lock file
cd "$(dirname "${BASH_SOURCE[0]}")"
npm i --package-lock-only @sourcegraph/amp@"$version"
rm -f package.json # package.json is not used by buildNpmPackage
cd "$(dirname "${BASH_SOURCE[0]}")/../../../.."
# Update version and hashes
cd -
nix-update amp-cli --version "$version"
for system in \
x86_64-linux \
aarch64-linux \
x86_64-darwin \
aarch64-darwin
do
update-source-version amp-cli "$version" \
--source-key="sources.$system" \
--ignore-same-version \
--ignore-same-hash
done