Description
Building opencode via the flake.nix fails since 1.4.11, with these errors:
error: Cannot build '/nix/store/hn3z2k8kf5xvbqlgh7nyppvq1124a4mf-opencode-1.14.19+27db54c.drv'.
Reason: builder failed with exit code 1.
Output paths:
/nix/store/lphr5c7lhjrpinradcrc3305sfvnpbz6-opencode-1.14.19+27db54c
Last 25 log lines:
> dist/assets/emacs-lisp-C9XAeP06.js 779.85 kB │ gzip: 196.53 kB
> dist/assets/index-CErAAXVV.js 1,768.24 kB │ gzip: 506.78 kB
>
> (!) Some chunks are larger than 500 kB after minification. Consider:
> - Using dynamic import() to code-split the application
> - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
> - Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
> ✓ built in 5.25s
> building opencode-linux-x64
> 32 | const prettier = await import("prettier")
> ^
> error: Could not resolve: "prettier". Maybe you need to "bun install"?
> at /build/source/packages/opencode/src/cli/cmd/generate.ts:32:35
>
> 33 | const babel = await import("prettier/plugins/babel")
> ^
> error: Could not resolve: "prettier/plugins/babel". Maybe you need to "bun install"?
> at /build/source/packages/opencode/src/cli/cmd/generate.ts:33:32
>
> 34 | const estree = await import("prettier/plugins/estree")
> ^
> error: Could not resolve: "prettier/plugins/estree". Maybe you need to "bun install"?
> at /build/source/packages/opencode/src/cli/cmd/generate.ts:34:33
>
> Bun v1.3.11 (Linux x64)
For full logs, run:
nix log /nix/store/hn3z2k8kf5xvbqlgh7nyppvq1124a4mf-opencode-1.14.19+27db54c.drv
I was able to successfully build with this custom overlay:
{ inputs, ... }:
let
opencodeNodeModules =
{
lib,
stdenvNoCC,
bun,
opencodeSrc,
rev ?
if opencodeSrc ? shortRev then
opencodeSrc.shortRev
else if opencodeSrc ? rev then
opencodeSrc.rev
else
"dirty",
hash,
}:
let
packageJson = lib.pipe (opencodeSrc + "/packages/opencode/package.json") [
builtins.readFile
builtins.fromJSON
];
platform = stdenvNoCC.hostPlatform;
bunCpu = if platform.isAarch64 then "arm64" else "x64";
bunOs = if platform.isLinux then "linux" else "darwin";
in
stdenvNoCC.mkDerivation {
pname = "opencode-node_modules";
version = "${packageJson.version}+${lib.replaceString "-" "." rev}";
src = lib.sources.cleanSource opencodeSrc;
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
"GIT_PROXY_COMMAND"
"SOCKS_SERVER"
];
nativeBuildInputs = [ bun ];
dontConfigure = true;
buildPhase = ''
runHook preBuild
export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
bun install \
--cpu="${bunCpu}" \
--os="${bunOs}" \
--filter './' \
--filter './packages/opencode' \
--filter './packages/desktop' \
--filter './packages/app' \
--filter './packages/shared' \
--frozen-lockfile \
--ignore-scripts \
--no-progress
bun --bun ${opencodeSrc + "/nix/scripts/canonicalize-node-modules.ts"}
bun --bun ${opencodeSrc + "/nix/scripts/normalize-bun-binaries.ts"}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
find . -type d -name node_modules -exec cp -R --parents {} $out \;
runHook postInstall
'';
dontFixup = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = hash;
meta.platforms = [
"aarch64-linux"
"x86_64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
};
in
{
flake.commonModules.development-opencode =
{ pkgs, ... }:
{
nixpkgs.overlays = [
inputs.opencode.overlays.default
(final: prev: {
opencode = prev.opencode.override {
node_modules = final.callPackage opencodeNodeModules {
opencodeSrc = inputs.opencode;
hash =
if final.stdenv.hostPlatform.isDarwin then
"sha256-t16bjKN5f/GCRmIyjv9/RG7PsYLQjUxeAvqo3uG0l9c="
else
"sha256-JjkS8fpYXHCs1h3nGtc8tdSXEMnp6o9aKvsbBx2gvVY=";
};
};
})
];
environment.systemPackages = [
pkgs.opencode
];
};
}
Plugins
No response
OpenCode version
v1.14.19
Steps to reproduce
Try to install opencode with the flake.nix.
Screenshot and/or share link
No response
Operating System
NixOS unstable
Terminal
Ghostty
Description
Building opencode via the
flake.nixfails since 1.4.11, with these errors:I was able to successfully build with this custom overlay:
Plugins
No response
OpenCode version
v1.14.19
Steps to reproduce
Try to install opencode with the flake.nix.
Screenshot and/or share link
No response
Operating System
NixOS unstable
Terminal
Ghostty