Always up-to-date Nix package for OpenCode — the open source coding agent.
Beta: This project is under active development by a solo maintainer and may break between updates. Use at your own risk. Contributions are welcome — feel free to open issues or submit pull requests!
The OpenCode flake shipped in the upstream repo may lag behind releases or have build issues. This flake lets you:
- Always have the latest version — update as soon as a new release drops
- Declarative installation — managed in your NixOS or Home Manager config
- Reproducible builds — built from source via Bun's
compilefeature
| File | Purpose |
|---|---|
flake.nix |
Flake definition: inputs (nixpkgs, flake-utils), overlay, packages, app |
package.nix |
Build recipe: fetches the GitHub source, installs node_modules (FOD), compiles with Bun, wraps with ripgrep |
hashes.json |
Per-platform sha256 hashes for the node_modules fixed-output derivation |
flake.lock |
Pinned inputs |
.gitignore |
Excludes Nix build artifacts and editor files |
# Run directly without installing
nix run github:selfhost-it/opencode-cli-nix
# Install to your profile
nix profile install github:selfhost-it/opencode-cli-nix{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
opencode = {
url = "github:selfhost-it/opencode-cli-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
}{
nixpkgs.overlays = [
opencode.overlays.default
];
}NixOS (configuration.nix):
environment.systemPackages = with pkgs; [
opencode
];Home Manager (home.nix):
home.packages = with pkgs; [
opencode
];git clone git@github.com:selfhost-it/opencode-cli-nix.git
cd opencode-cli-nix
nix build .
# Test
./result/bin/opencode --version
# Or run directly
nix run .-
Change
versioninpackage.nix(e.g."1.4.0") -
Update the source hash:
nix-prefetch-url --unpack --type sha256 https://github.com/anomalyco/opencode/archive/refs/tags/v1.4.0.tar.gz nix hash convert --hash-algo sha256 --to sri <HASH>
Copy the SRI hash into
package.nix. -
Set
modelsDevApihash to""inpackage.nixand run:nix build .The build will fail and print the correct hash. Paste it back.
-
Set the node_modules hash to
""inhashes.jsonand run:nix build .The build will fail and print the correct hash. Paste it back.
-
Run
nix build .again — it should succeed. -
Commit and push.
Or run the automated update: ./update.sh.
- Source: Built from the anomalyco/opencode GitHub monorepo
- Builder:
bun install(fixed-output derivation) +Bun.build({ compile: true }) - Runtime: Self-contained binary (Bun compiled), no Node.js or Bun needed at runtime
- Runtime deps:
ripgrep(for code search, wrapped on PATH) - Binary:
opencode(at$out/bin/opencode) - The build embeds a snapshot of the models.dev API so opencode knows about available AI models without a runtime fetch
- The bun version check is patched to tolerate the nixpkgs bun version, which may lag slightly behind upstream requirements
OpenCode is licensed under MIT by Anomaly.
Maintained by self-host.it