node_modules.nix 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {
  2. lib,
  3. stdenvNoCC,
  4. bun,
  5. rev ? "dirty",
  6. hash ?
  7. (lib.pipe ./hashes.json [
  8. builtins.readFile
  9. builtins.fromJSON
  10. ]).nodeModules.${stdenvNoCC.hostPlatform.system},
  11. }:
  12. let
  13. packageJson = lib.pipe ../packages/opencode/package.json [
  14. builtins.readFile
  15. builtins.fromJSON
  16. ];
  17. platform = stdenvNoCC.hostPlatform;
  18. bunCpu = if platform.isAarch64 then "arm64" else "x64";
  19. bunOs = if platform.isLinux then "linux" else "darwin";
  20. in
  21. stdenvNoCC.mkDerivation {
  22. pname = "opencode-node_modules";
  23. version = "${packageJson.version}+${lib.replaceString "-" "." rev}";
  24. src = lib.fileset.toSource {
  25. root = ../.;
  26. fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ../.)) (
  27. lib.fileset.unions [
  28. ../packages
  29. ../bun.lock
  30. ../package.json
  31. ../patches
  32. ../install # required by desktop build (cli.rs include_str!)
  33. ../.github/TEAM_MEMBERS # required by @opencode-ai/script
  34. ]
  35. );
  36. };
  37. impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
  38. "GIT_PROXY_COMMAND"
  39. "SOCKS_SERVER"
  40. ];
  41. nativeBuildInputs = [ bun ];
  42. dontConfigure = true;
  43. buildPhase = ''
  44. runHook preBuild
  45. export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
  46. bun install \
  47. --cpu="${bunCpu}" \
  48. --os="${bunOs}" \
  49. --filter '!./' \
  50. --filter './packages/opencode' \
  51. --filter './packages/desktop' \
  52. --filter './packages/app' \
  53. --frozen-lockfile \
  54. --ignore-scripts \
  55. --no-progress
  56. bun --bun ${./scripts/canonicalize-node-modules.ts}
  57. bun --bun ${./scripts/normalize-bun-binaries.ts}
  58. runHook postBuild
  59. '';
  60. installPhase = ''
  61. runHook preInstall
  62. mkdir -p $out
  63. find . -type d -name node_modules -exec cp -R --parents {} $out \;
  64. runHook postInstall
  65. '';
  66. dontFixup = true;
  67. outputHashAlgo = "sha256";
  68. outputHashMode = "recursive";
  69. outputHash = hash;
  70. meta.platforms = [
  71. "aarch64-linux"
  72. "x86_64-linux"
  73. "aarch64-darwin"
  74. "x86_64-darwin"
  75. ];
  76. }