66 Commits

Author SHA1 Message Date
Antoine du Hamel 8bd4119182 buildNpmPackage: remove double dependencies on nodejs+nodejs-slim 2026-05-28 11:36:13 +02:00
Sigmanificient 0bbc8dffae treewide: set meta.license on hooks 2026-05-25 13:48:20 +02:00
Bjørn Forsman 652d2da182 npmBuildHook: fix logging of the build command
The command `npm run` is wrongly logged as `npm build`. Fix it. Also,
the build script can be overridden, so log what is actually used:

  npm run $npmBuildScript [...]
2026-04-25 10:59:51 +02:00
nixpkgs-ci[bot] 802fb99f64 Merge master into staging-next 2026-04-17 18:18:45 +00:00
Antoine du Hamel 201ccf894a treewide: fix mentions for nodejs.python 2026-03-31 14:23:37 +02:00
Stefan Frijters d66b335e05 build-support/node/build-npm-package: fix npm-config-hook.sh for structuredAttrs
Do not rely on npmDeps being exported.
2026-03-05 11:29:15 +01:00
Jörg Thalheim ab89ffc4b1 fetchNpmDeps: rename cacheVersion to fetcherVersion
To align with pnpm tooling.
2026-01-03 18:45:33 +00:00
Winter d028ea9cd8 npmConfigHook: suggest cache v2 when npm install fails 2025-12-31 00:37:52 -05:00
Winter f297c444c2 npmConfigHook: always make cache writable when using cache v2 2025-12-31 00:37:52 -05:00
Winter 0b66fed9d7 buildNpmPackage: add diagnostic for cache version mismatch 2025-12-31 00:37:52 -05:00
Jörg Thalheim 5c99ffcb8e prefetch-npm-deps: add cacheVersion for packument support
Add a cacheVersion parameter to fetchNpmDeps and npmDepsCacheVersion to
buildNpmPackage. When set to 2, prefetch-npm-deps will also fetch and
cache packuments (package metadata) in addition to tarballs.

npm can request packuments with two different Accept headers:
- corgiDoc: abbreviated metadata (default)
- fullDoc: full metadata (used for workspaces)

npm's cache policy requires headers to match, so we cache both versions.

This is opt-in via cacheVersion to avoid breaking existing hashes.
Set npmDepsCacheVersion = 2 for projects using npm workspaces.

Also fix cacache index format to properly separate multiple entries
with newlines, and update map_cache() to parse multi-line index files.
2025-12-31 00:37:52 -05:00
Antoine du Hamel 3ef36b4fd0 buildNpmPackage: add support for npm-shrinkwrap.json 2025-09-22 17:50:12 +02:00
Colin faeab3c841 buildNpmPackage: push npm_config_* options into npmHooks.npmConfigHook
these options affect npm generally, and aren't specific to our
`buildNpmPackage`. pushing these options into the `npmConfigHook` (which
is used by `buildNpmPackage`, among others) makes them available to more
packages, especially to enable cross compilation.
2025-07-07 03:08:13 +00:00
Colin 8199f6b551 treewide: replace node platform mapping with stdenv.hostPlatform.node.{arch,platform} 2025-07-07 03:08:06 +00:00
K900 30830c6791 Merge remote-tracking branch 'origin/staging-next' into staging 2025-04-03 09:16:43 +03:00
Herwig Hochleitner 1e9054da3b Don't pass nativeBuildInputs from buildNpmPackage to fetchNpmDeps
This partially reverts commit fff29a3e5f.
2025-04-02 20:37:36 +02:00
Audrey Dutcher c522c987ca buildNpmPackage: fix cross builds 2025-03-18 14:08:21 -07:00
Herwig Hochleitner fff29a3e5f buildNpmPackage: pass nativeBuildInputs to npmDeps (for patch phase) 2025-03-16 16:40:31 +05:30
John Titor e6ca2b65ca buildNpmPackage: nixfmt 2025-03-15 16:13:05 +05:30
John Titor 70ae16e6bf buildNpmPackage: restructure with lib.extendMkDerivation
This allows using finalAttrs pattern.
2025-03-15 16:11:45 +05:30
K900 226cece119 buildNpmPackage: avoid using npm config (#373220) 2025-02-09 09:29:40 +03:00
Isaac Shapira 117929b9cc buildNpmPackage: avoid using npm config 2025-01-12 16:21:53 +01:00
Doron Behar 0fc94b12c7 npmHooks.npmInstallHook: inherit nodejs when evaluating nodejsInstallExecutables
Otherwise, using the following:

```
buildNpmPackage' = buildNpmPackage.override {
  nodejs = nodejs_20;
};
```

Doesn't override the nodejs version used by the `npmInstallHook`, that
is actually used as the nodejs executable of the wrapper created by
`makeWrapper` in the default `installPhase`.
2025-01-11 23:38:36 +02:00
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
Christoph Heiss f52c685f97 buildNpmPackage: pass down patchFlags to fetchNpmDeps
`fetchNpmDeps` works from the exact same source tree, thus `patchFlags`
must be respected so that any patches get applied correctly.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
2024-10-23 21:28:12 +02:00
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00
lelgenio 80a2825733 npmHooks.npmInstallHook: extract npmInstall{Manuals,Executables} 2024-08-26 20:43:42 -03:00
Randy Eckenrode f9b7f4ec09 tree-wide: use top-level cctools 2024-07-17 22:36:19 -04:00
Lily Foster ae86a507ed npmHooks.npmInstallHook: ignore bundle deps when calculating files to install
This assumes that downstream users of `buildNpmPackage` would rather our
own built `node_modules` be copied to the output rather than only the
`bundleDependencies` specified in the `package.json` file.

Having the latter behavior seems unexpected and unintuitive, and would
not work as installing from an `npm pack` is intended to (since doing
that would not do a `rebuild` step on those dependencies and it would
skip reifying a full dependency tree).
2024-03-14 14:04:51 +01:00
adisbladis b6e4b86809 importNpmLock: init
This is an alternative to `fetchNpmDeps` that is notably different in that it uses metadata from `package.json` & `package-lock.json` instead of specifying a fixed-output hash.

Notable features:
- IFD free.
- Only fetches a node dependency once. No massive FODs.
- Support for URL, Git and path dependencies.
- Uses most of the existing `npmHooks`

`importNpmLock` can be used _only_ in the cases where we need to check in a `package-lock.json` in the tree.
Currently this means that we have 13 packages that would be candidates to use this function, though I expect most usage to be in private repositories.

This is upstreaming the builder portion of https://github.com/adisbladis/buildNodeModules into nixpkgs (different naming but the code is the same).
I will archive this repository and consider nixpkgs the new upstream once it's been merged.

For more explanations and rationale see https://discourse.nixos.org/t/buildnodemodules-the-dumbest-node-to-nix-packaging-tool-yet/35733

Example usage:
``` nix
stdenv.mkDerivation {
  pname = "my-nodejs-app";
  version = "0.1.0";

  src = ./.;

  nativeBuildInputs = [
    importNpmLock.hooks.npmConfigHook
    nodejs
    nodejs.passthru.python # for node-gyp
    npmHooks.npmBuildHook
    npmHooks.npmInstallHook
  ];

  npmDeps = buildNodeModules.fetchNodeModules {
    npmRoot = ./.;
  };
}
```
2024-03-05 12:23:28 +13:00
Lily Foster 8999c9d930 npmHooks.npmInstallHook: ignore rather than error for missing bin/man keys in package.json 2023-12-24 22:58:32 +01:00
Lily Foster b5ca84b450 npmHooks.npmInstallHook: only overwrite npm cache for npm pack rather than for entire hook 2023-12-05 21:53:59 +01:00
Lily Foster 8e3009d95c buildNpmPackage: add forceEmptyCache option 2023-11-22 15:18:49 -05:00
midchildan 79459354cb buildNpmPackages: add missing deependencies 2023-11-17 07:58:58 +00:00
happysalada 7fb490674f buildNpmPackage: allow passing npmDeps 2023-11-16 11:57:48 +00:00
Janik 582f1e7321 Merge pull request #254420 from lilyinstarlight/fix/npm-pack-pls-😭
npmHooks.npmInstallHook: avoid script output in npm pack command
2023-11-13 22:43:57 +01:00
Yt 5aaeafbe26 buildNpmPackage: make nodejs overridable (#265171)
* buildNpmPackage: allow nodejs to be passed as argument

* Update doc/languages-frameworks/javascript.section.md

Co-authored-by: Lily Foster <lily@lily.flowers>

---------

Co-authored-by: Lily Foster <lily@lily.flowers>
2023-11-09 16:19:24 +00:00
Doron Behar d090cd9af4 Merge pull request #258384 from doronbehar/buildNpmPackage-makeWrapperArgs
buildNpmPackage: support makeWrapperArgs
2023-10-08 12:38:33 +03:00
Sandro 30992a8c51 buildNpmPackage: give a hint when npm prune fails
Co-authored-by: Lily Foster <lily@lily.flowers>
2023-10-07 21:53:56 +02:00
Doron Behar fc96f6d0fd buildNpmPackage: support makeWrapperArgs 2023-10-07 14:09:05 +03:00
Lily Foster 9b2ca17abc npmHooks.npmInstallHook: avoid script output in npm pack command 2023-09-10 10:31:41 -04:00
sternenseemann bd374243c0 npmHooks: use adjacent packages, not buildPackages
Hooks are essentially implemented as special shell packages that run on
their respective host platform. When they are used, they appear as
nativeBuildInputs (as they need to be executed as part of the build of a
package using them) so are taken from buildPackages relative to the
derivation using them.

Since the override in buildNpmPackage nullifies splicing, we take
npmHooks from buildPackages manually.

Fixes pkgsCross.ghcjs.buildPackages.emscripten and thus
pkgsCross.ghcjs.haskellPackages.ghc.
2023-09-09 17:55:37 +02:00
Robert Schütz 96e5dce777 buildNpmPackage: use installManPage 2023-08-19 10:04:00 -07:00
Pierre Bourdon 28693fb1c3 buildNpmPackage: symlink manpages to the correct output directory 2023-08-18 12:41:05 +02:00
Stanislav Asunkin 38ca04ed64 buildNpmPackage: remove redundant passthru.npmDeps 2023-07-15 10:29:55 +03:00
Lily Foster 19e48f0da9 buildNpmPackage: add npmWorkspace and npmPruneFlags args 2023-06-29 07:42:25 -04:00
Winter f9138c5ad6 npmHooks.npmInstallHook: allow disabling npm prune invocation
In some odd scenarios, `npm prune` either fails, or hangs. I have no idea
what could possibly be wrong at the moment, but let's provide an escape
hatch for packages that can still use the rest of the install hook's
functionality.
2023-05-28 00:47:54 -04:00
Winter 9117f01272 npmHooks.npmConfigHook: add npmRoot option 2023-05-21 17:26:22 -04:00
Winter 9f264f69f8 buildNpmPackage: use nodejs patch flag to work around roadblocks 2023-05-20 18:29:43 -04:00
Winter ac35d7ea86 prefetch-npm-deps: look up hashes from cache when fixing up lockfiles 2023-04-30 10:29:46 -04:00