node_modules.nix 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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}-${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
  33. ]
  34. );
  35. };
  36. impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
  37. "GIT_PROXY_COMMAND"
  38. "SOCKS_SERVER"
  39. ];
  40. nativeBuildInputs = [ bun ];
  41. dontConfigure = true;
  42. buildPhase = ''
  43. runHook preBuild
  44. export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
  45. bun install \
  46. --cpu="${bunCpu}" \
  47. --os="${bunOs}" \
  48. --filter '!./' \
  49. --filter './packages/opencode' \
  50. --filter './packages/desktop' \
  51. --frozen-lockfile \
  52. --ignore-scripts \
  53. --no-progress
  54. bun --bun ${./scripts/canonicalize-node-modules.ts}
  55. bun --bun ${./scripts/normalize-bun-binaries.ts}
  56. runHook postBuild
  57. '';
  58. installPhase = ''
  59. runHook preInstall
  60. mkdir -p $out
  61. find . -type d -name node_modules -exec cp -R --parents {} $out \;
  62. runHook postInstall
  63. '';
  64. dontFixup = true;
  65. outputHashAlgo = "sha256";
  66. outputHashMode = "recursive";
  67. outputHash = hash;
  68. meta.platforms = [
  69. "aarch64-linux"
  70. "x86_64-linux"
  71. "aarch64-darwin"
  72. "x86_64-darwin"
  73. ];
  74. }