Repository navigation
Closed as not planned
Description
Description
I'm not able to run opencode inside of WSL running NixOS:
Unstable:
nix run nixpkgs/nixos-unstable#opencode -- --version
zsh: segmentation fault nix run nixpkgs/nixos-unstable#opencode -- --version
Dev:
nix run github:anomalyco/opencode
error: Cannot build '/nix/store/hpl0fz47xs1bs9qfggv2g0v9yzrcbx2v-opencode-1.14.46+a780186.drv'.
Reason: builder failed with exit code 1.
Output paths:
/nix/store/nrsbqjxmr2f2jpvjq6ly9vi7nzvjarjv-opencode-1.14.46+a780186
Last 25 log lines:
> dist/assets/angular-ts-BwZT4LLn.js 183.87 kB │ gzip: 16.73 kB │ map: 249.42 kB
> dist/assets/vue-vine-8moa0y9V.js 190.27 kB │ gzip: 18.16 kB │ map: 255.24 kB
> dist/assets/wolfram-lXgVvXCa.js 262.44 kB │ gzip: 77.10 kB │ map: 279.68 kB
> dist/assets/session-CLdkD14I.js 528.86 kB │ gzip: 174.86 kB │ map: 1,979.63 kB
> dist/assets/wasm-CG6Dc4jp.js 622.38 kB │ gzip: 231.20 kB │ map: 622.93 kB
> dist/assets/cpp-CofmeUqb.js 626.12 kB │ gzip: 44.93 kB │ map: 816.15 kB
> dist/assets/ghostty-web-CmRTNB3y.js 652.83 kB │ gzip: 188.67 kB │ map: 793.29 kB
> dist/assets/emacs-lisp-C9XAeP06.js 779.90 kB │ gzip: 196.57 kB │ map: 789.84 kB
> dist/assets/index-BtCt3uoZ.js 1,787.77 kB │ gzip: 512.18 kB │ map: 7,132.59 kB
>
> (!) Some chunks are larger than 500 kB after minification. Consider:
> - Using dynamic import() to code-split the application
> - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
> - Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
> ✓ built in 12.13s
> building opencode-linux-x64
> Running smoke test: dist/opencode-linux-x64/bin/opencode --version
> Smoke test failed for opencode-linux-x64: ShellError: Failed with exit code 139
> exitCode: 139,
> stdout: "",
> stderr: "",
>
> at ShellPromise (unknown:75:16)
> at BunShell (unknown:191:35)
>
For full logs, run:
nix log /nix/store/hpl0fz47xs1bs9qfggv2g0v9yzrcbx2v-opencode-1.14.46+a780186.drv
(exit code 139 is segfault)
Stable is working tho:
nix run nixpkgs/nixos-25.11#opencode -- --version
1.1.14
Also using the non-nixos version from the https://opencode.ai/install script works fine
How can i debug this?
WSL:
uname -r
6.6.87.2-microsoft-standard-WSL2
Nix:
nix --version
nix (Nix) 2.34.7
NixOS:
nixos-version
26.05.20260505.549bd84 (Yarara)
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
NixOS 26.05
Terminal
Windows Terminal
Reacted by fjara-dimacofi, turtton, Yipeng Sun, nenw*, dannypritchard, Muhammad Asaduddin Hazazi, Horu, WoLeo-Z, Mauricio Scheffer, SoonHo Seo and 6 more
Metadata
Metadata
Assignees
Labels
No labels
Activity
yipengsun commentedon May 11, 2026
I'm having the same issue on NixOS + WSL.
janczarn commentedon May 11, 2026
I can also confirm this issue on NixOS in WSL.
fjararibet commentedon May 12, 2026
It's been happening for a while, I didn't catch it was a wsl issue. Version 1.4.3 is the latest one I got to work.
revert: downgrade nixpkgs-latest
mikebirdgeneau commentedon May 13, 2026
I just confirmed that v1.14.25 works for me narrowing down to between after v1.14.25 (working) and before v1.14.31 (failing)
alex-bartleynees commentedon Jun 6, 2026
I'm having the same issue with opencode on nixos-wsl too, works fine on my nixos desktop, some issue with the wsl kernel maybe?
OdysseusOperator commentedon Jun 10, 2026
Rolled back to 1.14.30, which works. So it is definetly something since version 1.14.31 acording to @alex-bartleynees post.
Just a simple
opencode --versionis enough for me to check if it is crashing.sonowz commentedon Jun 17, 2026
Looks like this is an issue of nixpkgs (or bun): NixOS/nixpkgs#520383
By the way I managed to create a workaround for segfault:
copy the
/tmp/opencode-fixedbinary somewhere to store itAdd opencode, pinned to nixos-25.11 on WSL
fix: patchelf opencode to fix glibc mismatch segfault on WSL2
🐛 bug: Corregir segfault de opencode con glibc 2.42 mediante overlay
Fix opencode WSL2 segfault in place instead of pinning stable
yuzow commentedon Aug 3, 2026
I hit this on NixOS+WSL2 and tracked down the root cause. Note Opus helped me debug this so take that as you will. It's an ELF layout problem in the built binary, and the WSL2 kernel is stricter about it than mainline.
opencode --version
1.18.4
uname -r
6.6.87.2-microsoft-standard-WSL2
nix --version
nix (Nix) 2.34.8
nixos-version
26.11.20260729.0954f7e (Zokor)
Root cause
The crash is in
ld.so, before any opencode code runs:That address is not arbitrary. It's a copy relocation target:
The binary's
PT_LOADsegments are not in ascendingp_vaddrorder — the 85MB.bunpayload segment is emitted first:The ELF spec requires
PT_LOADentries to be sorted byp_vaddr, and thekernel's ELF loader relies on that to size the
.bssmapping. With theordering wrong, the final page of
.bssnever gets mapped — and the threecopy relocations above land in exactly that page.
ld.sofaults on the firstone it writes.
Why it's WSL2-specific
Mainline kernels tolerate the bad ordering; the WSL2 kernel does not. That's
consistent with the package building and caching fine on Hydra while failing
on every WSL2 machine.
It also explains a detail worth knowing for anyone trying to debug this under
Nix: you cannot rebuild opencode locally on WSL2, because the build script's
own smoke test crashes:
That
dist/binary is pre-patchelf, straight out ofbun build --compile, sothe malformed layout is present the moment the executable is compiled — it is
not introduced by any later Nix-side patching. Since the install-script binary
reportedly works on WSL2, the released artifacts appear to have a correct
segment order, which suggests this comes from how the binary is compiled in
this build rather than from anything inherent to the released build. Running
the
readelf -lWcommand above against a release binary and a locallycompiled one would confirm that directly.
Fix / workaround
Rewriting the interpreter to the value it already has is semantically a no-op,
but it forces patchelf to regenerate the program header table, which emits the
segments correctly sorted:
(Thanks @sonowz!)
After that the
.bunsegment moves from first to last and the binary starts.Verified on 1.18.4 and reproduced identically on 1.18.11 (byte-identical
segment addresses, so version bumps alone won't help).
For nixpkgs users, this has to post-process the cached build rather than use
overrideAttrs, since any override triggers the local rebuild that fails thesmoke test above. The nixpkgs wrapper also hardcodes the original store path,
so the fixed inner binary needs a fresh wrapper.
A couple of questions for anyone who knows the build better than I do: is
emitting sorted program headers something that can be controlled at compile
time here, or is the post-hoc rewrite the practical route? And would a segment
ordering check be worth adding to the release pipeline? The existing smoke test
does catch this, but only on a kernel strict enough to fault, so it passes CI
and surfaces later on WSL2.
Happy to test any patch on a WSL2 box.
Moritz-Dorn commentedon Aug 4, 2026
hi,
Just had the same problem and also ran it down with Opus.
Confirming this on 1.18.12 with the readelf comparison you asked for, plus a
caveat about the patchelf workaround.
NixOS 25.05 (glibc 2.40), WSL2 kernel 6.6.87.2-microsoft-standard-WSL2.
Release vs. locally built: segment order
Release tarball (
opencode-linux-x64.tar.gz, v1.18.12),--versionworks:Locally built from the flake (same version, segfaults):
So the released artifacts do have correct ordering and the local build does
not — this comes from the build, not from the format. Fault address is
0x6510e40, byte-identical to your 1.18.4 and 1.18.11 despite a 178 MBpayload here vs. your 85 MB. Version bumps and payload size don't move it.
Also not glibc-dependent: forcing the binary through the older 2.40 loader
(
ld-linux-x86-64.so.2 <binary> --version) faults identically.Caveat: not every patchelf invocation is safe
--set-interpreterfixes it, but patchelf in general does not. Running--set-rpathon a working release binary breaks it:Different failure mode, not a re-ordering issue:
--set-rpath0x6510e400x495fd9c60Segment order stays correct after
--set-rpath(patchelf just prepends asegment at
0x1ff000for the new header table), and the fault is a read at anaddress outside every mapping, before TLS setup. Looks like shifted file
offsets invalidating Bun's recorded pointers into the appended blob — i.e. a
second, independent way to break these binaries. Both reproduce with identical
addresses across runs.
Worth flagging since the workaround is itself a patchelf call: it has to be
that specific no-op
--set-interpreterand nothing else.Alternative for Nix users
Skipping the local build entirely sidesteps both issues — fetch the release
tarball, keep patchelf away from it, and let nix-ld provide the interpreter:
with
programs.nix-ld.enable = true;. No local build, no post-processing of acached output, no wrapper rewrite. Running on WSL2 here.
github-actions commentedon Oct 5, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
kd2flz commentedon Oct 14, 2026
Is this really not going to be fixed upstream?