make opencode work w/ NixOS #2339

Closed
opened 2026-02-16 17:35:12 -05:00 by yindo · 11 comments
Owner

Originally created by @pmarreck on GitHub (Oct 29, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

Installed OpenCode via 'npm install -g --prefix "$HOME/.local" opencode-ai@latest'.

Ran it and got this:

bash> opencode
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

There is an "opencode" on nixpkgs but it is an extremely old version at this point.

Making assumptions about what's available on a linux install at runtime just because you're running on "a linux" is bad design. Neither codex nor gemini nor claude (all of which I have installed identically to the method above; they're available on nixpkgs, but the above method keeps them always at the bleeding edge) make this assumption and all run just fine.

Even better, perhaps someone should update the version on nixpkgs on a more regular basis, but none of the others do that either, so that's probably a big ask. ;)

https://search.nixos.org/packages?channel=25.05&show=opencode&query=opencode

OpenCode version

Latest

Steps to reproduce

  1. be on the ultimate linux distro, NixOS
  2. install opencode using npm
  3. try to run it

Screenshot and/or share link

No response

Operating System

NixOS 25.05

Terminal

Wezterm

Originally created by @pmarreck on GitHub (Oct 29, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description Installed OpenCode via 'npm install -g --prefix "$HOME/.local" opencode-ai@latest'. Ran it and got this: ```bash bash> opencode 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 ``` There is an "opencode" on nixpkgs but it is an extremely old version at this point. Making assumptions about what's available on a linux install at runtime just because you're running on "a linux" is bad design. Neither `codex` nor `gemini` nor `claude` (all of which I have installed identically to the method above; they're available on nixpkgs, but the above method keeps them always at the bleeding edge) make this assumption and all run just fine. Even better, perhaps someone should update the version on nixpkgs on a more regular basis, but none of the others do that either, so that's probably a big ask. ;) https://search.nixos.org/packages?channel=25.05&show=opencode&query=opencode ### OpenCode version Latest ### Steps to reproduce 1. be on the ultimate linux distro, NixOS 2. install opencode using npm 3. try to run it ### Screenshot and/or share link _No response_ ### Operating System NixOS 25.05 ### Terminal Wezterm
yindo added the help-wantedbug labels 2026-02-16 17:35:12 -05:00
yindo closed this issue 2026-02-16 17:35:12 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 29, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #3045: Similar dynamic linking issue with GLIBC compatibility across different Linux distributions
  • #3501: Related installation issue where OpenCode makes assumptions about available Linux tools
  • #3282: Linux distribution-specific installation issue related to glibc compatibility

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 29, 2025): This issue might be a duplicate of existing issues. Please check: - #3045: Similar dynamic linking issue with GLIBC compatibility across different Linux distributions - #3501: Related installation issue where OpenCode makes assumptions about available Linux tools - #3282: Linux distribution-specific installation issue related to glibc compatibility Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 29, 2025):

yeah we should fix this

@rekram1-node commented on GitHub (Oct 29, 2025): yeah we should fix this
Author
Owner

@xamcost commented on GitHub (Oct 29, 2025):

I know it doesn't answer @pmarreck 's original question, but an opencode service is available in home-manager. I use this config, and it works like a charm:

{
  home.file = {
    ".config/opencode/agent/".source = ../../dotfiles/config/opencode/agent;
  };

  programs.opencode = {
    enable = true;
    settings = {
      theme = "tokyonight";
      autoupdate = true;
      mcp = {
        context7 = {
          type = "remote";
          url = "https://mcp.context7.com/mcp";
        };
      };
    };
  };
}

Just dropping this in case that helps.

@xamcost commented on GitHub (Oct 29, 2025): I know it doesn't answer @pmarreck 's original question, but [an opencode service is available in home-manager](https://mynixos.com/home-manager/options/programs.opencode). I use this config, and it works like a charm: ```nix { home.file = { ".config/opencode/agent/".source = ../../dotfiles/config/opencode/agent; }; programs.opencode = { enable = true; settings = { theme = "tokyonight"; autoupdate = true; mcp = { context7 = { type = "remote"; url = "https://mcp.context7.com/mcp"; }; }; }; }; } ``` Just dropping this in case that helps.
Author
Owner

@pmarreck commented on GitHub (Oct 31, 2025):

@xamcost While I'm not yet on the home-manager train (long story: short time and LOTS of dotfiles), I do like how the declarative config for it is stored that way too, there.

@pmarreck commented on GitHub (Oct 31, 2025): @xamcost While I'm not yet on the home-manager train (long story: short time and LOTS of dotfiles), I do like how the declarative config for it is stored that way too, there.
Author
Owner

@itpropro commented on GitHub (Nov 3, 2025):

I know it doesn't answer @pmarreck 's original question, but an opencode service is available in home-manager. I use this config, and it works like a charm:

{
home.file = {
".config/opencode/agent/".source = ../../dotfiles/config/opencode/agent;
};

programs.opencode = {
enable = true;
settings = {
theme = "tokyonight";
autoupdate = true;
mcp = {
context7 = {
type = "remote";
url = "https://mcp.context7.com/mcp";
};
};
};
};
}

Just dropping this in case that helps.

This is also broken. Home-manager only provides an overlay for configs, but still uses the original opencode nixpkgs package. That one currently only displays Bun is a fast JavaScript runtime, package manager, bundler, and test runner. when you run it and the previous working version you could pin is far before 1.0.

@itpropro commented on GitHub (Nov 3, 2025): > I know it doesn't answer [@pmarreck](https://github.com/pmarreck) 's original question, but [an opencode service is available in home-manager](https://mynixos.com/home-manager/options/programs.opencode). I use this config, and it works like a charm: > > { > home.file = { > ".config/opencode/agent/".source = ../../dotfiles/config/opencode/agent; > }; > > programs.opencode = { > enable = true; > settings = { > theme = "tokyonight"; > autoupdate = true; > mcp = { > context7 = { > type = "remote"; > url = "https://mcp.context7.com/mcp"; > }; > }; > }; > }; > } > > Just dropping this in case that helps. This is also broken. Home-manager only provides an overlay for configs, but still uses the original opencode nixpkgs package. That one currently only displays `Bun is a fast JavaScript runtime, package manager, bundler, and test runner.` when you run it and the previous working version you could pin is far before 1.0.
Author
Owner

@itpropro commented on GitHub (Nov 3, 2025):

I think the best way forward would be to have a flake natively provided by the opencode team. This is how most fast moving projects do it to avoid having old versions in nixpkgs and to have the best experience for the users. You would also have full control over the build pipeline and dependencies, as the flake.nix would live here at the root of the repo.
A good example for this would be walker (https://github.com/abenz1267/walker) or the hyprland landscape.
Are there any plans to support Nix in the future @thdxr ?

@itpropro commented on GitHub (Nov 3, 2025): I think the best way forward would be to have a flake natively provided by the opencode team. This is how most fast moving projects do it to avoid having old versions in nixpkgs and to have the best experience for the users. You would also have full control over the build pipeline and dependencies, as the flake.nix would live here at the root of the repo. A good example for this would be walker (https://github.com/abenz1267/walker) or the hyprland landscape. Are there any plans to support Nix in the future @thdxr ?
Author
Owner

@rekram1-node commented on GitHub (Nov 3, 2025):

@itpropro I think what you are saying makes total sense, the issue we have had thus far is none of us use nix. That's partially why the "help-wanted" tag is on this issue because we are hoping someone in the community can help get this started and we will give them what they need to do so.

Keeping it first party supported makes sense

@rekram1-node commented on GitHub (Nov 3, 2025): @itpropro I think what you are saying makes total sense, the issue we have had thus far is none of us use nix. That's partially why the "help-wanted" tag is on this issue because we are hoping someone in the community can help get this started and we will give them what they need to do so. Keeping it first party supported makes sense
Author
Owner

@rekram1-node commented on GitHub (Nov 18, 2025):

Okay I think this may be good now?

nix run nixpkgs#opencode # or github:sst/opencode for latest dev branch

@rekram1-node commented on GitHub (Nov 18, 2025): Okay I think this may be good now? nix run nixpkgs#opencode # or github:sst/opencode for latest dev branch
Author
Owner

@parkers0405 commented on GitHub (Nov 21, 2025):

I was hitting hash mismatches with the upstream flake and the stub-ld error on runtime. I got it working w/ a local overlay that pins the version, and uses autoPatchelfHook, and nix-ld.

Here is the working configuration for anyone stuck:

  1. You have to enable nix-ld in your configuration.nix: This fixes the stub-ld error by allowing dynamic binaries to run.
programs.nix-ld.enable = true;
  1. Then create a local overlay that bypasses the hash mismatch issues
    by pinning
final: prev:
let
  version = "1.0.85";
  # Hash for the source tarball
  srcHash = "sha256-mUGFERzY7dbN2CwWWUhONvvwhlY0LrTAGZ168m8y0RE=";
  # Hash for the node_modules (you will need to update this on releases)
  nodeModulesHash = "sha256-xqiDrKpODha+cfU6UpXLEUcApZ1xEkjRpqzFVJmq1uA=";

  src = prev.fetchFromGitHub {
    owner = "sst";
    repo = "opencode";
    rev = "v${version}";
    hash = srcHash;
  };

  mkNodeModules = prev.callPackage ./node-modules.nix {
    hash = nodeModulesHash;
  };

  mkPackage = prev.callPackage ./opencode.nix { };
in
{
  opencode = mkPackage {
    inherit version src;
    scripts = ./.; 
    target = "bun-linux-arm64"; 
    modelsDev = ./models-api.json;
    mkNodeModules = mkNodeModules;
  };
}

3. opencode.nix (using autoPatchelfHook):

{ lib, stdenv, bun, makeWrapper, autoPatchelfHook, ... }:
args:
stdenv.mkDerivation (finalAttrs: {
  pname = "opencode";
  version = args.version;
  src = args.src;

  nativeBuildInputs = [
    bun
    makeWrapper
    autoPatchelfHook
  ];
})

This setup builds v1.0.85 successfully and runs without crashing as of now, your target will be different bc I run nixos-asahi-linux (mac m1 ARM).

@parkers0405 commented on GitHub (Nov 21, 2025): I was hitting hash mismatches with the upstream flake and the stub-ld error on runtime. I got it working w/ a local overlay that pins the version, and uses autoPatchelfHook, and nix-ld. Here is the working configuration for anyone stuck: 1. You have to enable nix-ld in your configuration.nix: This fixes the stub-ld error by allowing dynamic binaries to run. ``` programs.nix-ld.enable = true; ``` 2. Then create a local overlay that bypasses the hash mismatch issues by pinning ``` final: prev: let version = "1.0.85"; # Hash for the source tarball srcHash = "sha256-mUGFERzY7dbN2CwWWUhONvvwhlY0LrTAGZ168m8y0RE="; # Hash for the node_modules (you will need to update this on releases) nodeModulesHash = "sha256-xqiDrKpODha+cfU6UpXLEUcApZ1xEkjRpqzFVJmq1uA="; src = prev.fetchFromGitHub { owner = "sst"; repo = "opencode"; rev = "v${version}"; hash = srcHash; }; mkNodeModules = prev.callPackage ./node-modules.nix { hash = nodeModulesHash; }; mkPackage = prev.callPackage ./opencode.nix { }; in { opencode = mkPackage { inherit version src; scripts = ./.; target = "bun-linux-arm64"; modelsDev = ./models-api.json; mkNodeModules = mkNodeModules; }; } 3. opencode.nix (using autoPatchelfHook): { lib, stdenv, bun, makeWrapper, autoPatchelfHook, ... }: args: stdenv.mkDerivation (finalAttrs: { pname = "opencode"; version = args.version; src = args.src; nativeBuildInputs = [ bun makeWrapper autoPatchelfHook ]; }) ``` This setup builds v1.0.85 successfully and runs without crashing as of now, your target will be different bc I run nixos-asahi-linux (mac m1 ARM).
Author
Owner

@azuline commented on GitHub (Jan 2, 2026):

https://github.com/anomalyco/opencode/pull/3924 this works for me, should the issue be closed? i came here and thought there was no support until i found a flake.nix in the root

@azuline commented on GitHub (Jan 2, 2026): https://github.com/anomalyco/opencode/pull/3924 this works for me, should the issue be closed? i came here and thought there was no support until i found a flake.nix in the root
Author
Owner

@itpropro commented on GitHub (Jan 2, 2026):

This can be closed, the flake works fine, thanks for adding it!

@itpropro commented on GitHub (Jan 2, 2026): This can be closed, the flake works fine, thanks for adding it!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2339