refactor(opencode): generate config.json from the home module
Build opencode's config.json with pkgs.formats.json instead of shipping a static file, pinning each formatter command to its store-path binary via lib.getExe. Drops the standalone config/opencode/config.json. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d0c58a5c9d
commit
d10570a0d8
2 changed files with 82 additions and 53 deletions
|
|
@ -1,43 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://opencode.ai/config.json",
|
|
||||||
"lsp": true,
|
|
||||||
"formatter": {
|
|
||||||
"nixfmt": {
|
|
||||||
"command": ["nixfmt", "$FILE"],
|
|
||||||
"extensions": [".nix"]
|
|
||||||
},
|
|
||||||
"prettier": {
|
|
||||||
"command": ["prettier", "--write", "$FILE"],
|
|
||||||
"extensions": [".md", ".yaml", ".yml", ".json", ".css", ".html", ".js", ".ts", ".jsx", ".tsx"]
|
|
||||||
},
|
|
||||||
"shfmt": {
|
|
||||||
"command": ["shfmt", "-w", "$FILE"],
|
|
||||||
"extensions": [".sh", ".bash"]
|
|
||||||
},
|
|
||||||
"ruff": {
|
|
||||||
"command": ["ruff", "format", "$FILE"],
|
|
||||||
"extensions": [".py"]
|
|
||||||
},
|
|
||||||
"taplo": {
|
|
||||||
"command": ["taplo", "format", "$FILE"],
|
|
||||||
"extensions": [".toml"]
|
|
||||||
},
|
|
||||||
"stylua": {
|
|
||||||
"command": ["stylua", "$FILE"],
|
|
||||||
"extensions": [".lua"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"disabled_providers": ["opencode"],
|
|
||||||
"provider": {
|
|
||||||
"halo": {
|
|
||||||
"npm": "@ai-sdk/openai-compatible",
|
|
||||||
"name": "Halo",
|
|
||||||
"options": {
|
|
||||||
"baseURL": "http://halo:8000/v1"
|
|
||||||
},
|
|
||||||
"models": {
|
|
||||||
"coder": { "name": "coder" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -11,6 +11,83 @@ let
|
||||||
|
|
||||||
cfg = config.metacfg.cli-apps.opencode;
|
cfg = config.metacfg.cli-apps.opencode;
|
||||||
|
|
||||||
|
# Formatters opencode runs on save, each pinned to its exact store path.
|
||||||
|
formatters = {
|
||||||
|
nixfmt = {
|
||||||
|
command = [
|
||||||
|
(lib.getExe pkgs.nixfmt-rfc-style)
|
||||||
|
"$FILE"
|
||||||
|
];
|
||||||
|
extensions = [ ".nix" ];
|
||||||
|
};
|
||||||
|
prettier = {
|
||||||
|
command = [
|
||||||
|
(lib.getExe pkgs.nodePackages.prettier)
|
||||||
|
"--write"
|
||||||
|
"$FILE"
|
||||||
|
];
|
||||||
|
extensions = [
|
||||||
|
".md"
|
||||||
|
".yaml"
|
||||||
|
".yml"
|
||||||
|
".json"
|
||||||
|
".css"
|
||||||
|
".html"
|
||||||
|
".js"
|
||||||
|
".ts"
|
||||||
|
".jsx"
|
||||||
|
".tsx"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
shfmt = {
|
||||||
|
command = [
|
||||||
|
(lib.getExe pkgs.shfmt)
|
||||||
|
"-w"
|
||||||
|
"$FILE"
|
||||||
|
];
|
||||||
|
extensions = [
|
||||||
|
".sh"
|
||||||
|
".bash"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
ruff = {
|
||||||
|
command = [
|
||||||
|
(lib.getExe pkgs.ruff)
|
||||||
|
"format"
|
||||||
|
"$FILE"
|
||||||
|
];
|
||||||
|
extensions = [ ".py" ];
|
||||||
|
};
|
||||||
|
taplo = {
|
||||||
|
command = [
|
||||||
|
(lib.getExe pkgs.taplo)
|
||||||
|
"format"
|
||||||
|
"$FILE"
|
||||||
|
];
|
||||||
|
extensions = [ ".toml" ];
|
||||||
|
};
|
||||||
|
stylua = {
|
||||||
|
command = [
|
||||||
|
(lib.getExe pkgs.stylua)
|
||||||
|
"$FILE"
|
||||||
|
];
|
||||||
|
extensions = [ ".lua" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
opencodeConfig = {
|
||||||
|
"$schema" = "https://opencode.ai/config.json";
|
||||||
|
lsp = true;
|
||||||
|
formatter = formatters;
|
||||||
|
disabled_providers = [ "opencode" ];
|
||||||
|
provider.halo = {
|
||||||
|
npm = "@ai-sdk/openai-compatible";
|
||||||
|
name = "Halo";
|
||||||
|
options.baseURL = "http://halo:8000/v1";
|
||||||
|
models.coder.name = "coder";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
obsidianSkills =
|
obsidianSkills =
|
||||||
lib.mapAttrs'
|
lib.mapAttrs'
|
||||||
(
|
(
|
||||||
|
|
@ -30,21 +107,16 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
# Formatters referenced by config/opencode/config.json; keep them on PATH for opencode.
|
# The agents/, commands/ and other files come from the repo dir; config.json
|
||||||
home.packages = [
|
# is generated from opencodeConfig above so formatter paths stay pinned.
|
||||||
pkgs.nixfmt-rfc-style
|
|
||||||
pkgs.nodePackages.prettier
|
|
||||||
pkgs.shfmt
|
|
||||||
pkgs.ruff
|
|
||||||
pkgs.taplo
|
|
||||||
pkgs.stylua
|
|
||||||
];
|
|
||||||
|
|
||||||
xdg.configFile."opencode" = {
|
xdg.configFile."opencode" = {
|
||||||
source = ../../../../config/opencode;
|
source = ../../../../config/opencode;
|
||||||
recursive = true;
|
recursive = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
xdg.configFile."opencode/config.json".source =
|
||||||
|
(pkgs.formats.json { }).generate "opencode-config.json" opencodeConfig;
|
||||||
|
|
||||||
home.file = {
|
home.file = {
|
||||||
".agents/skills" = {
|
".agents/skills" = {
|
||||||
source = ../../../../config/agents/skills;
|
source = ../../../../config/agents/skills;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue