nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1> [!IMPORTANT]
2> There is currently an active project to [remove packages from `nodePackages`](https://github.com/NixOS/nixpkgs/issues/229475).
3> Please consider adding new packages using [another method](https://nixos.org/manual/nixpkgs/unstable/#javascript-tool-specific).
4
5This folder contains a generated collection of [npm packages](https://npmjs.com/) that can be installed with the Nix package manager.
6
7As a rule of thumb, the package set should only provide _end-user_ software packages, such as command-line utilities.
8Libraries should only be added to the package set if there is a non-npm package that requires it.
9
10When it is desired to use npm libraries in a development project, use the `node2nix` generator directly on the `package.json` configuration file of the project.
11
12The package set provides support for the official stable Node.js versions.
13The latest stable LTS release in `nodePackages`, as well as the latest stable current release in `nodePackages_latest`.
14
15If your package uses native addons, you need to examine what kind of native build system it uses. Here are some examples:
16
17- `node-gyp`
18- `node-gyp-builder`
19- `node-pre-gyp`
20
21After you have identified the correct system, you need to override your package expression while adding the build system as a build input.
22For example, `dat` requires `node-gyp-build`, so we override its expression in [pkgs/development/node-packages/overrides.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/node-packages/overrides.nix):
23
24```nix
25{
26 dat = prev.dat.override (oldAttrs: {
27 buildInputs = [
28 final.node-gyp-build
29 pkgs.libtool
30 pkgs.autoconf
31 pkgs.automake
32 ];
33 meta = oldAttrs.meta // {
34 broken = since "12";
35 };
36 });
37}
38```
39
40### Adding and updating JavaScript packages in Nixpkgs
41
42To add a package from npm to Nixpkgs:
43
441. Modify [pkgs/development/node-packages/node-packages.json](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/node-packages/node-packages.json) to add, update or remove package entries to have it included in `nodePackages` and `nodePackages_latest`.
452. Run the script:
46
47 ```sh
48 ./pkgs/development/node-packages/generate.sh
49 ```
50
513. Build your new package to test your changes:
52
53 ```sh
54 nix-build -A nodePackages.<new-or-updated-package>
55 ```
56
57 To build against the latest stable current Node.js version (e.g. 18.x):
58
59 ```sh
60 nix-build -A nodePackages_latest.<new-or-updated-package>
61 ```
62
63 If the package doesn't build, you may need to add an override as explained above.
644. Add and commit all modified and generated files.
65
66For more information about the generation process, consult the [README.md](https://github.com/svanderburg/node2nix) file of the `node2nix` tool.
67
68To update npm packages in Nixpkgs, run the same `generate.sh` script:
69
70```sh
71./pkgs/development/node-packages/generate.sh
72```
73
74#### Git protocol error
75
76Some packages may have Git dependencies from GitHub specified with `git://`.
77GitHub has [disabled unencrypted Git connections](https://github.blog/2021-09-01-improving-git-protocol-security-github/#no-more-unauthenticated-git), so you may see the following error when running the generate script:
78
79```
80The unauthenticated git protocol on port 9418 is no longer supported
81```
82
83Use the following Git configuration to resolve the issue:
84
85```sh
86git config --global url."https://github.com/".insteadOf git://github.com/
87```