Skip to content

Commit 03d7442

Browse files
committed
opencode: option to override model used by specialized (sub)agents
1 parent 3c2a315 commit 03d7442

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

lib/mkRiglib.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let
1919
);
2020
};
2121

22-
# Override a derivation so its always built locally, and not queried from remote substituters
22+
# Override a derivation so it is always built locally, and not queried from remote substituters
2323
alwaysLocal =
2424
x:
2525
if pkgs.lib.isDerivation x then

riglets/models.nix

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
_:
22
{ lib, ... }:
3+
let
4+
providerAndModel = with lib.types; {
5+
providerId = lib.mkOption {
6+
type = nullOr str;
7+
description = "Model provider ID. Can be ignored depending on the entrypoint";
8+
default = null;
9+
};
10+
modelId = lib.mkOption {
11+
type = nullOr str;
12+
description = "Model ID";
13+
default = null;
14+
};
15+
};
16+
in
317
{
418
options.models = with lib.types; {
5-
default = {
6-
providerId = lib.mkOption {
7-
type = nullOr str;
8-
description = "Model provider ID. Can be ignored depending on the entrypoint";
9-
default = null;
10-
};
11-
modelId = lib.mkOption {
12-
type = nullOr str;
13-
description = "Model ID";
14-
default = null;
15-
};
19+
default = providerAndModel;
20+
21+
specialized = lib.mkOption {
22+
type = types.attrsOf (types.submodule { options = providerAndModel; });
23+
description = "Model overrides for specialized agents (plan, build, explore, etc.). Support depends on entrypoint";
24+
default = { };
1625
};
1726

1827
providers = {
@@ -31,7 +40,7 @@ _:
3140
};
3241

3342
config.riglets.models.meta = {
34-
description = "Pre-select a specific model for a rig (to be imported by compatible entrypoints)";
43+
description = "Pre-select model(s) for a rig (to be imported by compatible entrypoints)";
3544
status = "stable";
3645
version = "0.1.0";
3746
intent = "base";

riglets/opencode.nix

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ in
3232
let
3333
manifestPath = rig.manifest.override { shownDocRoot = "$RIG_DOCS"; };
3434

35+
toModelId =
36+
x:
37+
if x.modelId != null && x.providerId == null then
38+
throw ''
39+
If modelId is set, then providerId must be set too
40+
''
41+
else
42+
"${x.providerId}/${x.modelId}";
43+
3544
# OpenCode config with permissions and MCP servers
3645
opencodeConfigJson = riglib.toJSON (
3746
{
@@ -106,30 +115,23 @@ in
106115
) (lib.concatMapAttrs (k: v: { "rig:${k}" = v; }) rig.promptCommands);
107116
}
108117
// lib.optionalAttrs (config.models.default.modelId != null) {
109-
model =
110-
if config.models.default.providerId == null then
111-
throw ''
112-
If models.default.modelId is set, then models.default.providerId must be too
113-
''
114-
else
115-
"${config.models.default.providerId}/${config.models.default.modelId}";
118+
model = toModelId config.models.default;
116119
}
117120
// lib.optionalAttrs (config.models.providers.disabled != null) {
118121
disabled_providers = config.models.providers.disabled;
119122
}
120123
// lib.optionalAttrs (config.models.providers.enabled != null) {
121124
enabled_providers = config.models.providers.enabled;
122125
}
126+
// lib.optionalAttrs (config.models.specialized != { }) {
127+
agent = lib.mapAttrs (_agentName: mdl: { model = toModelId mdl; }) config.models.specialized;
128+
}
123129
);
124130
in
125131
# Return a folder derivation with bin/ subfolder
126132
pkgs.writeShellScriptBin "opencode" ''
127133
set -euo pipefail
128134
129-
warn() {
130-
printf "\033[0;33m%s\n\033[0m" "$1" >&2
131-
}
132-
133135
export PATH="${rig.toolRoot}/bin:$PATH"
134136
export RIG_DOCS="${rig.docRoot}"
135137
# Exported for convenience

rigup.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ extends.self = "example-rig-claude"
6060
[rigs.example-rig-opencode]
6161
extends.self = "example-rig"
6262
riglets.self = ["opencode"]
63-
config.models.default.providerId = "opencode"
64-
config.models.default.modelId = "glm-4.7-free"
63+
config.models.default = { providerId = "opencode", modelId = "glm-4.7" }
64+
config.models.specialized.plan = { providerId = "opencode", modelId = "claude-opus-4-6" }
65+
config.models.specialized.explore = { providerId = "opencode", modelId = "kimi-k2.5-free" }
6566

6667
[rigs.example-rig-opencode.config.agent.personality]
6768
inspiration = "Fa Mulan"
@@ -88,8 +89,8 @@ extends.self = "example-rig"
8889
riglets.self = ["cursor"]
8990
config.models.default.modelId = "opus-4.5"
9091
# config.cursor.justSetupProject = true
91-
# If true, the entrypoiny will not start cursor-agent:
92-
# it will only setup the .cursor/ folder in the CWD, to be used by Cursor IDE.
92+
# If true, the entrypoiny will not start cursor-agent:
93+
# it will only setup the .cursor/ folder in the CWD, to be used by Cursor IDE.
9394

9495
[rigs.example-rig-cursor.config.agent.personality]
9596
inspiration = "Sauron"

0 commit comments

Comments
 (0)