nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildNpmPackage,
4 fetchzip,
5 ripgrep,
6 makeWrapper,
7 testers,
8}:
9
10buildNpmPackage (finalAttrs: {
11 pname = "amp-cli";
12 version = "0.0.1769346334-gc7e300";
13
14 src = fetchzip {
15 url = "https://registry.npmjs.org/@sourcegraph/amp/-/amp-${finalAttrs.version}.tgz";
16 hash = "sha256-Y0ySMlYP/mvD+ydkGhqt03zYkFj6BmZpe2zLnAV5rDk=";
17 };
18
19 postPatch = ''
20 cp ${./package-lock.json} package-lock.json
21
22 # Create a minimal package.json with just the dependency we need (without devDependencies)
23 cat > package.json <<EOF
24 {
25 "name": "amp-cli",
26 "version": "0.0.0",
27 "license": "UNLICENSED",
28 "dependencies": {
29 "@sourcegraph/amp": "${finalAttrs.version}"
30 },
31 "bin": {
32 "amp": "./bin/amp-wrapper.js"
33 }
34 }
35 EOF
36
37 # Create wrapper bin directory
38 mkdir -p bin
39
40 # Create a wrapper script that will be installed by npm
41 cat > bin/amp-wrapper.js << EOF
42 #!/usr/bin/env node
43 import('@sourcegraph/amp/dist/main.js')
44 EOF
45 chmod +x bin/amp-wrapper.js
46 '';
47
48 npmDepsHash = "sha256-2e0kJJqmIB3kAaSzATSaNojLvsCIq5MwTGK0y0OxfO4=";
49
50 propagatedBuildInputs = [
51 ripgrep
52 ];
53
54 nativeBuildInputs = [
55 makeWrapper
56 ];
57
58 npmFlags = [
59 "--no-audit"
60 "--no-fund"
61 "--ignore-scripts"
62 ];
63
64 # Disable build and prune steps
65 dontNpmBuild = true;
66
67 postInstall = ''
68 wrapProgram $out/bin/amp \
69 --prefix PATH : ${lib.makeBinPath [ ripgrep ]} \
70 --set AMP_SKIP_UPDATE_CHECK 1
71 '';
72
73 passthru.updateScript = ./update.sh;
74 passthru.tests.version = testers.testVersion {
75 package = finalAttrs.finalPackage;
76 command = "HOME=$(mktemp -d) amp --version";
77 };
78
79 meta = {
80 description = "CLI for Amp, an agentic coding agent in research preview from Sourcegraph";
81 homepage = "https://ampcode.com/";
82 downloadPage = "https://www.npmjs.com/package/@sourcegraph/amp";
83 license = lib.licenses.unfree;
84 maintainers = with lib.maintainers; [
85 keegancsmith
86 burmudar
87 ];
88 mainProgram = "amp";
89 };
90})