This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This repository packages OpenCode, a terminal-based AI assistant for developers, as a Nix flake. OpenCode is developed by SST (Serverless Stack) and this flake allows for easy installation and use in NixOS or other Nix-based environments.
This project uses Nix flakes for dependency management and building:
# Check nix version
nix --version
# Show flake outputs
nix flake show
# Build the flake
nix build
# Develop with the flake
nix develop
# Run opencode
nix run . -- [args]
# Test version
nix run . -- --versionThe main configuration is in flake.nix, which:
- Uses the unstable nixpkgs channel
- Uses flake-utils for multi-system support
- Downloads and packages pre-built binaries from npm
- Supports multiple platforms (aarch64-darwin, x86_64-darwin, aarch64-linux, x86_64-linux)
The flake implementation:
- Uses a custom
fetchNpmPackagefunction to download tarballs from npm registry - Includes a system-to-architecture mapping for platform-specific binaries
- Unpacks both the main package (
opencode-ai) and platform-specific package - Creates a proper FHS directory structure in the Nix store
- Uses
makeWrapperto set environment variables for the binary
The flake creates:
- A package that can be installed in Nix environments
- An app that can be run with
nix run - A devShell for development
The flake currently packages OpenCode version 0.1.117.
To update the flake to a new version of OpenCode:
- Update the
versionvariable inflake.nix - Update the hashes in the
packageHashesattribute set# Get correct hashes for each package nix-prefetch-url https://registry.npmjs.org/opencode-ai/-/opencode-ai-${version}.tgz nix-prefetch-url https://registry.npmjs.org/opencode-darwin-arm64/-/opencode-darwin-arm64-${version}.tgz nix-prefetch-url https://registry.npmjs.org/opencode-darwin-x64/-/opencode-darwin-x64-${version}.tgz nix-prefetch-url https://registry.npmjs.org/opencode-linux-arm64/-/opencode-linux-arm64-${version}.tgz nix-prefetch-url https://registry.npmjs.org/opencode-linux-x64/-/opencode-linux-x64-${version}.tgz # Convert hashes to SRI format (if needed) nix hash to-sri sha256:{hash}
After building the flake, you can install OpenCode using:
# Install to your profile
nix profile install .
# Or add to your NixOS configuration
environment.systemPackages = [ inputs.opencode-flake.packages.${system}.default ];The project is licensed under the MIT License.