Skip to content

make opencode work w/ NixOS #3540

Closed
Closed

Description

@pmarreck

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

Activity

  1. github-actions commented on Oct 29, 2025

    @github-actions
    Contributor

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

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

  2. changed the title [-]Unable to even run opencode on NixOS because it makes unfortunate assumptions about linux distros[/-] [+]make opencode work w/ NixOS[/+] on Oct 29, 2025
  3. rekram1-node commented on Oct 29, 2025

    @rekram1-node
    Collaborator

    yeah we should fix this

  4. xamcost commented on Oct 29, 2025

    @xamcost

    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.

  5. pmarreck commented on Oct 31, 2025

    @pmarreck
    Author

    @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.

  6. itpropro commented on Nov 4, 2025

    @itpropro

    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.

  7. itpropro commented on Nov 4, 2025

    @itpropro

    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 ?

  8. rekram1-node commented on Nov 4, 2025

    @rekram1-node
    Collaborator

    @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

  9. rekram1-node commented on Nov 18, 2025

    @rekram1-node
    Collaborator

    Okay I think this may be good now?

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

  10. self-assigned this
    on Nov 18, 2025
  11. parkers0405 commented on Nov 21, 2025

    @parkers0405

    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).

  12. azuline commented on Jan 2, 2026

    @azuline

    #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

  13. itpropro commented on Jan 2, 2026

    @itpropro

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

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions