opencode: add web service configuration
Add configuration options for the opencode web service including host, port, mDNS, logging, and CORS settings. Implement systemd user service to run the web server with configurable parameters.
This commit is contained in:
parent
2539eba97a
commit
d9da6e6457
5 changed files with 157 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ let
|
|||
;
|
||||
|
||||
cfg = config.programs.opencode;
|
||||
webCfg = cfg.web;
|
||||
|
||||
jsonFormat = pkgs.formats.json { };
|
||||
|
||||
|
|
@ -87,6 +88,35 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
web = {
|
||||
enable = lib.mkEnableOption "opencode web service";
|
||||
|
||||
extraArgs = mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"--hostname"
|
||||
"0.0.0.0"
|
||||
"--port"
|
||||
"4096"
|
||||
"--mdns"
|
||||
"--cors"
|
||||
"https://example.com"
|
||||
"--cors"
|
||||
"http://localhost:3000"
|
||||
"--print-logs"
|
||||
"--log-level"
|
||||
"DEBUG"
|
||||
];
|
||||
description = ''
|
||||
Extra arguments to pass to the opencode web command.
|
||||
|
||||
These arguments override the "server" options defined in the configuration file.
|
||||
See <https://opencode.ai/docs/web/#config-file> for available options.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
rules = lib.mkOption {
|
||||
type = lib.types.either lib.types.lines lib.types.path;
|
||||
default = "";
|
||||
|
|
@ -443,5 +473,43 @@ in
|
|||
)
|
||||
) cfg.themes
|
||||
);
|
||||
|
||||
systemd.user.services = mkIf webCfg.enable {
|
||||
opencode-web = {
|
||||
Unit = {
|
||||
Description = "OpenCode Web Service";
|
||||
After = [ "network.target" ];
|
||||
};
|
||||
|
||||
Service = {
|
||||
ExecStart = "${lib.getExe cfg.package} web ${lib.escapeShellArgs webCfg.extraArgs}";
|
||||
Restart = "always";
|
||||
RestartSec = 5;
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = [ "default.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
launchd.agents = mkIf webCfg.enable {
|
||||
opencode-web = {
|
||||
enable = true;
|
||||
config = {
|
||||
ProgramArguments = [
|
||||
(lib.getExe cfg.package)
|
||||
"web"
|
||||
]
|
||||
++ webCfg.extraArgs;
|
||||
KeepAlive = {
|
||||
Crashed = true;
|
||||
SuccessfulExit = false;
|
||||
};
|
||||
ProcessType = "Background";
|
||||
RunAtLoad = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue