node_modules.nix 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 HOME=$(mktemp -d)
  45. export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
  46. bun install \
  47. --cpu="${bunCpu}" \
  48. --os="${bunOs}" \
  49. --frozen-lockfile \
  50. --ignore-scripts \
  51. --no-progress \
  52. --linker=isolated
  53. bun --bun ${./scripts/canonicalize-node-modules.ts}
  54. bun --bun ${./scripts/normalize-bun-binaries.ts}
  55. runHook postBuild
  56. '';
  57. installPhase = ''
  58. runHook preInstall
  59. mkdir -p $out
  60. find . -type d -name node_modules -exec cp -R --parents {} $out \;
  61. runHook postInstall
  62. '';
  63. dontFixup = true;
  64. outputHashAlgo = "sha256";
  65. outputHashMode = "recursive";
  66. outputHash = hash;
  67. meta.platforms = [
  68. "aarch64-linux"
  69. "x86_64-linux"
  70. "aarch64-darwin"
  71. "x86_64-darwin"
  72. ];
  73. }