opencode icon indicating copy to clipboard operation
opencode copied to clipboard

When built from the flake, opencode package is extremely large (4GB+)

Open palekiwi opened this issue 1 month ago • 3 comments

First off, thanks so much for the addition of the flake.nix to the repo. It's been a monumental piece of work that I absolutely rely on.

However, I've noticed that the package built from the flake.nix takes up over 4GB of space.

Below is an AI generated report that may be helpful.

Summary

The OpenCode package is 4.0 GiB, which is excessive. Investigation shows that all platform-specific optional dependencies are being bundled instead of just the required platform.

Environment

  • OpenCode version: v1.0.119
  • Package manager: Bun
  • Platform: Linux x64
  • Installation: Via Nix flake from github:sst/opencode

Issue Details

The OpenCode Nix store package is 4.0 GiB:

$ nix path-info -Sh github:sst/opencode
/nix/store/q3p8pk2qk3ydsi2fdvnjl6raiydwdgyi-opencode-1.0.119  4.0 GiB

Nearly all of this size (4.2GB) comes from node_modules/.bun/ containing platform-specific binaries for all platforms instead of just Linux x64.

Breakdown of Bloat

Platform-specific binaries (only Linux x64 needed, but all platforms included):

  • SST binaries: ~470MB total (6 platforms)

    • sst-darwin-arm64: 77M
    • sst-darwin-x64: 82M
    • sst-linux-arm64: 75M
    • sst-linux-x64: 80M ✅ (only one needed)
    • sst-win32-arm64: 75M
    • sst-win32-x64: 81M
  • Cloudflare Workerd: ~500MB total (5 platforms)

    • @cloudflare/workerd-darwin-64: 99M
    • @cloudflare/workerd-darwin-arm64: 95M
    • @cloudflare/workerd-linux-64: 112M ✅ (only one needed)
    • @cloudflare/workerd-linux-arm64: 116M
    • @cloudflare/workerd-windows-64: 80M
  • Pagefind: ~390MB total (6 platforms)

    • @pagefind/darwin-arm64: 63M
    • @pagefind/darwin-x64: 63M
    • @pagefind/freebsd-x64: 66M
    • @pagefind/linux-arm64: 65M
    • @pagefind/linux-x64: 66M ✅ (only one needed)
    • @pagefind/windows-x64: 63M
  • Turbo: ~200MB total (6 platforms)

    • turbo-darwin-64: 31M
    • turbo-darwin-arm64: 27M
    • turbo-linux-64: 33M ✅ (only one needed)
    • turbo-linux-arm64: 29M
    • turbo-windows-64: 39M
    • turbo-windows-arm64: 39M

Other large dependencies:

  • @ibm/plex fonts: 203MB
  • aws-sdk: 101MB
  • cloudflare: 53MB
  • three: 32MB

Total: 1,898 packages in node_modules/.bun/

palekiwi avatar Nov 28 '25 05:11 palekiwi

This issue might be related to existing nix flake issues. Please check:

  • #4575: opencode binary on macOS arm64 is 0 byte large when building from nix flake (similar flake build problems, though with different symptoms)
  • #4498: Hash mismatch when using opencode flake.nix (related to flake.nix build issues)

These are related to Nix flake build problems. The root cause might be shared - potentially issues with how dependencies are bundled in the Nix sandbox environment.

github-actions[bot] avatar Nov 28 '25 05:11 github-actions[bot]

seems like the nix script has some bugs in it a lot of those packages shouldnt be in the executable

rekram1-node avatar Nov 28 '25 05:11 rekram1-node

Here is the resulting directory structure.

└╼[nix-shell:/nix/store/yfm1d0h42byzy2iawwaghw58bwqys6bd-opencode-1.0.164]$ tree
.
├── bin
│   └── opencode
└── lib
    └── opencode
        ├── dist
        │   ├── src
        │   │   ├── cli
        │   │   │   └── cmd
        │   │   │       └── tui
        │   │   │           ├── parser.worker.js
        │   │   │           └── worker.js
        │   │   └── index.js
        │   ├── tree-sitter-3jzf13jk.wasm
        │   └── tree-sitter-bash-hq5s6fxb.wasm
        └── node_modules
            └── @opentui
                ├── core -> ../.bun/@[email protected]+81ecd8642a1892ca/node_modules/@opentui/core
                ├── core-darwin-arm64 -> ../.bun/@[email protected]/node_modules/@opentui/core-darwin-arm64
                ├── core-darwin-x64 -> ../.bun/@[email protected]/node_modules/@opentui/core-darwin-x64
                ├── core-linux-arm64 -> ../.bun/@[email protected]/node_modules/@opentui/core-linux-arm64
                ├── core-linux-x64 -> ../.bun/@[email protected]/node_modules/@opentui/core-linux-x64
                ├── core-win32-arm64 -> ../.bun/@[email protected]/node_modules/@opentui/core-win32-arm64
                ├── core-win32-x64 -> ../.bun/@[email protected]/node_modules/@opentui/core-win32-x64
                └── solid -> ../.bun/@[email protected]+897ebc1644d3edd0/node_modules/@opentui/solid

The binary in bin is only 52K and is the correct one.

The culprit, as always, is node_modules

$ du -hs *
15M	dist
4.3G	node_modules


$ ls
core  core-darwin-arm64  core-darwin-x64  core-linux-arm64  core-linux-x64  core-win32-arm64  core-win32-x64  solid

podocarp avatar Dec 17 '25 00:12 podocarp