# Home Manager module: installs the OpenCode plugin for OpenCodeReview. # # Creates symlinks under ~/.config/opencode/plugins/ for the plugin file and # its runtime node_modules, and puts the matching `ocr` CLI on PATH. # # Note: the node_modules symlink is shared by everything in the plugins # directory. Plugins installed by other means that need conflicting npm # dependencies cannot coexist with this one. { config, lib, pkgs, ... }: let cfg = config.programs.open-code-review; in { options.programs.open-code-review = { enable = lib.mkEnableOption "OpenCodeReview AI code review CLI and its OpenCode plugin"; package = lib.mkOption { type = lib.types.package; default = pkgs.open-code-review; defaultText = lib.literalExpression "pkgs.open-code-review"; description = "The open-code-review package to use."; }; opencode = { enable = lib.mkEnableOption "symlink the bundled OpenCode plugin into ~/.config/opencode"; }; }; config = lib.mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; } (lib.mkIf cfg.opencode.enable { # The plugin resolves its imports Node-style: node_modules next to the # plugin file, or in any parent directory (via the file's realpath). # Linking both the file and node_modules covers either resolution. xdg.configFile."opencode/plugins/open-code-review.ts".source = "${cfg.package.passthru.opencode-plugin}/share/open-code-review/opencode/open-code-review.ts"; xdg.configFile."opencode/plugins/node_modules".source = "${cfg.package.passthru.opencode-plugin}/share/open-code-review/opencode/node_modules"; }) ]); }