{pkgs, ...}: let
  languages = import ./_languages.nix {inherit pkgs;};
  providers = import ./_providers.nix;
  skills = import ./_skills.nix {inherit pkgs;};

  inherit (pkgs) opencode;

  opencodeEnv = pkgs.buildEnv {
    name = "opencode-env";
    paths =
      languages.packages
      ++ skills.packages;
  };
  opencodeInitScript = pkgs.writeShellScript "opencode-init" ''
    mkdir -p "$HOME/.local/cache/opencode/node_modules/@opencode-ai"
    mkdir -p "$HOME/.config/opencode/node_modules/@opencode-ai"
    if [ -d "$HOME/.config/opencode/node_modules/@opencode-ai/plugin" ]; then
      if [ ! -L "$HOME/.local/cache/opencode/node_modules/@opencode-ai/plugin" ]; then
        ln -sf "$HOME/.config/opencode/node_modules/@opencode-ai/plugin" \
               "$HOME/.local/cache/opencode/node_modules/@opencode-ai/plugin"
      fi
    fi
    exec ${opencode}/bin/opencode "$@"
  '';
  opencodeWrapped =
    pkgs.runCommand "opencode-wrapped" {
      buildInputs = [pkgs.makeWrapper];
    } ''
      mkdir -p $out/bin
      makeWrapper ${opencodeInitScript} $out/bin/opencode \
        --prefix PATH : ${opencodeEnv}/bin \
        --prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath [pkgs.stdenv.cc.cc.lib]}"
    '';
   configFile = "opencode/config.json";
   tuiFile = "opencode/tui.json";
 in {
   users.users.someone.packages = [
     opencodeWrapped
   ];
   xdg.configFile = {
     "${configFile}".text = builtins.toJSON {
       "$schema" = "https://opencode.ai/config.json";
        plugin = [
        "opencode-antigravity-auth@latest"
        "@tarquinen/opencode-dcp@latest"
        "oh-my-openagent@latest"
        ];
       small_model = "google/gemma-3n-e4b-it:free";
       autoupdate = false;
       share = "disabled";
       disabled_providers = [
         "amazon-bedrock"
         "anthropic"
         "azure-openai"
         "azure-cognitive-services"
         "baseten"
         "cerebras"
         "cloudflare-ai-gateway"
         "cortecs"
         "deep-infra"
         "fireworks-ai"
         "google-vertex-ai"
         "groq"
         "hugging-face"
         "helicone"
         "llama.cpp"
         "io-net"
         "lmstudio"
         "moonshot-ai"
         "nebius-token-factory"
         "ollama"
         "ollama-cloud"
         "openai"
         "sap-ai-core"
         "ovhcloud-ai-endpoints"
         "together-ai"
         "venice-ai"
         "xai"
         "zai"
         "zenmux"
       ];
       enabled_providers = ["opencode" "google" "openrouter"];
       mcp = {
         gh_grep = {
           type = "remote";
           url = "https://mcp.grep.app/";
           enabled = true;
           timeout = 10000;
         };
         deepwiki = {
           type = "remote";
           url = "https://mcp.deepwiki.com/mcp";
           enabled = true;
           timeout = 10000;
         };
         context7 = {
           type = "remote";
           url = "https://mcp.context7.com/mcp";
           enabled = true;
           timeout = 10000;
         };
       };
       inherit (languages) formatter lsp;
       provider = providers.config;
     };
     "${tuiFile}".text = builtins.toJSON {
       "$schema" = "https://opencode.ai/tui.json";
       theme = "gruvbox";
     };
     "opencode/skill".source = skills.skillsSource + "/skill";
   };
 }
