{ config, lib, pkgs, ... }: with lib; let cfg = config.coding.opencode; in { options.coding.opencode = { enable = mkEnableOption "opencode AI coding assistant"; ohMyOpencodeSettings = mkOption { type = types.attrs; default = {}; description = '' Attributes merged (via recursiveUpdate) on top of the default oh-my-opencode.json. Use this to set provider-specific model assignments per machine. ''; example = literalExpression '' { agents.sisyphus.model = "anthropic/claude-opus-4-5"; categories.ultrabrain.model = "anthropic/claude-opus-4-5"; } ''; }; extraSettings = mkOption { type = types.attrs; default = {}; description = '' Extra opencode settings merged (via mkMerge) into programs.opencode.settings. Use this to add provider configuration that is specific to a machine or organisation. ''; example = literalExpression '' { provider.anthropic = { name = "Anthropic"; models."claude-opus-4-5" = { limit.context = 200000; }; }; } ''; }; extraPlugins = mkOption { type = types.listOf types.str; default = []; description = '' Additional opencode plugins to add to the plugin list. Each entry is a path or package name passed to opencode's plugin array. ''; }; }; config = mkIf cfg.enable { programs.opencode = { enable = true; enableMcpIntegration = true; settings = mkMerge [ { theme = "opencode"; plugin = ["oh-my-openagent"] ++ cfg.extraPlugins; formatter = { alejandra = { command = ["alejandra" "-q" "-"]; extensions = [".nix"]; }; }; } cfg.extraSettings ]; }; home.file.".config/opencode/oh-my-opencode.json".text = builtins.toJSON ( recursiveUpdate { "$schema" = "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json"; google_auth = false; disabled_mcps = ["context7" "websearch"]; } cfg.ohMyOpencodeSettings ); }; }