node_modules.nix 1.9 KB

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