Skip to content

fix(nix): launch the electron-builder binary that carries the app fuses - #65545

Open
jerome-benoit wants to merge 5 commits into
anomalyco:devfrom
jerome-benoit:desktop-fuses
Open

jerome-benoit wants to merge 5 commits into
anomalyco:devfrom
jerome-benoit:desktop-fuses

Conversation

@jerome-benoit

@jerome-benoit jerome-benoit commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

No dedicated issue. This is the Nix follow-up to #63002, which added the enableCookieEncryption fuse (#63611 was folded into it). The Nix Linux package never ran the binary the fuse was flipped on.

Type of change

  • Bug fix

What does this PR do?

On Linux, nix/desktop.nix installed only resources from the electron-builder output and wrapped the stock nixpkgs Electron. electron-builder flips the fuses on the executable in dist/linux*-unpacked/, so the installed app launched an unfused binary and browser-pane cookies stayed plain text.

The package now installs the whole dist/linux*-unpacked directory and wraps the single executable at its root:

  • The fuse flip rewrites bytes in place, so the installed binary keeps the nixpkgs interpreter and RUNPATH baked from electron.dist: library, sandbox-helper and crashpad resolution in the store is unchanged.
  • The executable name comes from electron-builder's channel appId, which Nix cannot know, so it is discovered from the exec bits at the unpacked root, with a "exactly one" guard.
  • The target is no longer nixpkgs' own Electron wrapper, so the gapps wrapper args (XDG_DATA_DIRS, GSETTINGS_SCHEMA_PATH via wrapGAppsHook3) are applied directly and the GTK environment is preserved.
  • Flags (app.asar, Wayland/Ozone, ELECTRON_FORCE_IS_PACKAGED), sandbox file and modes, icons, metainfo, the bundled CLI and native modules are untouched. Darwin installs the full .app and is unchanged. No fuse list is duplicated in Nix: electron-builder.config.ts stays the single source.

How did you verify your code works?

Built c2761b7 on x86_64 Linux using the dependency hash from #60957 as a local override. The same x86_64 hash has since landed on dev in #65598; this PR does not modify dependency hashes.

  • The installed launcher is a shell wrapper. Under headless Weston, it launched ai.opencode with --ozone-platform=wayland and --enable-wayland-ime=true. The app created a Wayland window and presented a buffer.
  • The wrapped binary retains the nixpkgs RUNPATH, including libsecret. The Electron fuse reader confirms EnableCookieEncryption is enabled. Cookie writes with a real keyring were not tested.
  • ARM Linux and macOS were evaluated on earlier revisions, not built or run.

Screenshots / recordings

No UI change.

A combined Linux x86_64 build of #60683, #59403 and #65545 also passed without a dependency hash override. Desktop opened a Wayland surface and registered service-prod.json.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #52122

electron-builder flips the Electron fuses (enableCookieEncryption among them) on the executable it produces, but on Linux the Nix package installed only the unpacked resources and launched the stock nixpkgs Electron, so the packaged app never ran the binary carrying that configuration. The fuses are one-way build settings, so the flipped executable is the only one that can provide cookie encryption.

Install the full linux*-unpacked output and wrap its executable. The fuse flip rewrites bytes in place, so the binary keeps nixpkgs' patched interpreter and RUNPATH from electron.dist and still resolves every library, sandbox helper layout, native module and bundled CLI from the store unchanged. The wrapper now applies nixpkgs' gapps wrapper args directly, preserving the GSettings environment the nixpkgs Electron wrapper used to export. The app.asar path and Wayland flags are untouched.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't verify this: building it needs Nix, and the sandbox doesn't have it. The description also says it was only evaluated, never built. Reading the code against current nixpkgs, I expect one blocking problem: autoPatchelfHook now runs over the whole copied Electron tree, so the claim that the binary keeps nixpkgs' RUNPATH won't hold. Details are in the inline comment. Please build .#opencode-desktop on Linux and run npx @electron/fuses read on the binary the wrapper points to. Please also check its RUNPATH with patchelf --print-rpath and confirm that the browser pane writes cookies with libsecret available.

Public API: unchanged. This only touches Nix packaging.

The executable lookup, the gapps wrapper arguments and the resources path rewrite all look right to me.

Related: #52122

Comment thread nix/desktop.nix
# binary keeps nixpkgs' patched interpreter and RUNPATH from electron.dist
# and still resolves every library from the store as before.
mkdir -p $out/opt
cp -r dist/linux*-unpacked $out/opt/opencode-desktop

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying the whole unpacked tree into $out means the fixup step's autoPatchelfHook now patches the Electron binary and chrome_crashpad_handler too, not just resources. auto-patchelf.py doesn't read a file's existing RUNPATH. It looks up each DT_NEEDED library among buildInputs (and the RPATHs of .so files it finds), then runs patchelf --set-rpath with whatever it found. As a result:

  • libnss3, libasound, libcups, libdbus, libdrm, libgbm and others aren't in buildInputs, so the build likely fails with "could not satisfy dependency".
  • If it gets through, the nixpkgs electronLibPath RUNPATH is replaced. That drops libraries Electron loads at runtime that aren't in DT_NEEDED: libGL, vulkan, pipewire, pulseaudio and libsecret. libsecret is what cookie encryption uses to reach the keyring.

One way to keep the binary as nixpkgs patched it is dontAutoPatchelf = true; plus autoPatchelf $out/opt/opencode-desktop/resources in postFixup, so only the bundled CLI and native modules get patched as before. Either way, a real Linux build is needed before merging.

If nothing matches, wc -l <<<"" still prints 1, so this guard passes. The build then fails later in makeWrapper with an unclear empty-path error. Checking [ -n "$desktop_exe" ] as well would make the guard do what it says.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both fixed in 95ee52c.

dontAutoPatchelf = true plus autoPatchelf $out/opt/opencode-desktop/resources in postFixup, exactly as suggested. That is also precisely the file set the hook covered before this PR (the unpacked tree used to contribute only resources to $out; the bin wrapper is a shell script), so the Electron binary, sandbox and crashpad helpers keep the RUNPATH nixpkgs baked into electron.dist byte-for-byte, libsecret included.

The guard now also requires a non-empty desktop_exe: wc -l <<<"" prints 1, so the empty-find case failed with the wrong message; it fails with the intended one now.

A full nix build .#packages.x86_64-linux.opencode-desktop is running now; I will report the fuse read on the binary the wrapper resolves to and the autoPatchelf scope when it finishes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both look right in 95ee52c. Scoping autoPatchelf to resources covers the same files the hook patched before this PR, so the Electron binary, chrome-sandbox and chrome_crashpad_handler keep the RUNPATH from electron.dist. The test -n guard also handles the empty case now.

I can't build it here, so the results from your Linux build are what's left to confirm. Please post the npx @electron/fuses read output for the binary the wrapper points to and patchelf --print-rpath on it (it should still list libsecret). A cookie write in the browser pane with a keyring available would help too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified cookie writes and reads in the actual packaged browser pane on x86_64 Linux (combined Nix build of #60683, #59403 and #65545 at c2761b7). I used a disposable profile, a private D-Bus session, and an unlocked GNOME Keyring. Secret Service showed a new OpenCode Safe Storage item.

A loopback HTTP server set a persistent HttpOnly cookie. In Partitions/opencode-browser/Cookies, the row had an empty value, a 99-byte encrypted_value starting with v11, and is_persistent=1. After a full Desktop quit and restart, the server received the same cookie on /check with no new /set request.

The wrapper targets opt/opencode-desktop/ai.opencode. @electron/fuses read --app reports EnableCookieEncryption is Enabled; patchelf --print-rpath on that binary includes libsecret-0.21.8.2/lib.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing this with a real keyring. The cookie row stored as v11 ciphertext with an empty value, plus the OpenCode Safe Storage item and the cookie surviving a restart, is the end-to-end check I was missing. I can't reproduce it without Nix.

One caveat: the build combined this PR with #60683 and #59403. If you can, please confirm that the wrapper target, the fuse read and the libsecret RUNPATH entry come out the same when you build this branch alone (with the hash override). That way the result doesn't depend on those two PRs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on #65545 alone at c2761b7 (x86_64 Linux, with only the local dependency hash override; neither #60683 nor #59403 was included). The installed shell wrapper executes opt/opencode-desktop/ai.opencode. On that target, @electron/fuses read --app reports EnableCookieEncryption is Enabled and RunAsNode is Disabled. The ELF RUNPATH has all 36 original entries, including libsecret-0.21.8.2/lib. The standalone artifact also opened a Wayland window under Weston. The cookie round-trip in the previous reply was on the combined build.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that answers my question. The standalone build at c2761b7 matches the combined one where it counts: the wrapper launches ai.opencode, EnableCookieEncryption is on, RunAsNode is off, and the RUNPATH keeps all 36 entries including libsecret. So the encrypted cookie round-trip from the combined build doesn't depend on #60683 or #59403. I have nothing further on this thread.

autoPatchelf rewrites the RUNPATH of every ELF it scans, so installing the
full unpacked tree made it clobber the library path nixpkgs baked into
electron.dist. That path covers DT_NEEDED entries absent from buildInputs
(libnss3, libasound, ...) and runtime dlopen()s a scan cannot see (libGL,
pipewire, libsecret, which cookie encryption uses for the keyring). Skip the
automatic pass and run autoPatchelf on resources/ only, which is exactly the
set the hook used to cover.

Also require a non-empty desktop_exe in the single-executable guard: wc -l
prints 1 for empty input, so an empty find result passed the guard and failed
later in makeWrapper.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier points are fixed. autoPatchelf now patches only resources, so the Electron binary, chrome-sandbox and chrome_crashpad_handler keep their library path (RUNPATH) from nixpkgs, libsecret included. The executable guard also rejects an empty result now. I couldn't verify a build because the sandbox has no Nix. A Linux build is still needed: please post the npx @electron/fuses read output and patchelf --print-rpath for the binary the wrapper points to.

Public API: unchanged. This only touches Nix packaging.

No new concerns.

…ixup

Two nixpkgs-drift fixes needed to build the Linux Desktop output:

script/build.ts bundles the prod CLI from packages/cli/dist and hard-fails
otherwise; the OPENCODE_CLI_DIST export it was written against belongs to the
retired scripts/prebuild.ts and is read by nothing. Stage the Nix-built CLI at
the path the build actually reads.

patchelf's setup hook runs --shrink-rpath over every ELF in $out, which cut the
Electron binary's RUNPATH from 36 store paths to 23, dropping the libraries
Electron only dlopen()s: libGL, vulkan, pipewire, pulseaudio and libsecret, the
last being how cookie encryption reaches the keyring. dontPatchELF keeps the
RUNPATH nixpkgs baked into electron.dist whole; autoPatchelf in postFixup still
patches the bundled CLI and native modules.

Verified with a full build: the wrapper resolves to ai.opencode, its RUNPATH is
byte-identical to electron.dist, and @electron/fuses read on the packaged binary
reports EnableCookieEncryption enabled, RunAsNode and
EnableNodeCliInspectArguments disabled.
@jerome-benoit

Copy link
Copy Markdown
Contributor Author

Full Linux build done on 300a3a0: nix build .#packages.x86_64-linux.opencode-desktop. Two more blockers surfaced, both pre-existing nix drift, both fixed in 300a3a0:

  • script/build.ts hard-fails unless the prod CLI is staged in packages/cli/dist. The OPENCODE_CLI_DIST the Nix build exported belongs to the retired scripts/prebuild.ts and is read by nothing, so the Linux drv could not build at all on dev. The CLI is now staged where the build reads it.
  • The patchelf setup hook ran --shrink-rpath over the installed Electron binary and cut its RUNPATH from 36 store paths to 23, dropping exactly the dlopen-only set: libGL, vulkan, pipewire, pulseaudio, libsecret. Cookie encryption needs libsecret for the keyring. dontPatchELF = true keeps the nixpkgs RUNPATH whole; the scoped autoPatchelf resources still patches the bundled CLI and native modules.

Post-build verification on the store output:

  • bin/opencode-desktop is the generated binary wrapper; it execs opt/opencode-desktop/ai.opencode with the app.asar flag, ELECTRON_FORCE_IS_PACKAGED, and the gsettings/XDG_DATA_DIRS args (make-shell-wrapper-hook folded my installPhase script into it).
  • patchelf --print-rpath on ai.opencode is byte-identical to electron.dist/libexec/electron/electron (36/36 entries).
  • @electron/fuses read on the packaged binary: EnableCookieEncryption Enabled, RunAsNode Disabled, EnableNodeCliInspectArguments Disabled - the prod fuse config from electron-builder.config.ts, on the binary that now actually launches.

Caveat kept from earlier: nix/hashes.json on dev is stale after the Nov 19 nixpkgs bump (bun 1.4.4); the up-to-date values are in the open bot PR #60957, whose x86_64 hash matched my local build hash byte-for-byte. This branch changes no dependency inputs, so no hash is included here.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit looks right. dontPatchELF = true keeps the patchelf hook from shrinking the Electron binary's RUNPATH, which would otherwise drop libraries Electron loads at runtime (libGL, vulkan, pipewire, pulseaudio, libsecret). Staging the CLI in ../cli/dist matches where script/build.ts reads it on the latest dev. Nothing reads OPENCODE_CLI_DIST any more, so the Nix desktop build was already failing on dev. That bug predates this PR, but this build needs the fix. I couldn't build it myself because the sandbox has no Nix; the RUNPATH and fuse results come from your build.

Public API: unchanged. This only touches Nix packaging.

No new concerns.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commits look right. Switching to makeShellWrapper makes the NIXOS_OZONE_WL/WAYLAND_DISPLAY flags expand when the app starts. The compiled wrapper that wrapGAppsHook3 brings in would have passed them as literal text. --ozone-platform=wayland is a reasonable explicit choice when the user opts in. The CLI staging cleanup behaves the same as before. I couldn't build or launch it because the sandbox has no Nix.

Public API: unchanged. This only touches Nix packaging.

No new concerns.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant