Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126{ config, inputs, lib, pkgs, ...}:
let agentSource = ../../../copilot/plugins/jj-flake-vigilance/agents; skills = import ./shared-skills.nix { inherit inputs; }; adaptAgentTools = replacement: file: lib.concatMapStringsSep "\n" (line: if lib.hasPrefix "tools:" line then replacement else line) ( lib.splitString "\n" (builtins.readFile file) ); # OpenCode 2 from upstream, since nixpkgs still ships 1.x. Upstream builds # for channel "prod", which registers the background service in # service-prod.json where clients look for service.json; "latest" is the # official release channel and keeps the same database. Upstream's source # fileset also leaves out script/native-arch.ts, which the CLI's build # script imports since 2.0.30 ("Cannot find module # '../../../script/native-arch'"), so copy it back in. opencode = inputs.opencode.packages.${pkgs.stdenv.hostPlatform.system}.opencode.overrideAttrs (old: { postPatch = old.postPatch + '' install -Dm644 ${inputs.opencode}/script/native-arch.ts script/native-arch.ts ''; env = old.env // { OPENCODE_CHANNEL = "latest"; }; });in{ imports = [ ./common.nix ];
xdg.configFile = lib.mapAttrs' ( _: plugin: lib.nameValuePair "opencode/plugins/${plugin.target}" { source = plugin.source; } ) config.dotfiles.tooling.opencodeConfig;
programs.opencode = { enable = true; # Keep OpenCode's own config writable while applying these defaults. mutableSettings = true; package = pkgs.writeNuScriptBin "opencode" '' def --wrapped main [...args] { ^${pkgs.secretspec}/bin/secretspec run --file ${../../secretspec.toml} --provider keyring --profile default --reason "OpenCode invocation" -- ${opencode}/bin/opencode ...$args } ''; enableMcpIntegration = true; inherit skills; # Copilot agents declare tools as a list, while OpenCode expects a boolean # map. Adapt only the copies installed in OpenCode's config. agents = { project-specialist = adaptAgentTools "" "${agentSource}/project-specialist.agent.md"; trunk-triage = adaptAgentTools "tools: { bash: false, edit: false, write: false, patch: false, task: false }" "${agentSource}/trunk-triage.agent.md"; }; settings = { command.init-repo = { description = "Initialize the current directory as a Nix, Nushell, and Jujutsu project."; agent = "build"; template = '' Initialize a new repository in the current directory. The project requirements are:
- Use Nix as the default environment and package-management tool. Create a flake and development shell targeting only x86_64-linux for all flake outputs unless explicitly asked for more. - Use Nushell for project scripts and automation rather than Bash where shell tooling is needed. - Use Jujutsu as the version-control interface, initialized with a Git backend for interoperability. - Add only the minimal repository metadata, ignores, and documentation needed for the chosen project shape.
First inspect the directory and any supplied requirements. Do not overwrite or discard existing work. Ask one concise question only if the language, application type, or another material project decision is genuinely ambiguous.
User requirements: $ARGUMENTS ''; }; mcp.chrome-devtools = let server = import ./chrome-devtools-mcp.nix; in { type = "local"; command = [ server.command ] ++ server.args; enabled = true; }; mcp.github = { type = "remote"; url = "https://api.githubcopilot.com/mcp/"; enabled = true; oauth = false; headers.Authorization = "Bearer {env:GITHUB_TOKEN}"; }; mcp.stitch = { type = "remote"; url = "https://stitch.googleapis.com/mcp"; enabled = true; oauth = false; headers.X-Goog-Api-Key = "{env:STITCH_API_KEY}"; }; server.hostname = "localhost"; # Bill the GitHub Copilot and ChatGPT subscriptions only; both sign in # with `opencode auth login`. Anthropic forbids Claude plan sign-in here. enabled_providers = [ "github-copilot" "openai" ]; }; };
dotfiles.nixpkgsWatch.opencode = { inherit (opencode) version; reason = "use pkgs.opencode in modules/tooling/ai/opencode.nix and drop the opencode input with its build overrides"; };
dotfiles.tooling.ai.opencode = { command = "${config.programs.opencode.package}/bin/opencode"; automation = '' let model = $env.AI_RUN_MODEL? if $model == null { ^${config.programs.opencode.package}/bin/opencode run --agent $agent --auto $prompt } else { ^${config.programs.opencode.package}/bin/opencode run --agent $agent --model $model --auto $prompt } ''; };}