node_modules.nix 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {
  2. lib,
  3. stdenvNoCC,
  4. bun,
  5. bunCpu ? if stdenvNoCC.hostPlatform.isAarch64 then "arm64" else "x64",
  6. bunOs ? if stdenvNoCC.hostPlatform.isLinux then "linux" else "darwin",
  7. rev ? "dirty",
  8. hash ?
  9. (lib.pipe ./hashes.json [
  10. builtins.readFile
  11. builtins.fromJSON
  12. ]).nodeModules.${stdenvNoCC.hostPlatform.system},
  13. }:
  14. let
  15. packageJson = lib.pipe ../packages/opencode/package.json [
  16. builtins.readFile
  17. builtins.fromJSON
  18. ];
  19. in
  20. stdenvNoCC.mkDerivation {
  21. pname = "opencode-node_modules";
  22. version = "${packageJson.version}-${rev}";
  23. src = lib.fileset.toSource {
  24. root = ../.;
  25. fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ../.)) (
  26. lib.fileset.unions [
  27. ../packages
  28. ../bun.lock
  29. ../package.json
  30. ../patches
  31. ../install
  32. ]
  33. );
  34. };
  35. impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
  36. "GIT_PROXY_COMMAND"
  37. "SOCKS_SERVER"
  38. ];
  39. nativeBuildInputs = [
  40. bun
  41. ];
  42. dontConfigure = true;
  43. buildPhase = ''
  44. runHook preBuild
  45. export HOME=$(mktemp -d)
  46. export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
  47. bun install \
  48. --cpu="${bunCpu}" \
  49. --os="${bunOs}" \
  50. --frozen-lockfile \
  51. --ignore-scripts \
  52. --no-progress \
  53. --linker=isolated
  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. }