Files
nixos/home-modules/opencode-config.nix
T

90 lines
3.4 KiB
Nix
Raw Normal View History

{ ... }:
let
# W&B Inference (CoreWeave), OpenAI-compatible.
# The API key is NOT in this repo. Put it on each machine with:
# mkdir -p ~/.keys && install -m 600 /dev/stdin ~/.keys/wandb
# (paste the key, then Ctrl-D)
# NOTE: opencode refuses to start if a {file:...} reference is missing.
wandbTokenFile = "~/.keys/wandb";
# Model IDs from https://docs.coreweave.com/inference/models (Nov 2026).
# Prices are $/1M tokens, input/output.
wandbModels = {
# Quality.
"zai-org/GLM-5.3" = { name = "GLM 5.3"; context = 1048576; }; # $0.75/$3.00
"moonshotai/Kimi-K2.7-Code" = { name = "Kimi K2.7 Code"; context = 262144; }; # $0.60/$3.00
"deepseek-ai/DeepSeek-V4-Pro-0813" = { name = "DeepSeek V4 Pro"; context = 1048576; }; # $1.31/$3.96
# Balanced.
"deepseek-ai/DeepSeek-V4.1-Flash-1017" = { name = "DeepSeek V4.1 Flash 1017"; context = 1048576; }; # $0.30/$1.20
"MiniMaxAI/MiniMax-M3" = { name = "MiniMax M3"; context = 262144; }; # $0.23/$0.96
# Speed.
"zai-org/GLM-5.3-Flash" = { name = "GLM 5.3 Flash"; context = 1048576; }; # $0.12/$0.38
"nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B" = { name = "Nemotron 3.5 Lightning"; context = 262144; }; # $0.07/$0.20
};
fastModel = "wandb/zai-org/GLM-5.3-Flash";
rule = action: resource: effect: { inherit action resource effect; };
# Last matching rule wins; unmatched checks default to "ask".
# `opencode --auto` (alias: oca) turns every "ask" into "allow", but "deny"
# is still enforced, so the deny list below is the guardrail for auto mode.
permissions = [
# Normal (non-auto) mode: prompt for edits and fetches.
(rule "edit" "*" "ask")
(rule "webfetch" "*" "ask")
(rule "shell" "git status *" "allow")
(rule "shell" "git diff *" "allow")
(rule "shell" "git log *" "allow")
(rule "shell" "ls *" "allow")
(rule "shell" "pwd" "allow")
# Hard denies, in every mode.
(rule "shell" "sudo *" "deny")
(rule "shell" "git push *--force*" "deny")
(rule "shell" "git push * -f" "deny")
(rule "shell" "git push * -f *" "deny")
(rule "shell" "git push -f *" "deny")
(rule "shell" "git reset --hard *" "deny")
(rule "shell" "git clean *" "deny")
(rule "shell" "rm -rf /*" "deny")
(rule "shell" "rm -rf ~*" "deny")
] ++ builtins.concatMap (dir: [
(rule "read" dir "deny")
(rule "edit" dir "deny")
]) [ "~/.keys/*" "~/.ssh/*" "~/.aws/*" "~/.config/sops/*" ];
opencodeConfig = {
"$schema" = "https://opencode.ai/config.json";
model = "wandb/zai-org/GLM-5.3";
# Cheap background calls.
agents = {
title.model = fastModel;
summary.model = fastModel;
};
providers.wandb = {
name = "W&B Inference";
package = "@opencode/ai/providers/openai-compatible";
settings = {
baseURL = "https://api.inference.wandb.ai/v1";
apiKey = "{file:${wandbTokenFile}}";
};
# "<team>/<project>" to bill against. Required when the account is in
# several teams; the default entity (coreweave1) rejects this key.
headers."OpenAI-Project" = "cw-wb/at";
models = builtins.mapAttrs (_: m: {
inherit (m) name;
limit = { inherit (m) context; output = 32768; };
}) wandbModels;
};
inherit permissions;
};
in {
home.file.".config/opencode/opencode.jsonc".text = builtins.toJSON opencodeConfig;
programs.zsh.shellAliases.oca = "opencode --auto";
}