This repository packages OpenCode, a terminal-based AI assistant for developers, as a Nix flake. OpenCode is developed by SST (Serverless Stack) and provides powerful AI-powered coding assistance directly in your terminal.
This flake automatically stays up-to-date with the latest OpenCode releases through automated workflows that run every 6 hours.
# Run directly from the flake
nix run github:aodhanhayter/opencode-flake
# Check the version
nix run github:aodhanhayter/opencode-flake -- --version
# Install to your profile
nix profile install github:aodhanhayter/opencode-flakenix profile install github:aodhanhayter/opencode-flake{
inputs.opencode-flake.url = "github:aodhanhayter/opencode-flake";
# In your configuration:
environment.systemPackages = [ inputs.opencode-flake.packages.${pkgs.system}.default ];
# Or in home-manager:
home.packages = [ inputs.opencode-flake.packages.${pkgs.system}.default ];
}This flake builds OpenCode from source, copying the approach from the official nixpkgs build. If you don't require the latest version of opencode, I recommend using the official nixpkgs version as it will likely be more stable and well tested.
- Source-based builds: Fetches source code directly from the sst/opencode repository
- Multi-component build system:
- Go TUI Component: Builds the terminal UI (
packages/tui) usingbuildGoModule - TypeScript Core: Uses Bun to compile the main application logic
- Go TUI Component: Builds the terminal UI (
- Deterministic builds: Includes a local models patch to avoid network dependencies during build
- Cross-platform support: Supports all major platforms with proper platform-specific library linking
# Enter development shell with OpenCode available
nix develop github:aodhanhayter/opencode-flake
# Build locally
nix build
# Test the package
nix flake checkThis repository features fully automated maintenance:
- Automatic updates: GitHub Actions workflow runs every 6 hours using
nix-update - Version detection: Automatically detects new OpenCode releases from upstream
- Auto-deployment: Updates are automatically tested, tagged, and released
- Zero-maintenance: No manual intervention required for version updates
- Check the workflow runs to see recent updates
- Note: Scheduled workflows are automatically disabled after 60 days of repository inactivity
- To reactivate: Make any commit or manually trigger the workflow
# Force update to latest version
nix-update --flake opencode
# Build and test
nix build && nix flake checkNote: When OpenCode updates, nix-update may fail during the build phase if Go module dependencies have changed. This is normal - check the build logs for the correct vendorHash and update package.nix manually.
aarch64-darwin(macOS on Apple Silicon)x86_64-darwin(macOS on Intel)aarch64-linux(Linux on ARM64)x86_64-linux(Linux on x86_64)
flake.nix: Clean, minimal flake following nixpkgs patternspackage.nix: Comprehensive OpenCode package definition with source buildslocal-models-dev.patch: Patch for deterministic builds with local models.github/workflows/: Automated CI/CD workflows
-
Automated Updates (
update-opencode-nix.yml):- Runs every 6 hours (00:15, 06:15, 12:15, 18:15 UTC)
- Uses
nix-updatefor reliable version detection - Auto-creates releases and tags
- Handles errors and cleanup automatically
- Can be manually triggered via GitHub Actions UI
-
Build Verification:
- Ensures packages build correctly across all platforms
- Validates version reporting and functionality
This project is licensed under the MIT License - see the LICENSE file for details.