node_modules.nix 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. --filter './packages/shared' \
  54. --frozen-lockfile \
  55. --ignore-scripts \
  56. --no-progress
  57. bun --bun ${./scripts/canonicalize-node-modules.ts}
  58. bun --bun ${./scripts/normalize-bun-binaries.ts}
  59. runHook postBuild
  60. '';
  61. installPhase = ''
  62. runHook preInstall
  63. mkdir -p $out
  64. find . -type d -name node_modules -exec cp -R --parents {} $out \;
  65. runHook postInstall
  66. '';
  67. dontFixup = true;
  68. outputHashAlgo = "sha256";
  69. outputHashMode = "recursive";
  70. outputHash = hash;
  71. meta.platforms = [
  72. "aarch64-linux"
  73. "x86_64-linux"
  74. "aarch64-darwin"
  75. "x86_64-darwin"
  76. ];
  77. }