From 20ed122d2e82cf2d2ae7708de869aabb6ec70242 Mon Sep 17 00:00:00 2001 From: Christopher Colantuono Date: Fri, 27 Nov 2026 12:58:49 -0800 Subject: [PATCH] fix(nix): flake hash for v153.5.1-1; the repack no longer rewrites Mozilla's libraries The first published release's flake package crashed at start (SIGSEGV in a library constructor during dlopen): autoPatchelfHook, patchELF and strip rewrote the Mozilla libraries and corrupted their packed relocations. The derivation now sets only each executable's interpreter and puts the linked and dlopen libraries on the wrapper's LD_LIBRARY_PATH (list derived by ldd over every ELF file outside any FHS environment: 0 unresolved). Verified: nix build .#powerbrowser, --version, and a headless start reaching SHELL_READY and BACKEND_READY. flake-repack rules and plants follow. The hash record is the SRI of the published tarball, equal to the release's SHA256SUMS entry (what the not-yet-wired flake-hash-pr bot would write). Co-Authored-By: Claude Opus 5.5 --- nix/pkg/powerbrowser-bin.nix | 61 +++++++++++++++++++++++++++++---- nix/pkg/release-hash.json | 3 +- scripts/verify-flake-repack.mjs | 27 +++++++++++---- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/nix/pkg/powerbrowser-bin.nix b/nix/pkg/powerbrowser-bin.nix index b39ba6f8..70a5d283 100644 --- a/nix/pkg/powerbrowser-bin.nix +++ b/nix/pkg/powerbrowser-bin.nix @@ -10,14 +10,30 @@ lib, stdenv, fetchurl, - autoPatchelfHook, + patchelf, makeWrapper, copyDesktopItems, jq, # The flake's Node binding, passed in by flake.nix. It is the sidecar's PATH fallback only (see the wrapper below). nodejs, - # The libraries the binaries link against (DT_NEEDED), which autoPatchelfHook resolves from buildInputs. + # The libraries the binaries link against (DT_NEEDED); the wrapper puts them on LD_LIBRARY_PATH. gtk3, + glib, + pango, + cairo, + gdk-pixbuf, + atk, + libxrandr, + libxi, + libxfixes, + libxdamage, + libxcursor, + libxcomposite, + libxcb, + libxrender, + freetype, + fontconfig, + dbus, libx11, libxext, libdbusmenu-gtk3, @@ -82,8 +98,27 @@ let alsa-lib ]; # stdenv.cc.cc.lib is libstdc++, which the Gecko binaries and the staged Node link against. + # The libraries the tarball's ELF files name in DT_NEEDED, resolved through the wrapper's + # LD_LIBRARY_PATH (nothing is patched; see dontAutoPatchelf). The list was derived by running ldd + # over every ELF file of the v153.5.1-1 repack outside any FHS environment. runtimeLibs = [ gtk3 + glib + pango + cairo + gdk-pixbuf + atk + libxrandr + libxi + libxfixes + libxdamage + libxcursor + libxcomposite + libxcb + libxrender + freetype + fontconfig + dbus libx11 libxext libdbusmenu-gtk3 @@ -108,8 +143,16 @@ stdenv.mkDerivation { dontBuild = true; dontConfigure = true; + # No ELF file of the tarball is rewritten except each executable's interpreter. Rewriting Mozilla's + # libraries (autoPatchelfHook, the stdenv patchELF and strip steps) corrupted their packed + # relocations: the first release v153.5.1-1 repacked that way crashed in a library constructor + # during dlopen (SIGSEGV in _dl_init). The libraries resolve through LD_LIBRARY_PATH instead. + dontAutoPatchelf = true; + dontPatchELF = true; + dontStrip = true; + nativeBuildInputs = [ - autoPatchelfHook + patchelf makeWrapper copyDesktopItems jq @@ -128,12 +171,18 @@ stdenv.mkDerivation { jq '.policies.DisableAppUpdate = true' "$policies" > "$policies.tmp" mv "$policies.tmp" "$policies" - # The sidecar runs on the tarball's own staged node/bin/node, which autoPatchelfHook patches with the rest of the ELF - # files; TheiaService falls back to the first node on PATH only when that file is absent, and nodejs (the flake + # The sidecar runs on the tarball's own staged node/bin/node, whose interpreter is set below with the other executables; TheiaService falls back to the first node on PATH only when that file is absent, and nodejs (the flake # Node binding) is what the wrapper puts there. LD_LIBRARY_PATH carries the dlopen'd libraries. + # Each ELF executable (it has a PT_INTERP) gets the store's dynamic loader; nothing else in the file changes. + while IFS= read -r -d "" f; do + if [ "$(head -c 4 "$f" | od -An -tx1 | tr -d ' ')" = "7f454c46" ] && patchelf --print-interpreter "$f" >/dev/null 2>&1; then + patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$f" + fi + done < <(find $out/lib/powerbrowser -type f -perm -u+x -print0) + makeWrapper $out/lib/powerbrowser/powerbrowser $out/bin/powerbrowser \ --prefix PATH : ${lib.makeBinPath [ nodejs ]} \ - --prefix LD_LIBRARY_PATH : ${dlopenPath} + --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibs}:${dlopenPath} # The tracked release desktop entry, with its checkout-root placeholders rewritten to the store paths. desktop=$out/share/applications/powerbrowser.desktop diff --git a/nix/pkg/release-hash.json b/nix/pkg/release-hash.json index 4d620c01..9dcec580 100644 --- a/nix/pkg/release-hash.json +++ b/nix/pkg/release-hash.json @@ -1,5 +1,4 @@ { "releaseKey": "v153.5.1-1", - "sha256": "sha256-UExBQ0VIT0xERVItRElTVDEyLUJPVC1QUi1GSUxMTUU=", - "state": "placeholder: decodes to PLACEHOLDER-DIST12-BOT-PR-FILLME; the DIST-12 bot PR (channel-manifests.yml flake-hash-pr) replaces it with the SRI hash of the published asset, and verify-flake-repack.mjs --release refuses it until then" + "sha256": "sha256-YBL03tSV1Q/yFGzXf8CDFiQnZUptwglFA2MAb61DQyo=" } diff --git a/scripts/verify-flake-repack.mjs b/scripts/verify-flake-repack.mjs index 4162af65..dfbf8389 100644 --- a/scripts/verify-flake-repack.mjs +++ b/scripts/verify-flake-repack.mjs @@ -7,7 +7,9 @@ // 1. the release key and version releaseIdentity() via scripts/lib/channel-identity.mjs; // 2. the tarball URL and name -..tar.xz under /releases/download//, // with the token the first Target key of docs/RELEASING.md's table; -// 3. the derivation shape nix/pkg/powerbrowser-bin.nix uses fetchurl, autoPatchelfHook, +// 3. the derivation shape nix/pkg/powerbrowser-bin.nix uses fetchurl, sets only each executable's +// interpreter (no autoPatchelfHook, patchELF or strip: they corrupt +// Mozilla's packed relocations, first release v153.5.1-1), wrapper LD_LIBRARY_PATH, // makeWrapper and copyDesktopItems; builds nothing (dontBuild); // takes the flake's nodejs binding and never a nodejs_ literal; // carries the repack-only DisableAppUpdate merge; names x86_64-linux @@ -85,14 +87,17 @@ export function runChecks(root, overrides = {}) { } else { const required = [ [/\bfetchurl\b/, 'fetchurl fetches the tarball'], - [/\bautoPatchelfHook\b/, 'autoPatchelfHook rewrites the ELF interpreter and rpath'], + [/dontAutoPatchelf\s*=\s*true/, 'dontAutoPatchelf = true (rewriting the Mozilla libraries corrupts their packed relocations)'], + [/dontPatchELF\s*=\s*true/, 'dontPatchELF = true (the stdenv rpath shrink rewrites every ELF file)'], + [/dontStrip\s*=\s*true/, 'dontStrip = true (strip rewrites every ELF file)'], + [/patchelf --set-interpreter/, 'each executable gets the store dynamic loader'], [/\bmakeWrapper\b/, 'makeWrapper wraps the launcher'], [/\bcopyDesktopItems\b/, 'copyDesktopItems is in nativeBuildInputs'], [/dontBuild\s*=\s*true/, 'dontBuild = true (the derivation compiles nothing)'], [/\.policies\.DisableAppUpdate\s*=\s*true/, 'the repack-only DisableAppUpdate merge'], [/releases\/download\/\$\{releaseKey\}\/\$\{tarball\}/, 'the tarball URL built from the release key and the derived tarball name'], [/makeBinPath \[ nodejs \]/, 'the sidecar PATH takes the flake nodejs binding'], - [/--prefix LD_LIBRARY_PATH : \$\{dlopenPath\}/, 'the wrapper puts the dlopen libraries on LD_LIBRARY_PATH, as the nixpkgs firefox wrapper does (WR-08)'], + [/--prefix LD_LIBRARY_PATH : \$\{lib\.makeLibraryPath runtimeLibs\}:\$\{dlopenPath\}/, 'the wrapper puts the linked and the dlopen libraries on LD_LIBRARY_PATH, as the nixpkgs firefox wrapper does (WR-08)'], [/stdenv\.cc\.cc\.lib/, 'libstdc++ (stdenv.cc.cc.lib) in the runtime libraries'], [/platforms\s*=\s*\[\s*"x86_64-linux"\s*\]/, 'platforms is x86_64-linux only'], [/release-hash\.json/, 'the hash comes from the tracked hash record'], @@ -227,6 +232,8 @@ function selfTest() { const base = diskReader(REPO_ROOT); const { facts } = deriveChannel(REPO_ROOT, base); const neighbour = neighbourKey(facts.releaseKey); + // The tracked record holds a real hash once a release is published, so the placeholder cases plant it. + const placeholderRecord = { read: r => (r === RELEASE_HASH_REL ? `${JSON.stringify({ releaseKey: facts.releaseKey, sha256: SENTINEL_SRI }, null, 2)}\n` : base(r)) }; const withPlant = (rel, transform) => { const original = base(rel); const planted = transform(original); @@ -245,7 +252,7 @@ function selfTest() { }, { name: 'placeholder hash refused under --release', expect: RELEASE_HASH_REL, - overrides: { release: true }, + overrides: { release: true, ...placeholderRecord }, }, { name: 'nodejs_22 sidecar literal', expect: 'nodejs_22', @@ -265,7 +272,15 @@ function selfTest() { }, { name: 'wrapper without the dlopen LD_LIBRARY_PATH prefix (WR-08)', expect: 'LD_LIBRARY_PATH', - overrides: withPlant(DERIV_REL, t => t.replace(' \\\n --prefix LD_LIBRARY_PATH : ${dlopenPath}', '')), + overrides: withPlant(DERIV_REL, t => t.replace(' \\\n --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibs}:${dlopenPath}', '')), + }, + { + name: 'automatic ELF patching switched back on', expect: 'dontAutoPatchelf', + overrides: withPlant(DERIV_REL, t => t.replace('dontAutoPatchelf = true;', 'dontAutoPatchelf = false;')), + }, + { + name: 'strip switched back on', expect: 'dontStrip', + overrides: withPlant(DERIV_REL, t => t.replace('dontStrip = true;', '')), }, { name: 'libstdc++ dropped from the runtime libraries', expect: 'stdenv.cc.cc.lib', @@ -309,7 +324,7 @@ function selfTest() { }, { name: 'control: placeholder stays green in the quick tier', expect: null, - overrides: { release: false }, + overrides: { release: false, ...placeholderRecord }, }, ];