From 542a0a59b6b5993ae50c50141d629cbfcfb565a0 Mon Sep 17 00:00:00 2001 From: Cooper Maruyama Date: Sat, 16 May 2026 07:12:48 -0700 Subject: [PATCH] feat: opencode.installPackage toggle and OpenCode README section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds `darkmatter.agentSkills.opencode.installPackage` (default true) so consumers managing the opencode binary outside Home Manager (Homebrew, manual install) can skip HM's `pkgs.opencode` add to `home.packages`. When false, a tiny stub derivation is substituted into `programs.opencode.package` — required because setting it to null currently crashes the upstream HM warnings block (calls `lib.versionAtLeast` on a null version). README updates: - Drop `targets.opencode.enable = true` from the registry-skills example. The darkmatter preset now installs OpenCode skills via `programs.opencode.skills`, and enabling the agent-skills opencode target would overlap with the preset's per-skill entries. - New OpenCode subsection documenting how skills land in OpenCode, the known third-party-source limitation, and the installPackage toggle. Lock bump for `darkmatter-agents` follows once the upstream PR lands. Co-Authored-By: Claude Opus 4.7 --- README.md | 25 +++++++++++++++++++--- src/home-manager/agents.nix | 41 ++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 30bab8f..af177aa 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ Personal skills can stay outside git and be layered in locally: Personal skills are installed with the `personal/*` prefix. -### Layer registry skills into Claude, Codex, OpenCode, Cursor, and Zed +### Layer registry skills into Claude, Codex, Cursor, and Zed The default module can be combined with any `agent-skills-nix` catalog. Add the catalog as a flake input, pass `inputs` to Home Manager, then add a source and enable the targets you want. @@ -234,8 +234,11 @@ Then configure the additional catalog in `home.nix`: targets.claude.enable = true; targets.codex.enable = true; - targets.opencode.enable = true; targets.cursor.enable = true; + # `targets.opencode.enable` is intentionally omitted — OpenCode + # skills are managed by the Darkmatter preset via the canonical + # `programs.opencode.skills` option. See the OpenCode section + # below. # `agent-skills-nix` does not currently define a built-in Zed target, # but custom targets work the same way. @@ -248,7 +251,23 @@ Then configure the additional catalog in `home.nix`: } ``` -This installs Darkmatter preset skills under `darkmatter/*` plus the selected registry skills under `anthropic/*` into Claude, Codex, OpenCode, Cursor, and Zed. +This installs Darkmatter preset skills under `darkmatter/*` plus the selected registry skills under `anthropic/*` into Claude, Codex, Cursor, and Zed. + +### OpenCode + +The Darkmatter preset configures OpenCode through Home Manager's canonical `programs.opencode` module. Team-wide `darkmatter/*` skills (and any directory set via `darkmatter.agentSkills.personalPath`) flow into `~/.config/opencode/skills/` automatically — `programs.agent-skills.targets.opencode` should be left unset to avoid clobbering those per-skill entries. + +Layering third-party `agent-skills-nix` sources (e.g. `anthropic-skills`) into OpenCode is a known follow-up. Until that lands, OpenCode receives only the curated Darkmatter skills; layer additional catalogs into Claude/Codex/Cursor. + +If you manage the `opencode` binary outside Home Manager (Homebrew, manual install, etc), skip the package install: + +```nix +{ + darkmatter.agentSkills.opencode.installPackage = false; +} +``` + +Config files and skills are still installed when this is `false`. ## Shared Secrets diff --git a/src/home-manager/agents.nix b/src/home-manager/agents.nix index cee1ee0..97a81e4 100644 --- a/src/home-manager/agents.nix +++ b/src/home-manager/agents.nix @@ -2,26 +2,57 @@ { config, lib, + pkgs, ... }: let cfg = config.darkmatter.agentSkills; + + # When the user opts out of HM installing opencode, substitute a + # tiny stub derivation. This sidesteps an upstream HM bug where + # `programs.opencode.package = null` crashes the warnings block — + # it calls `lib.versionAtLeast` on a null version. The stub's + # only job is to satisfy `lib.getVersion` and produce an empty + # output so PATH isn't shadowed. + opencodeStub = + (pkgs.runCommand "opencode-stub" { + meta.mainProgram = "opencode"; + } "mkdir -p $out") + // { + version = "1.2.15"; + }; in { imports = [ darkmatter-agents.homeManagerModules.default ]; - options.darkmatter.agentSkills.personalPath = lib.mkOption { - type = lib.types.nullOr lib.types.path; - default = null; - example = lib.literalExpression "/Users/me/.config/darkmatter/skills"; - description = "Optional private skills directory to install with the personal id prefix."; + options.darkmatter.agentSkills = { + personalPath = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + example = lib.literalExpression "/Users/me/.config/darkmatter/skills"; + description = "Optional private skills directory to install with the personal id prefix."; + }; + + opencode.installPackage = lib.mkOption { + type = lib.types.bool; + default = true; + example = false; + description = '' + Whether the OpenCode preset should add `pkgs.opencode` to + `home.packages`. Set to `false` if you manage the opencode + binary outside Home Manager (Homebrew, manual install, etc). + OpenCode config files and skills are installed either way. + ''; + }; }; config = { _module.args.personalAgentSkillsPath = cfg.personalPath; programs.agent-skills.enable = lib.mkDefault true; + + programs.opencode.package = lib.mkIf (!cfg.opencode.installPackage) opencodeStub; }; }