Repository navigation
fix(nix): launch the electron-builder binary that carries the app fuses - #65545
jerome-benoit wants to merge 5 commits into
Conversation
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.
There was a problem hiding this comment.
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
| # 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 |
There was a problem hiding this comment.
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,libgbmand others aren't inbuildInputs, so the build likely fails with "could not satisfy dependency".- If it gets through, the nixpkgs
electronLibPathRUNPATH is replaced. That drops libraries Electron loads at runtime that aren't inDT_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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Full Linux build done on
Post-build verification on the store output:
Caveat kept from earlier: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Issue for this PR
Closes #
No dedicated issue. This is the Nix follow-up to #63002, which added the
enableCookieEncryptionfuse (#63611 was folded into it). The Nix Linux package never ran the binary the fuse was flipped on.Type of change
What does this PR do?
On Linux,
nix/desktop.nixinstalled onlyresourcesfrom the electron-builder output and wrapped the stock nixpkgs Electron. electron-builder flips the fuses on the executable indist/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*-unpackeddirectory and wraps the single executable at its root:electron.dist: library, sandbox-helper and crashpad resolution in the store is unchanged.appId, which Nix cannot know, so it is discovered from the exec bits at the unpacked root, with a "exactly one" guard.XDG_DATA_DIRS,GSETTINGS_SCHEMA_PATHviawrapGAppsHook3) are applied directly and the GTK environment is preserved.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.appand is unchanged. No fuse list is duplicated in Nix:electron-builder.config.tsstays the single source.How did you verify your code works?
Built
c2761b7on x86_64 Linux using the dependency hash from #60957 as a local override. The same x86_64 hash has since landed ondevin #65598; this PR does not modify dependency hashes.ai.opencodewith--ozone-platform=waylandand--enable-wayland-ime=true. The app created a Wayland window and presented a buffer.EnableCookieEncryptionis enabled. Cookie writes with a real keyring were not tested.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
Added by the opencode bot (AI-generated).
Related: #52122