|
| 1 | +--- |
| 2 | +name: add-package |
| 3 | +description: Add a new package to the toolbox registry. Handles prebuilt binaries, source builds, or hybrid (prebuilt with source fallback) depending on what upstream provides. Use when adding a new tool to toolbox. |
| 4 | +argument-hint: <name> [version] |
| 5 | +allowed-tools: Bash Read Edit Write Glob Grep |
| 6 | +--- |
| 7 | + |
| 8 | +# Add Package |
| 9 | + |
| 10 | +Add a new package to the toolbox registry. |
| 11 | + |
| 12 | +## Current packages |
| 13 | + |
| 14 | +!`cd "$(git rev-parse --show-toplevel)" && ls -d packages/*/` |
| 15 | + |
| 16 | +## Task |
| 17 | + |
| 18 | +Add a package called `$0` at version `$1` (if provided; otherwise discover the latest version). |
| 19 | + |
| 20 | +## Steps |
| 21 | + |
| 22 | +### 1. Research upstream |
| 23 | + |
| 24 | +- Find the upstream repository and releases page |
| 25 | +- Check what release assets exist: prebuilt binaries per platform? source tarballs only? |
| 26 | +- Determine which platforms have prebuilt binaries (x86_64-linux, aarch64-linux, x86_64-darwin, aarch64-darwin) |
| 27 | +- Check the build system for source builds (Go → buildGoModule, Rust → buildRustPackage, C/Make → stdenv.mkDerivation) |
| 28 | + |
| 29 | +### 2. Choose the builder strategy |
| 30 | + |
| 31 | +**Prebuilt only** — all 4 platforms have prebuilt binaries (e.g. uv, biome, gh): |
| 32 | +- `data.json` has per-platform SHA256 hashes |
| 33 | +- `default.nix` uses `fetchurl` + `stdenv.mkDerivation` with `dontBuild = true` |
| 34 | +- Reference: `packages/uv/default.nix`, `packages/gh/default.nix` |
| 35 | + |
| 36 | +**Source only** — no prebuilt binaries, or user prefers source builds (e.g. jj, beadwork, git): |
| 37 | +- `data.json` has source hash + build-specific hashes (vendorHash, cargoHash) |
| 38 | +- `default.nix` uses `buildGoModule`, `buildRustPackage`, or `stdenv.mkDerivation` |
| 39 | +- Reference: `packages/jj/default.nix` (Rust), `packages/beadwork/default.nix` (Go), `packages/git/default.nix` (C) |
| 40 | + |
| 41 | +**Hybrid** — some platforms have prebuilt binaries, others need source builds (e.g. delta): |
| 42 | +- `data.json` has per-platform hashes for prebuilt platforms, plus `srcHash`/`cargoHash`/`rust` (or `vendorHash`/`go`) for source builds |
| 43 | +- `default.nix` has a single `default` builder that checks `if versionData ? ${system}` to pick prebuilt vs source |
| 44 | +- Reference: `packages/delta/default.nix` |
| 45 | + |
| 46 | +The hybrid pattern looks like: |
| 47 | + |
| 48 | +```nix |
| 49 | +builders = { |
| 50 | + default = version: versionData: |
| 51 | + if versionData ? ${system} then |
| 52 | + mkPrebuilt version versionData |
| 53 | + else |
| 54 | + mkFromSource version versionData; |
| 55 | +}; |
| 56 | +``` |
| 57 | + |
| 58 | +Where `mkPrebuilt` and `mkFromSource` are defined as `let` bindings in the same file. |
| 59 | + |
| 60 | +### 3. Create the package |
| 61 | + |
| 62 | +1. `mkdir packages/$0` |
| 63 | +2. Create `data.json` with `_meta` (default version, releases URL) and the version entry |
| 64 | +3. Create `default.nix` following the chosen pattern |
| 65 | +4. Compute hashes: |
| 66 | + - Prebuilt: `nix-prefetch-url --type sha256 --unpack <url>` then `nix hash convert --hash-algo sha256 --to sri <hash>` |
| 67 | + - **Important**: `nix-prefetch-url` hashes often differ from what nix uses at build time. Set the hash, attempt a build, and use the correct hash from the error if it mismatches. |
| 68 | + - Source (Go): set `vendorHash` to `""`, build, use hash from error |
| 69 | + - Source (Rust): set `cargoHash` to `""`, build, use hash from error |
| 70 | +5. `git add packages/$0` — Nix flakes require tracked files |
| 71 | +6. Build and verify: `nix build .#$0.default -o result-$0 && ./result-$0/bin/$0 --version` |
| 72 | + |
| 73 | +### 4. Platform considerations |
| 74 | + |
| 75 | +- macOS zips need `pkgs.unzip` in `nativeBuildInputs` |
| 76 | +- Linux prebuilt binaries need `pkgs.autoPatchelfHook` and `pkgs.stdenv.cc.cc.lib` |
| 77 | +- macOS source builds needing system frameworks use `pkgs.apple-sdk_15` (not the removed `pkgs.darwin.apple_sdk`) |
| 78 | +- If a platform has no prebuilt and can't easily build from source, it's fine to omit it — document in `meta.platforms` |
| 79 | + |
| 80 | +### 5. Finalize |
| 81 | + |
| 82 | +- Create a jj change with message: `feat: add $0 <version>` |
| 83 | +- If adding to a toolchain, that's a separate jj change |
0 commit comments