Skip to content

Commit 0753072

Browse files
committed
fix: correct hash prefetch guidance in add-package skill and CLAUDE.md
Document the correct nix-prefetch-url invocation for each Nix fetcher: fetchurl (raw file, no --unpack) vs fetchFromGitHub (unpacked, --unpack).
1 parent 55eb963 commit 0753072

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

.claude/skills/add-package/SKILL.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,26 @@ Where `mkPrebuilt` and `mkFromSource` are defined as `let` bindings in the same
6262
1. `mkdir packages/$0`
6363
2. Create `data.json` with `_meta` (default version, releases URL) and the version entry
6464
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
65+
4. Compute hashes — match the prefetch tool to the Nix fetcher:
66+
67+
**`fetchurl`** (prebuilt binaries — .tar.gz, .zip, single files):
68+
`fetchurl` hashes the raw downloaded file. The builder's `unpackPhase` extracts it later.
69+
```bash
70+
nix-prefetch-url --type sha256 <url>
71+
nix hash convert --hash-algo sha256 --to sri <hash>
72+
```
73+
Do NOT use `--unpack` — that hashes the extracted content, which is wrong for `fetchurl`.
74+
75+
**`fetchFromGitHub`** (source builds from GitHub):
76+
`fetchFromGitHub` internally uses `fetchzip`, which unpacks and strips the top-level directory. The hash is of the unpacked content.
77+
```bash
78+
nix-prefetch-url --type sha256 --unpack https://github.com/OWNER/REPO/archive/refs/tags/TAG.tar.gz
79+
nix hash convert --hash-algo sha256 --to sri <hash>
80+
```
81+
Here `--unpack` IS correct because `fetchFromGitHub` hashes unpacked content.
82+
83+
**`vendorHash` / `cargoHash`** (Go/Rust dependency hashes):
84+
These can't be computed upfront. Set to `""`, attempt a build, and use the hash from the error output.
7085
5. `git add packages/$0` — Nix flakes require tracked files
7186
6. Build and verify: `nix build .#$0.default -o result-$0 && ./result-$0/bin/$0 --version`
7287

AGENTS.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ Each package directory has a `data.json` with version entries and a `_meta` key:
4747

4848
### 1. Compute the source hash
4949

50-
For a Go source tarball:
50+
**Match the prefetch tool to the Nix fetcher used in `default.nix`:**
51+
52+
For `fetchFromGitHub` / `fetchzip` (hashes unpacked content — use `--unpack`):
5153
```bash
52-
nix-prefetch-url --type sha256 --unpack https://go.dev/dl/go1.25.7.src.tar.gz
53-
# Convert to SRI: nix hash convert --hash-algo sha256 --to sri <hash>
54+
nix-prefetch-url --type sha256 --unpack https://github.com/OWNER/REPO/archive/refs/tags/vX.Y.Z.tar.gz
55+
nix hash convert --hash-algo sha256 --to sri <hash>
5456
```
5557

56-
For a GitHub release:
58+
For `fetchurl` (hashes the raw downloaded file — do NOT use `--unpack`):
5759
```bash
58-
nix-prefetch-url --type sha256 --unpack https://github.com/OWNER/REPO/archive/refs/tags/vX.Y.Z.tar.gz
60+
nix-prefetch-url --type sha256 https://example.com/package-X.Y.Z.tar.gz
5961
nix hash convert --hash-algo sha256 --to sri <hash>
6062
```
6163

64+
`fetchurl` downloads the file as-is; the builder's `unpackPhase` extracts it. `fetchFromGitHub` unpacks and strips the top-level directory before hashing. Using the wrong prefetch mode produces a hash mismatch at build time.
65+
6266
### 2. Add the version entry to `data.json`
6367

6468
```json

0 commit comments

Comments
 (0)