From fcda1f4a042bc23e8d4bd2a8eff182a1b364d5a3 Mon Sep 17 00:00:00 2001 From: atlas Date: Thu, 15 Oct 2026 15:32:20 +0200 Subject: [PATCH] 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 --- nix/packages/reference-docs.nix | 59 +++++++++++++-------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/nix/packages/reference-docs.nix b/nix/packages/reference-docs.nix index b40aabb2..121a3ca8 100644 --- a/nix/packages/reference-docs.nix +++ b/nix/packages/reference-docs.nix @@ -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 (`../`, no specific file — - # forge's browser renders that as a directory listing today) becomes a - # sibling crates/.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 - # / -> docs/ was, so the leading docs/ segment drops) - # ../ (that crate's own directory, no file) - # -> ./.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 + # / -> docs/ was, so the leading docs/ segment drops) + # ../ (that crate's own directory, no file; forge + # renders it as a directory listing) -> ./.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 '';