Files
home-manager/tests/modules/programs/opencode/layer-cli.nix
Rimapus 6d9655f764 opencode: support OpenCode 2 cli settings
Add programs.opencode.cli for OpenCode 2's global cli.json, while
retaining programs.opencode.tui for OpenCode 1.

Support mutable CLI configuration through OPENCODE_CLI_CONFIG_CONTENT,
leaving cli.json writable by OpenCode. Add validation against the
configured package's CLI schema and warn when CLI or TUI settings do
not match the package version.
2026-10-23 11:35:25 -05:00

51 lines
1.4 KiB
Nix

{
config,
lib,
realPkgs,
...
}:
let
cli = {
theme.name = "system";
tabs.mode = "off";
plugins = [ "plugin-$HOME-\"quoted\"-`cmd`" ];
};
expectedCli = builtins.toJSON (lib.importJSON ./cli-layer.json);
in
{
imports = [ ./opencode-v2-stubs.nix ];
programs.opencode = {
enable = true;
mutableSettings = true;
inherit cli;
validateFiles.cli = true;
};
assertions = [
{
assertion = config.home.sessionVariables ? OPENCODE_CLI_CONFIG_CONTENT;
message = "OpenCode must export the CLI settings layer through OPENCODE_CLI_CONFIG_CONTENT.";
}
{
assertion = !(config.home.sessionVariables ? OPENCODE_CONFIG);
message = "OpenCode must not export a settings selector for an empty settings layer.";
}
{
assertion = !(config.home.sessionVariables ? OPENCODE_TUI_CONFIG);
message = "OpenCode must not export a TUI selector for an empty TUI layer.";
}
];
nmt.script = ''
assertFileContent home-files/.config/opencode/home-manager-cli.json \
${./cli-layer.json}
assertPathNotExists home-files/.config/opencode/cli.json
${lib.getExe realPkgs.bash} -c '
. "$1"
test "$OPENCODE_CLI_CONFIG_CONTENT" = "$2"
' -- "$TESTED/home-path/etc/profile.d/hm-session-vars.sh" '${expectedCli}' \
|| fail "OpenCode CLI settings must preserve JSON content through the session variable"
'';
}