Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions nix/pkg/powerbrowser-bin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions nix/pkg/release-hash.json
Original file line number Diff line number Diff line change
@@ -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="
}
27 changes: 21 additions & 6 deletions scripts/verify-flake-repack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
// 1. the release key and version releaseIdentity() via scripts/lib/channel-identity.mjs;
// 2. the tarball URL and name <app>-<version>.<token>.tar.xz under /releases/download/<key>/,
// 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_<N> literal;
// carries the repack-only DisableAppUpdate merge; names x86_64-linux
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -309,7 +324,7 @@ function selfTest() {
},
{
name: 'control: placeholder stays green in the quick tier', expect: null,
overrides: { release: false },
overrides: { release: false, ...placeholderRecord },
},
];

Expand Down
Loading