summaryrefslogtreecommitdiffhomepage
path: root/nix/node_modules.nix
diff options
context:
space:
mode:
authorCaleb Norton <[email protected]>2026-01-18 21:46:00 -0600
committerGitHub <[email protected]>2026-01-18 21:46:00 -0600
commit2fc4ab9687219aae4cef5fba042264f7638c5ebc (patch)
treeb69ae3f464b7a1b79f3682e6f22606fcf9de6efc /nix/node_modules.nix
parentd939a3ad547f1794ab39a5455517bedfc310f286 (diff)
downloadopencode-2fc4ab9687219aae4cef5fba042264f7638c5ebc.tar.gz
opencode-2fc4ab9687219aae4cef5fba042264f7638c5ebc.zip
ci: simplify nix hash updates (#9309)
Diffstat (limited to 'nix/node_modules.nix')
-rw-r--r--nix/node_modules.nix85
1 files changed, 85 insertions, 0 deletions
diff --git a/nix/node_modules.nix b/nix/node_modules.nix
new file mode 100644
index 000000000..981a60ef9
--- /dev/null
+++ b/nix/node_modules.nix
@@ -0,0 +1,85 @@
+{
+ lib,
+ stdenvNoCC,
+ bun,
+ bunCpu ? if stdenvNoCC.hostPlatform.isAarch64 then "arm64" else "x64",
+ bunOs ? if stdenvNoCC.hostPlatform.isLinux then "linux" else "darwin",
+ rev ? "dirty",
+ hash ?
+ (lib.pipe ./hashes.json [
+ builtins.readFile
+ builtins.fromJSON
+ ]).nodeModules.${stdenvNoCC.hostPlatform.system},
+}:
+let
+ packageJson = lib.pipe ../packages/opencode/package.json [
+ builtins.readFile
+ builtins.fromJSON
+ ];
+in
+stdenvNoCC.mkDerivation {
+ pname = "opencode-node_modules";
+ version = "${packageJson.version}-${rev}";
+
+ src = lib.fileset.toSource {
+ root = ../.;
+ fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ../.)) (
+ lib.fileset.unions [
+ ../packages
+ ../bun.lock
+ ../package.json
+ ../patches
+ ../install
+ ]
+ );
+ };
+
+ impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
+ "GIT_PROXY_COMMAND"
+ "SOCKS_SERVER"
+ ];
+
+ nativeBuildInputs = [
+ bun
+ ];
+
+ dontConfigure = true;
+
+ buildPhase = ''
+ runHook preBuild
+ export HOME=$(mktemp -d)
+ export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
+ bun install \
+ --cpu="${bunCpu}" \
+ --os="${bunOs}" \
+ --frozen-lockfile \
+ --ignore-scripts \
+ --no-progress \
+ --linker=isolated
+ bun --bun ${./scripts/canonicalize-node-modules.ts}
+ bun --bun ${./scripts/normalize-bun-binaries.ts}
+ runHook postBuild
+ '';
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out
+ find . -type d -name node_modules -exec cp -R --parents {} $out \;
+
+ runHook postInstall
+ '';
+
+ dontFixup = true;
+
+ outputHashAlgo = "sha256";
+ outputHashMode = "recursive";
+ outputHash = hash;
+
+ meta.platforms = [
+ "aarch64-linux"
+ "x86_64-linux"
+ "aarch64-darwin"
+ "x86_64-darwin"
+ ];
+}