Watch
0
0
Fork
You've already forked hyperhive
0

reference-docs: build again with 40 workspace crates

The crate README rewrite was unrolled at eval time: one sed block per
crate, each carrying one -e expression per other crate. The installPhase
string grew with the square of the crate count, and at 40 crates
(d5de1e494 added swarm-claude-login) it reached 131708 bytes. Linux
caps a single environment variable at 128 KiB, so exec of the builder
failed with "Argument list too long" and every consumer of
reference-docs failed with it, the website repo included.

The rewrite is now a shell loop over $members at build time, building
the same sed expressions per crate. The phase text no longer depends on
the crate count. Output is byte-identical to the old form at 6aab2ebb6
(39 crates, the last commit where it built).

Closes #5321
This commit is contained in:
atlas 2026-10-15 15:32:20 +02:00
commit fcda1f4a04

View file

@ -1,6 +1,5 @@
{
stdenv,
lib,
self,
optionsMd,
}:
@ -34,22 +33,6 @@
let
cargoToml = builtins.fromTOML (builtins.readFile ../../Cargo.toml);
members = cargoToml.workspace.members;
# A member-name relative link (`../<other-crate>`, no specific file —
# forge's browser renders that as a directory listing today) becomes a
# sibling crates/<other-crate>.md link once every crate README
# lives flat in the same directory. Built once, applied per file below,
# rather than a fresh `lib.concatMapStrings` per crate's own transform —
# every crate needs the exact same substitution list (every *other*
# member), so this only differs on the `member != other` filter.
siblingLinkFixups =
member:
lib.concatMapStrings (
other:
lib.optionalString (other != member) ''
-e 's,\]\(\.\./${other}(/)?\),](./${other}.md),g' \
''
) members;
in
stdenv.mkDerivation {
pname = "hyperhive-docs";
@ -63,11 +46,15 @@ stdenv.mkDerivation {
# the alternative is hand-copying READMEs into docs/ and letting them
# drift, which is the exact duplication this issue exists to avoid.
src = ../../docs;
inherit self optionsMd;
inherit self optionsMd members;
dontBuild = true;
dontConfigure = true;
# The per-crate rewrite is a loop at build time, so this phase's text
# stays the same size as crates are added: each attribute reaches the
# builder as one environment variable, and Linux refuses to exec with
# a single one over 128 KiB.
installPhase = ''
runHook preInstall
mkdir -p $out
@ -75,24 +62,24 @@ stdenv.mkDerivation {
mkdir -p "$out/crates"
cp -r "$optionsMd" "$out/options"
${lib.concatMapStrings (member: ''
if [ -f "$self/${member}/README.md" ]; then
# Rewrite relative links that were correct from the crate's own
# position in the repo tree but aren't once the file is
# virtually one level under docs/ instead:
# ../docs/x.md (crate root -> repo docs/) -> ../x.md lint:allow (stand-in name)
# (crates/ -> docs/ is one directory shallower than
# <crate>/ -> docs/ was, so the leading docs/ segment drops)
# ../<sibling-crate> (that crate's own directory, no file)
# -> ./<sibling-crate>.md, once that sibling also has a
# crates page every crate README lives flat beside it.
sed -E \
-e 's,\]\(\.\./docs/,](../,g' \
${siblingLinkFixups member} \
"$self/${member}/README.md" \
> "$out/crates/${member}.md"
fi
'') members}
for member in $members; do
[ -f "$self/$member/README.md" ] || continue
# Rewrite relative links that were correct from the crate's own
# position in the repo tree but aren't once the file is
# virtually one level under docs/ instead:
# ../docs/x.md (crate root -> repo docs/) -> ../x.md lint:allow (stand-in name)
# (crates/ -> docs/ is one directory shallower than
# <crate>/ -> docs/ was, so the leading docs/ segment drops)
# ../<sibling-crate> (that crate's own directory, no file; forge
# renders it as a directory listing) -> ./<sibling-crate>.md,
# since every crate README lives flat beside it under crates/.
fixups=(-e 's,\]\(\.\./docs/,](../,g')
for other in $members; do
[ "$other" != "$member" ] || continue
fixups+=(-e "s,\]\(\.\./$other(/)?\),](./$other.md),g")
done
sed -E "''${fixups[@]}" "$self/$member/README.md" >"$out/crates/$member.md"
done
runHook postInstall
'';