Nix flake for OpenCode - an AI coding assistant in your terminal.
Features:
- Direct binary packaging from GitHub releases
- Smart Home Manager detection with automatic symlink management
- Pre-built binaries via Garnix for instant installation
- Hourly automated updates for new OpenCode versions
- Linux and macOS support (x86_64 and aarch64)
Try without installing:
nix run github:dominicnunez/opencode-nixInstall to your profile:
nix profile add github:dominicnunez/opencode-nixThis flake uses Garnix for CI and binary caching. The nixConfig in flake.nix automatically configures the cache, so pre-built binaries are fetched without any manual setup.
If prompted to allow configuration from the flake, answer yes or add accept-flake-config = true to your Nix configuration.
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
opencode-nix.url = "github:dominicnunez/opencode-nix";
};
outputs = { self, nixpkgs, opencode-nix, ... }: {
# Your configuration here
};
}{ inputs, pkgs, ... }:
{
environment.systemPackages = [
inputs.opencode-nix.packages.${pkgs.system}.default
];
}{ inputs, pkgs, ... }:
{
home.packages = [
inputs.opencode-nix.packages.${pkgs.system}.default
];
}{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
opencode-nix.url = "github:dominicnunez/opencode-nix";
};
outputs = { self, nixpkgs, opencode-nix, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ opencode-nix.overlays.default ];
};
in {
# pkgs.opencode is now available
devShells.${system}.default = pkgs.mkShell {
buildInputs = [ pkgs.opencode ];
};
};
}This package includes smart Home Manager detection. When Home Manager is detected, the package skips creating symlinks to respect your declarative configuration.
Detection methods:
HM_SESSION_VARSenvironment variable is set~/.config/home-managerdirectory exists/etc/profiles/per-user/$USERdirectory exists
Behavior:
- Home Manager detected: Skips symlink creation and cleans up any orphaned symlinks
- Home Manager absent: Creates
~/.local/bin/opencodesymlink for convenience
Automatic cleanup: If you previously installed opencode standalone (creating a ~/.local/bin/opencode symlink) and later enable Home Manager, the package will automatically remove the orphaned symlink on first run to prevent PATH conflicts.
| Variable | Description |
|---|---|
OPENCODE_NIX_VERBOSE |
Set to 1 to enable Home Manager detection and symlink management messages |
Example:
export OPENCODE_NIX_VERBOSE=1If using nix profile add:
nix profile upgrade '.*opencode.*'If using as a flake input:
nix flake update opencode-nix
nixos-rebuild switch # or home-manager switchgit clone https://github.com/dominicnunez/opencode-nix
cd opencode-nix
nix develop # enters shell with dev tools
nix build
./result/bin/opencode --versionThe update.sh script checks for new OpenCode releases and updates version.json:
# Enter dev shell (provides required tools)
nix develop
# Check for updates (dry run)
./update.sh
# Update to latest version
./update.sh --updateThe script:
- Queries GitHub API for the latest non-prerelease release
- Compares against current version in
version.json - With
--update: fetches SRI hashes for all platforms and updatesversion.json
A GitHub Actions workflow runs hourly to check for new releases. When a new version is found, it automatically:
- Updates
version.jsonwith new version and hashes - Validates with
nix flake check - Pushes directly to main
This packaging is MIT-licensed. See LICENSE.
OpenCode is developed by Anomaly.