You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for NixOS and/or Static linked binaries #462
Hey, I love this project, it is really the coolest coding agent in the terminal. However, I can't use it on my NixOS workstation machine because of the dynamic linking of the application. Here is how I install it:
The $HOME/.npm/node_module/bin is in my path, and there i install all my global NPM bins
When I run opencode I get the following error:
Could not start dynamically linked executable: opencode
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
So I'm not really sure what is the root of this issue, not even sure what is missing so I can run a patchelf on it to make it work. of course if you guys release a static build for Linux and detect NixOS and others and download that statically linked binary that would solve the issue.
enter the sell via nix develop (you might have to add it to git first because of flakes i guess git add flake.nix)
change scripts/hooks -- the shebang #!/bin/sh is not the "portable way of sh/bash shebangs"
#!/usr/bin/env bash
if [ ! -d ".git" ]; then
exit 0
fi
mkdir -p .git/hooks
cat >.git/hooks/pre-push <<'EOF'
#!/usr/bin/env bash
bun run typecheck
EOF
chmod +x .git/hooks/pre-push
echo "✅ Pre-push hook installed"
run bun install
now you have your dev version of opensource and can run bun run packages/opencode/src/index.ts
now you have opensource running (from source) in nixOS
to make it "usable for all the sourcode directories" you could set an alias alias opencode='nix develop /path/to/your/opencode --command bun run /path/to/your/opencode/packages/opencode/src/index.ts'
@thdxr i think the shebang change could be helpful for others and shouldn't risk the stability of the build - i just didn't find the time to do a PR
PS: the created binary did still not work because of nix vs. bun ... but i guess if a nix expert would face the same issue, it will be a matter of minutes/hours to provide a nix build
I no longer have the expression around but you can use autopatchelfhook to package the binary. You need to turn off elf stripping though because otherwise you remove the js code and just get the bun binary. You can give this prompt to Claude to reproduce the nix expression. Otherwise check out nix-ld.
If you're not married to the idea of building from source I have a flake that simply pulls the package from NPM. It's not well tested on anything but MacOS but it makes it simple to integrate with an existing flake based nix-darwin setup.
Update: Sorry just noticed you mentioned NixOS, I have a NixOS machine and will be testing this eventually. Just haven't gotten around to it.
You can also ask Claude to build the bun deps as an FOD and than it can use the to build the rest from source. Haven't tried that on this project specifically but on others.
In case anybody just wants something to paste into linux-x64 nixos config without using external flake (nothing wrong with that), here is my simple config:
thx @kittyandrew - but just fyi ... installing that way (i did change it to flake, but kept the steps as you described it), i got:
Could not start dynamically linked executable: opencode
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
edit: also tried it via pkgs - ended up with the same error
thx @kittyandrew - but just fyi ... installing that way (i did change it to flake, but kept the steps as you described it), i got:
Could not start dynamically linked executable: opencode
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
edit: also tried it via pkgs - ended up with the same error
hmm, I guess I'm too noob to understand why it works on my nixos machine, I just assumed it was a statically linked.
Well I spent a day trying replicate the above solutions into my own flake and did not get it working. But the PR to nixpkgs with v0.1.169 does work that alejandro posted. Thanks!
If you want to add this to your nixos configuration you can add that specific PR as an input (until it is merged officially) if you want it now like me
I have an update from my comment above. The main nixpkgs has been merged so unstable does have at least 0.1.194 in which is great!
You can use a normal pkgs.opencode if you track unstable and are fine with that version. But if you build your system on 25.05 (or older), you will need to overlay the unstable version (this is 1 way to use a later version in nix).
You can use unstable pkg in a 25.05 nixos build like so... (it is very similar to below so you can skip this if you want the latest)
This is the same as below but without the overrideAttrs and opencodeinput.
However this repo is FAST paced so if you also want to get the latest version like me, such as 0.2.13, then you can override the attributes of the unstable package with the latest source code. You will need to manually update hashes on every single new release, but this is at least how you do it for anyone wondering in nix.
You can see my use of it here if you looked at my last one as an example:
Seems like nixpkgs#opencode has transitioned from the opencode-ai/opencode to sst/opencode about 3 weeks ago and the error @itpropro is getting is because he is pulling the old version of the package. There have also been very recent updates (~2 hours ago) to nixpkgs that will take a day or two to arrive into nixpkgs-unstable which most people are using. You can already run the new update with following command, or modify your nixos configs to pull the package from nixpkgs-master if you are impatient. There's no need for flake in this repo imo, you can anyway update the version and hashes with the overlay method shown above.
It defaults to trying to cd into the opencode directory, if you specify a valid directory as the first argument it should work.
Yes, specifying a directory works. However, this is not the default behavior of opencode, but rather a peculiarity specific to Nix. So far, I haven't been able to determine the exact reason why.
@delafthi I installed opencode via nix and never had such issue until the latest version (0.6.3). so now need to run opencode . to tell it to open in current dir.
@delafthi I installed opencode via nix and never had such issue until the latest version (0.6.3). so now need to run opencode . to tell it to open in current dir.
Yes, this issue only appears since the update to 0.6.3. Forgot to mention that in my comment 🙈.
I figured out the source of the issue: it occurs when building (bun build) opencode with bun 1.2.21 (instead of previously 1.2.20). Bun 1.2.21 introduces --compile-exec-argv which has to be set to "--" to achieve the same behavior as before (see the changelog https://bun.sh/blog/bun-v1.2.21#embed-runtime-flags-into-standalone-executables-with-compile-exec-argv). Though, I'm not sure if this is the intended behavior of this flag.
If someone's looking for a hacky "impure" way to get this working without fiddling with overlays or custom packages (or relying on the sometimes broken nixpkgs); installing via npm then adding this to my nix config gets opencode running:
Activity
kajdo commentedon Jun 27, 2025
Hi,
was in the same situation and played around a bit. first docker which runs fine, but wasn't the fix i was looking for.
i did not find a way to package it (yet) because of bun and my lack of nixOS expertise. but maybe my workaround helps you a bit @shekohex
do a flake.nix for a development shell (within checked out opencode directory) ... if you aren't using flakes a shell.nix should work as well
enter the sell via
nix develop(you might have to add it to git first because of flakes i guessgit add flake.nix)change
scripts/hooks-- the shebang#!/bin/shis not the "portable way of sh/bash shebangs"run
bun installnow you have your dev version of opensource and can run
bun run packages/opencode/src/index.tsnow you have opensource running (from source) in nixOS
to make it "usable for all the sourcode directories" you could set an alias
alias opencode='nix develop /path/to/your/opencode --command bun run /path/to/your/opencode/packages/opencode/src/index.ts'@thdxr i think the shebang change could be helpful for others and shouldn't risk the stability of the build - i just didn't find the time to do a PR
PS: the created binary did still not work because of nix vs. bun ... but i guess if a nix expert would face the same issue, it will be a matter of minutes/hours to provide a nix build
Mic92 commentedon Jun 27, 2025
I no longer have the expression around but you can use autopatchelfhook to package the binary. You need to turn off elf stripping though because otherwise you remove the js code and just get the bun binary. You can give this prompt to Claude to reproduce the nix expression. Otherwise check out nix-ld.
AodhanHayter commentedon Jun 27, 2025
If you're not married to the idea of building from source I have a flake that simply pulls the package from NPM. It's not well tested on anything but MacOS but it makes it simple to integrate with an existing flake based nix-darwin setup.
Update: Sorry just noticed you mentioned NixOS, I have a NixOS machine and will be testing this eventually. Just haven't gotten around to it.
https://github.com/AodhanHayter/opencode-flake
Mic92 commentedon Jun 27, 2025
You can also ask Claude to build the bun deps as an FOD and than it can use the to build the rest from source. Haven't tried that on this project specifically but on others.
raulescobar-g commentedon Jun 28, 2025
very hacky and probably very bad build from source that works on nixos
any nix pro out there that can point out why it sucks ass, that would be great
https://github.com/raulescobar-g/opencode
Mic92 commentedon Jun 28, 2025
Well does upstream wants a flake.nix after all?
kittyandrew commentedon Jun 29, 2025
In case anybody just wants something to paste into linux-x64 nixos config without using external flake (nothing wrong with that), here is my simple config:
kajdo commentedon Jun 30, 2025
thx @kittyandrew - but just fyi ... installing that way (i did change it to flake, but kept the steps as you described it), i got:
edit: also tried it via pkgs - ended up with the same error
kittyandrew commentedon Jun 30, 2025
hmm, I guess I'm too noob to understand why it works on my nixos machine, I just assumed it was a statically linked.
alejandro-angulo commentedon Jun 30, 2025
There's an in-progress PR to get this packaged with nix NixOS/nixpkgs#419604
Hope I'm not adding noise but figured this would be relevant.
RingOfStorms commentedon Jul 1, 2025
Well I spent a day trying replicate the above solutions into my own flake and did not get it working. But the PR to nixpkgs with v0.1.169 does work that alejandro posted. Thanks!
If you want to add this to your nixos configuration you can add that specific PR as an input (until it is merged officially) if you want it now like me
https://git.joshuabell.xyz/ringofstorms/dotfiles/src/branch/master/common/flake.nix#L8
https://git.joshuabell.xyz/ringofstorms/dotfiles/src/branch/master/common/flake.nix#L29-L38
Then you can do a normal
environment.systemPackages = [ pkgs.opencode ];RingOfStorms commentedon Jul 9, 2025
I have an update from my comment above. The main nixpkgs has been merged so unstable does have at least 0.1.194 in which is great!
You can use a normal
pkgs.opencodeif you track unstable and are fine with that version. But if you build your system on 25.05 (or older), you will need to overlay the unstable version (this is 1 way to use a later version in nix).You can use unstable pkg in a 25.05 nixos build like so... (it is very similar to below so you can skip this if you want the latest)
This is the same as below but without the
overrideAttrsandopencodeinput.However this repo is FAST paced so if you also want to get the latest version like me, such as 0.2.13, then you can override the attributes of the unstable package with the latest source code. You will need to manually update hashes on every single new release, but this is at least how you do it for anyone wondering in nix.
You can see my use of it here if you looked at my last one as an example:
A simplified flake containing a nixos config
The important overlay part of the below nix
Or if you just have nixos-unstable system you can simplify a bit from below.
itpropro commentedon Jul 17, 2025
This didn't work for me unfortunately, as it constantly says
Doosty commentedon Jul 21, 2025
Seems like nixpkgs#opencode has transitioned from the
opencode-ai/opencodetosst/opencodeabout 3 weeks ago and the error @itpropro is getting is because he is pulling the old version of the package. There have also been very recent updates (~2 hours ago) to nixpkgs that will take a day or two to arrive into nixpkgs-unstable which most people are using. You can already run the new update with following command, or modify your nixos configs to pull the package from nixpkgs-master if you are impatient. There's no need for flake in this repo imo, you can anyway update the version and hashes with the overlay method shown above.10 remaining items
Parsifa1 commentedon Aug 16, 2025
For this frequently updated software, if you want to install it directly from
nixosusingpnpm/npmlike I did, usenix-ld.just add these pieces into your nixos config,
librariesare those libs your executable may use.no need to always wait nixpkgs to upgrade.
pulpo commentedon Sep 3, 2025
I was using opencode with the @Doosty approach, but with the new updates I have problems:
Anyone with the same problem?
coredev-uk commentedon Sep 3, 2025
It defaults to trying to cd into the opencode directory, if you specify a valid directory as the first argument it should work.
delafthi commentedon Sep 4, 2025
Yes, specifying a directory works. However, this is not the default behavior of opencode, but rather a peculiarity specific to Nix. So far, I haven't been able to determine the exact reason why.
pulpo commentedon Sep 5, 2025
Ok, following @coredev-uk suggestion,
nix run github:nixos/nixpkgs#opencode -- .did the trick.nickkadutskyi commentedon Sep 5, 2025
@delafthi I installed opencode via nix and never had such issue until the latest version (0.6.3). so now need to run
opencode .to tell it to open in current dir.delafthi commentedon Sep 6, 2025
Yes, this issue only appears since the update to 0.6.3. Forgot to mention that in my comment 🙈.
nickkadutskyi commentedon Sep 6, 2025
@delafthi btw I tested it with regular npm install and it works in 0.6.3 version as expected #2269 (comment)
delafthi commentedon Sep 6, 2025
I figured out the source of the issue: it occurs when building (
bun build) opencode with bun 1.2.21 (instead of previously 1.2.20). Bun 1.2.21 introduces--compile-exec-argvwhich has to be set to"--"to achieve the same behavior as before (see the changelog https://bun.sh/blog/bun-v1.2.21#embed-runtime-flags-into-standalone-executables-with-compile-exec-argv). Though, I'm not sure if this is the intended behavior of this flag.opencode: fix `failed to change directory` error
colout commentedon Sep 6, 2025
If someone's looking for a hacky "impure" way to get this working without fiddling with overlays or custom packages (or relying on the sometimes broken nixpkgs); installing via npm then adding this to my nix config gets opencode running:
(though I've generally just been running in container anyway for saftey)
rekram1-node commentedon Dec 28, 2025
[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!
docs: add Antigravity setup and usage guide (anomalyco#552)
Merge pull request anomalyco#462 from different-ai/feat/openwrk-tui-c…