{ lib, pkgs, config, ... }: let inherit (lib) literalExpression mkEnableOption mkIf mkOption mkPackageOption ; cfg = config.programs.opencode; jsonFormat = pkgs.formats.json { }; in { meta.maintainers = with lib.hm.maintainers; [ delafthi ]; options.programs.opencode = { enable = mkEnableOption "opencode"; package = mkPackageOption pkgs "opencode" { nullable = true; }; settings = mkOption { inherit (jsonFormat) type; default = { }; example = literalExpression '' { theme = "opencode"; model = "anthropic/claude-sonnet-4-20250514"; autoshare = false; autoupdate = true; } ''; description = '' Configuration written to {file}`$XDG_CONFIG_HOME/opencode/config.json`. See for the documentation. ''; }; }; config = mkIf cfg.enable { home.packages = mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile."opencode/config.json" = mkIf (cfg.settings != { }) { source = jsonFormat.generate "config.json" cfg.settings; }; }; }