Skip to content

npmHooks.npmConfigHook: add npmRoot option#230991

Merged
lilyinstarlight merged 2 commits intoNixOS:masterfrom
winterqt:add-npm-root
May 22, 2023
Merged

npmHooks.npmConfigHook: add npmRoot option#230991
lilyinstarlight merged 2 commits intoNixOS:masterfrom
winterqt:add-npm-root

Conversation

@winterqt
Copy link
Member

@winterqt winterqt commented May 10, 2023

Description of changes

Only, what, 48 hours late?

Told you it was simple! Would appreciate if someone would test, then I'll document and we can land. Thanks!

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels May 10, 2023
@winterqt
Copy link
Member Author

...I forgot to pushd/popd...

@ajs124 Can I just add a commit that implements #230092 in this PR so we can test the implementation here?

@mweinelt
Copy link
Member

Feel free to pick #229953.

@ajs124
Copy link
Member

ajs124 commented May 10, 2023

@ajs124 Can I just add a commit that implements #230092 in this PR so we can test the implementation here?

sure, feel free

@mweinelt
Copy link
Member

After setting

  npmRoot = "ui";

on the navidrome derivation I am greeted by

navidrome> unpacking sources
navidrome> unpacking source archive /nix/store/f51j4vbggdg3a7bq8xr8ksf3a5xs0wvv-source
navidrome> source root is source
navidrome> patching sources
navidrome> Executing npmConfigHook
navidrome> Configuring npm
navidrome> Validating consistency between /build/source/ui/package-lock.json and /nix/store/y2splh2dkp37gjkn77hqkscbsd9x89cj-npm-deps/package-lock.json
navidrome> Fixing lockfile
navidrome> Installing dependencies
navidrome> npm ERR! code EUSAGE
navidrome> npm ERR! 
navidrome> npm ERR! The `npm ci` command can only install with an existing package-lock.json or
navidrome> npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
navidrome> npm ERR! later to generate a package-lock.json file, then try again.
navidrome> npm ERR! 
navidrome> npm ERR! Clean install a project
navidrome> npm ERR! 
navidrome> npm ERR! Usage:
navidrome> npm ERR! npm ci
navidrome> npm ERR! 
navidrome> npm ERR! Options:
navidrome> npm ERR! [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
navidrome> npm ERR! [-E|--save-exact] [-g|--global]
navidrome> npm ERR! [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
navidrome> npm ERR! [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
navidrome> npm ERR! [--strict-peer-deps] [--no-package-lock] [--foreground-scripts]
navidrome> npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
navidrome> npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
navidrome> npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
navidrome> npm ERR! 
navidrome> npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
navidrome> npm ERR! 
navidrome> npm ERR! Run "npm help ci" for more info
navidrome> 
navidrome> npm ERR! Log files were not written due to an error writing to the directory: /nix/store/y2splh2dkp37gjkn77hqkscbsd9x89cj-npm-deps/_logs
navidrome> npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
navidrome> 
navidrome> ERROR: npm failed to install dependencies
navidrome> 
navidrome> Here are a few things you can try, depending on the error:
navidrome> 1. Set `makeCacheWritable = true`
navidrome>   Note that this won't help if npm is complaining about not being able to write to the logs directory -- look above that for the actual error.
navidrome> 2. Set `npmFlags = [ "--legacy-peer-deps" ]`
navidrome> 

@winterqt winterqt marked this pull request as ready for review May 18, 2023 02:17
@winterqt
Copy link
Member Author

Just needs documentation, but implementation should be good.

Some notes:

  1. Do we want src = "${src}/foo" or sourceRoot to be the only way to integrate fetchNpmDeps into this (which either only supports directory sources, or has bad UX.), or should we add support for something else?
  2. @ajs124 Any clue why (presumably?) the same Webpack and Node version combination suddenly require the legacy OpenSSL flag for botamusique?

@ofborg ofborg bot requested a review from infinisil May 18, 2023 02:48
@ofborg ofborg bot added 10.rebuild-linux: 101-500 This PR causes between 101 and 500 packages to rebuild on Linux. and removed 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels May 18, 2023
Copy link
Member

@lilyinstarlight lilyinstarlight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the other hooks need pushd/popd too?

  1. Do we want src = "${src}/foo" or sourceRoot to be the only way to integrate fetchNpmDeps into this (which either only supports directory sources, or has bad UX.), or should we add support for something else?

I think we should allow fetchNpmDeps to accept an npmRoot as well so that people can just inherit npmRoot; in their fetcher. I suppose it doesn't need pushd/popd for that and can just specify an absolute path to the package-lock.json

@ajs124
Copy link
Member

ajs124 commented May 19, 2023

@ajs124 Any clue why (presumably?) the same Webpack and Node version combination suddenly require the legacy OpenSSL flag for botamusique?

It's not the same version. Pre #230092, there's a nodejs = pkgs.nodejs_14; in there. That was my motivation for #230092, moving from a soon to me marked EOL nodejs release to a supported one.

@winterqt
Copy link
Member Author

winterqt commented May 20, 2023

Do the other hooks need pushd/popd too?

I don't think so, all this is meant to do is allow the installation of dependencies (which is arguably the most annoying part without the hook), just like the Rust hooks.

It's not the same version. Pre #230092, there's a nodejs = pkgs.nodejs_14; in there. That was my motivation for #230092, moving from a soon to me marked EOL nodejs release to a supported one.

Got it, I was looking for something like that, but guess I missed it. Thanks.

@lilyinstarlight
Copy link
Member

I don't think so, all this is meant to do is allow the installation of dependencies (which is arguably the most annoying part without the hook), just like the Rust hooks.

Yeah, but some people may find benefit in using it with buildNpmPackage since sourceRoot has pretty poor UX

I'm not gonna let it block this PR, though, since this PR blocks other updates. We'll investigate adding npmRoot to the other hooks and fetchNpmDeps in a follow-up

Copy link
Member

@lilyinstarlight lilyinstarlight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That last push was to rebase to fix merge conflicts

Once ofborg is good, I'll merge since this looks good now and unblocks other work

@lilyinstarlight lilyinstarlight merged commit 273b32a into NixOS:master May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 101-500 This PR causes between 101 and 500 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants