@@ -239,6 +239,7 @@ Consult previous versions of this document for older versions of Node.js:
239
239
240
240
Installation via Linux package manager can be achieved with:
241
241
242
+ * Nix, NixOS: ` nix-shell `
242
243
* Ubuntu, Debian: ` sudo apt-get install python3 g++-12 gcc-12 make python3-pip `
243
244
* Fedora: ` sudo dnf install python3 gcc-c++ make python3-pip `
244
245
* CentOS and RHEL: ` sudo yum install python3 gcc-c++ make python3-pip `
@@ -259,6 +260,75 @@ installed, you can find them under the menu `Xcode -> Open Developer Tool ->
259
260
More Developer Tools...` . This step will install ` clang` , ` clang++`, and
260
261
` make ` .
261
262
263
+ #### Nix integration
264
+
265
+ If you are using Nix and direnv, you can use the following to get started:
266
+
267
+ ``` bash
268
+ echo ' use_nix --arg sharedLibDeps {} --argstr icu small' > .envrc
269
+ direnv allow .
270
+ make build-ci -j12
271
+ ```
272
+
273
+ The use of ` make build-ci ` is to ensure you are using the ` CONFIG_FLAGS `
274
+ environment variable. You can also specify it manually:
275
+
276
+ ``` bash
277
+ ./configure $CONFIG_FLAGS
278
+ make -j12
279
+ ```
280
+
281
+ Passing the ` --arg sharedLibDeps {} ` instructs direnv and Nix to generate an
282
+ environment that uses the vendored-in native dependencies. Using the vendored-in
283
+ dependencies result in a result closer to the official binaries, the tradeoff
284
+ being the build will take longer to complete as you'd have to build those
285
+ dependencies instead of using the cached ones from the Nix cache. You can omit
286
+ that flag to use all the shared dependencies, or specify only some dependencies:
287
+
288
+ ``` bash
289
+ cat -> .envrc << 'EOF '
290
+ use nix --arg sharedLibDeps '{
291
+ inherit (import <nixpkgs> {})
292
+ openssl
293
+ zlib
294
+ ;
295
+ }'
296
+ EOF
297
+ ```
298
+
299
+ Passing the ` --argstr icu small ` instructs direnv and Nix to pass ` --with-intl=small ` in
300
+ the ` CONFIG_FLAGS ` environment variable. If you omit this, the prebuilt ICU from Nix cache
301
+ will be used, which should speed up greatly compilation time.
302
+
303
+ The use of ` direnv ` is completely optional, you can also use ` nix-shell ` directly,
304
+ e.g. here's a command you can use to build a binary for benchmarking purposes:
305
+
306
+ ``` bash
307
+ # Passing `--arg loadJSBuiltinsDynamically false` to instruct the compiler to
308
+ # embed the JS core files so it is no longer affected by local changes
309
+ # (necessary for getting useful benchmark results).
310
+ # Passing `--arg devTools '[]' --arg benchmarkTools '[]'` since we don't need
311
+ # those to build node.
312
+ nix-shell \
313
+ --arg loadJSBuiltinsDynamically false \
314
+ --arg devTools ' []' --arg benchmarkTools ' []' \
315
+ --run ' make build-ci -j12'
316
+
317
+ mv out/Release/node ./node_old
318
+
319
+ # ...
320
+ # Make your local changes, and re-build node
321
+
322
+ nix-shell \
323
+ --arg loadJSBuiltinsDynamically false \
324
+ --arg devTools ' []' --arg benchmarkTools ' []' \
325
+ --run ' make build-ci -j12'
326
+
327
+ nix-shell --pure --run ' ./node benchmark/compare.js --old ./node_old --new ./node http | Rscript benchmark/compare.R'
328
+ ```
329
+
330
+ There are additional attributes you can pass, see ` shell.nix ` file for more details.
331
+
262
332
#### Building Node.js
263
333
264
334
If the path to your build directory contains a space, the build will likely
@@ -267,7 +337,6 @@ fail.
267
337
To build Node.js:
268
338
269
339
``` bash
270
- export CXX=g++-12
271
340
./configure
272
341
make -j4
273
342
```
0 commit comments