<< All versions

Skill v1.0.0

currentLLM-judged scan95/100
codebam/hermes-skills/npm-deps-hash-replication
──Details
PublishedOctober 23, 2026 at 06:38 PM
Content Hashsha256:eff0cde54fd2e30e...
Git SHA7ee252ca1d0c
──Files
Files (1 file, 3.5 KB)
SKILL.md3.5 KBactive
SKILL.md · 75 lines · 3.5 KB

name: npm-deps-hash-replication description: Use when computing npmDepsHash without a Nix build. version: 1.0.0 author: Hermes Agent license: MIT platforms: [linux] metadata: hermes: tags: [nix, npm, packaging, buildNpmPackage, fetchNpmDeps, prefetch-npm-deps] related_skills: [declarative-hermes-config, nixos-flake-verify-in-sandbox]


npm-deps hash replication (no Nix build required)

When to Use

  • You need npmDepsHash for a buildNpmPackage derivation but cannot run a

real Nix build (no daemon, sandbox store, or no substitute coverage for the pinned nixpkgs rev).

  • Packaging a new npm-distributed CLI into a Nix config from a sandbox.
  • Bumping a vendored npm package whose lockfile changed.

Replicate what prefetch-npm-deps would produce and hash the tree yourself.

Method

  1. Produce a clean lockfile: lockfile v2/v3 whose production graph is

registry tarballs only (for a published npm package, vendor the shipped lockfile with devDependencies stripped; a file: or git ref in the prod graph means the approach must change).

  1. Fetch every tarball to a content-addressed disk cache:

scripts/fetch-lock-tarballs.py package-lock.json cache-dir (resumable; verifies every SRI digest; safe to re-run).

  1. Assemble the prefetch tree:

scripts/assemble-cacache.py package-lock.json cache-dir outdir

  1. Hash it: nix hash path outdir → that is your npmDepsHash

(the FOD uses outputHashMode = recursive).

  1. Always validate against a golden control before pinning. Find any

realized *-npm-deps FOD already in a store, run this pipeline on the same lockfile, and require a byte-for-byte identical tree (diff -r <golden> <replica> must be empty; nix hash path both sides). Only a golden reproduction makes the computed hash trustworthy.

Output format (prefetch-npm-deps 0.1.0, fetcherVersion=1)

  • Tree root: package-lock.json (bytes identical to input) + _cacache/.
  • Tarball bodies: _cacache/content-v2/<algo>/<h[0:2]>/<h[2:4]>/<h[4:]>

where h = hex of the lockfile SRI digest.

  • Index: _cacache/index-v5/<sha256(key)[0:2]>/<[2:4]>/<[4:]>; each line is

sha1(json)\tjson with NO trailing newline (prefix "\n" only when appending to a non-empty file); json is the compact serialization of {key,integrity,time:0,size,metadata:{url,options:{compress:true}}}; key = "make-fetch-happen:request-cache:" + url.

  • Selection: non-empty packages keys only; drop entries whose resolved

is missing/not URL-shaped or starts with file:; refuse git/ssh; per duplicate URL keep the strongest integrity (sha512 > sha1).

  • The derivation's env carries NPM_FETCHER_VERSION=1 — check the generated

FOD drv contains it together with your hash.

Pitfalls

  • Dev deps must be stripped from the vendored lockfile: dev nodes often

point at file:/workspace refs that prefetch refuses, and npm ci --ignore-scripts in buildNpmPackage only needs the prod graph.

  • A one-shot downloader that buffers bodies in RAM dies on large lockfiles;

use the fetch→cache→assemble two-phase scripts (resumable by design).

  • Keep os/cpu fields on platform-specific packages — they are part of

the graph and the fetch set.

  • A near-miss in index-line formatting (newline handling, json key order,

separator spacing) shifts the whole tree hash; the golden comparison is what catches it, not eyeballing.

  • URL normalization: registry URLs are already canonical; only lowercase

scheme/host and drop default ports if a non-registry URL ever appears.

All versions