Commit Graph

309 Commits

Author SHA1 Message Date
Jörg Thalheim
0cb5de2d62 prefetch-npm-deps: use package name field for aliases
npm lockfiles can contain package aliases where the lockfile key differs
from the actual package name (e.g., "string-width-cjs" aliasing
"string-width"). Previously we always used the lockfile key, causing us
to fetch packuments for the wrong package.

Use the package's own "name" field when present, falling back to the
lockfile key. This ensures we fetch the correct packument for aliased
packages, fixing non-deterministic builds where the wrong packument
fetch could succeed or fail depending on network timing.
2025-12-31 07:53:32 +00:00
Jörg Thalheim
40f1b80ac7 prefetch-npm-deps: clarify backwards compatibility comment 2025-12-31 06:57:27 +00:00
Jörg Thalheim
3fb4fe294b prefetch-npm-deps: extract package names from lockfile keys
The current approach parses tarball URLs to extract package names for
packument fetching. This is fragile as it only handles npmjs.org URLs
and requires special-casing other registries.

Use lockfile keys directly instead. The lockfile already contains the
canonical package names in the form "node_modules/@scope/name", so we
can simply strip the prefix rather than parsing URLs.

This handles all registries uniformly and eliminates the URL parsing
code along with its tests.
2025-12-31 06:37:24 +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
Jonathan Davies
22526da87d prefetch-npm-deps: Enable full LTO 2025-12-19 21:53:26 +00:00
Jonathan Davies
bb37dfe300 prefetch-npm-deps: Bump edition to 2024 and apply cargo clippy and rustfmt fixes 2025-12-19 21:53:22 +00:00
Jonathan Davies
1cfd281c2c prefetch-npm-deps: Run cargo update 2025-12-19 21:53:21 +00:00
Jonathan Davies
ca4684c9a3 prefetch-npm-deps: Fix isahc default-features 2024 warning 2025-12-19 21:53:13 +00:00
Jonathan Davies
ff1906466c prefetch-npm-deps: Rename directory to match name 2025-12-19 21:53:02 +00:00
Sefa Eyeoglu
63cdea5359 fetchPnpmDeps: allow passing existing derivation args
Previously, users had to add hacks to add additional nativeBuildInputs
entries to the fetcher. This way we allow users to append
nativeBuildInputs, impureEnvVars and also merge potential passthru
attributes.

This might cause rebuilds.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
2025-12-18 12:24:09 +01:00
Sefa Eyeoglu
65b04e5fb8 treewide: migrate to fetchPnpmDeps and pnpmConfigHook
This moves all packages to the new top-level attributes introduced
previously.

This doesn't cause any rebuilds.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
2025-12-18 12:24:09 +01:00
Sefa Eyeoglu
d925565179 fetchPnpmDeps,pnpmConfigHook: move to top-level attribute
move pnpm.{fetchDeps,configHook} to fetchPnpmDeps and pnpmConfigHook
respectively. Also adds aliases to the former package-level attributes.

Additionally, pnpmConfigHook does not propagate pnpm anymore, to make
changing pnpm versions easier.

This brings pnpm in line with the other Node.js/JavaScript tooling in
nixpkgs.

This doesn't cause any rebuilds.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
2025-12-17 23:43:59 +01:00
Ihar Hrachyshka
567e8dfd8e treewide: clean up 'meta = with' pattern
This commit was created by a combination of scripts and tools:
- an ast-grep script to prefix things in meta with `lib.`,
- a modified nixf-diagnose / nixf combination to remove unused `with
lib;`, and
- regular nixfmt.

Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
2025-12-10 18:09:49 +01:00
dish
86fb272649 yarnInstallHook: add meta.description
Makes search.nixos.org give the correct location for the package and
also helps users better understand it
2025-11-24 12:14:54 -05:00
Antoine du Hamel
5b74cebfbc prefetch-npm-deps: add support for npm-shrinkwrap.json 2025-11-09 16:27:54 +01:00
Alexander Bantyev
c3a465a6de config: add npmRegistryOverrides option
Adds npmRegistryOverrides, to be passed through to `fetchNpmDeps`.
2025-10-17 15:19:57 +04:00
Alexander Bantyev
ac3eccd296 fetchNpmDeps: add an npmRegistryOverrides argument
Adds an `npmRegistryOverrides` argument & variable to fetchNpmDeps
& prefetch-npm-deps. This is similar in usage to `url.<url>.insteadOf`
in `.gitconfig`, allowing one to redirect requests to a registry to
another URL.
2025-10-17 15:19:56 +04:00
nixpkgs-ci[bot]
e23d356469 Merge staging-next into staging 2025-10-05 00:18:23 +00:00
NAHO
c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00
Antoine du Hamel
3ef36b4fd0 buildNpmPackage: add support for npm-shrinkwrap.json 2025-09-22 17:50:12 +02:00
K900
8eb75c9e73 Merge remote-tracking branch 'origin/master' into staging-next 2025-08-18 15:14:49 +03:00
Alexander Sieg
2323653633 fetch-yarn-deps: follow relative redirects 2025-08-11 18:02:56 +02:00
Wolfgang Walther
90604d95bc Merge branch 'staging-next' into staging 2025-07-24 14:33:09 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
nixpkgs-ci[bot]
a506444d89 Merge staging-next into staging 2025-07-23 18:05:43 +00:00
Philip Taron
c98749388a importNpmLock: fix native dependencies for Darwin (#423199) 2025-07-23 08:01:57 -07:00
Philip Taron
77dca5875a treewide: populate arch and platform for more node packages (#422938) 2025-07-15 09:18:57 -07:00
Philip Taron
2f9b4fe37e importNpmLock: Don't create intermediate symlink files (#425009) 2025-07-14 20:51:13 -07:00
adisbladis
db7050bb88 importNpmLock: Don't create intermediate symlink files
It's currently possible to run into a race condition when entering the same development environment concurrently:
```
❯ git fetch; jj rebase -b 'all:mutable() & mine()' -d main@origin --skip-emptied
Rebased 4 commits onto destination
Abandoned 1 newly emptied commits
Working copy  (@) now at: tnyknvqt 93e36def (empty) (no description set)
Parent commit (@-)      : wnqxqyyl e0983a05 main@origin | Increase limit of max number of words
Added 0 files, modified 8 files, removed 0 files
direnv: loading ~/dev/REDACTED/.envrc
direnv: loading https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc (sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4=)
Executing linkNodeModulesHook
node:internal/fs/promises:782
  return await PromisePrototypeThen(
         ^

Error: ENOENT: no such file or directory, rename 'node_modules/.bin-nix-hook-temp' -> 'node_modules/.bin'
    at async Object.rename (node:internal/fs/promises:782:10)
    at async /nix/store/ps9ivjjxzi0fks67j6vd4gbw5dcnhp0w-link-node-modules.js:84:7
    at async Promise.all (index 0)
    at async main (/nix/store/ps9ivjjxzi0fks67j6vd4gbw5dcnhp0w-link-node-modules.js:58:3) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: 'node_modules/.bin-nix-hook-temp',
  dest: 'node_modules/.bin'
}

Node.js v20.17.0
Finished executing linkNodeModulesShellHook
```

This change removes the intermediate file creation and simply tries to create a symlink directly.
If the target `node_modules/foo` already exists we unlink it and try to create the symlink again.
2025-07-14 18:43:05 +12:00
Moritz Heidkamp
da4672b591 importNpmLock: fix native dependencies for Darwin
Essentially the same fix as 79459354cb for `buildNpmPackage`.
2025-07-07 15:33:28 +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
Wolfgang Walther
3d4c1c0d26 .editorconfig: two spaces for .js files
Most other scripting languages we use in tree have the same.
2025-06-23 14:54:45 +02:00
uonr
339d1d1cb1 importNpmLock: handle "resolved" is null 2025-04-30 18:52:11 +09:00
Doron Behar
9732e5125c prefetch-yarn-deps: fix resolving of local packages using file: (#387313) 2025-04-29 18:23:14 +03:00
K900
1d039734de Merge remote-tracking branch 'origin/master' into staging-next 2025-04-10 16:30:48 +03:00
K900
460cbc8c6c prefetch-yarn-deps: don't explicitly depend on nixForLinking
See: https://github.com/NixOS/nixpkgs/pull/395147
2025-04-07 21:51:59 +03: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
Silvan Mosberger
e52d633a63 Merge remote-tracking branch 'upstream/staging-next' into staging 2025-04-02 18:30:54 +02:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +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
jade
31f7f3fc9e nixForLinking: init (#384099) 2025-03-12 10:13:54 -07:00
Yureka
c1c82774ae yarnConfigHook: add yarn.lock consistency check (#387316) 2025-03-05 21:16:12 +01:00