Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various buildNpmPackage fixes #200470

Merged
merged 14 commits into from
Nov 21, 2022
Merged

Conversation

winterqt
Copy link
Member

Description of changes
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/)
  • 22.11 Release Notes (or backporting 22.05 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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@winterqt
Copy link
Member Author

@delroth @mweinelt Please test this branch to see if it's fixed your respective issues. Thanks!

@delroth
Copy link
Contributor

delroth commented Nov 10, 2022

@delroth @mweinelt Please test this branch to see if it's fixed your respective issues. Thanks!

On my side everything now Just Works as it should for etherpad-lite. Thank you so much for the quick turnaround!

@mweinelt
Copy link
Member

mweinelt commented Nov 10, 2022

Running into that new check, even though npmDeps is set.

evcc-0.106.3-go-modules> unpacking sources
evcc-0.106.3-go-modules> unpacking source archive /nix/store/7kxszkq3jd6x1dwl1va6n8fvqppsack5-source
evcc-0.106.3-go-modules> source root is source
evcc-0.106.3-go-modules> patching sources
evcc-0.106.3-go-modules> Executing npmConfigHook
evcc-0.106.3-go-modules> Configuring npm
evcc-0.106.3-go-modules> 
evcc-0.106.3-go-modules> ERROR: no dependencies were specified
evcc-0.106.3-go-modules> Hint: set `npmDeps` if using these hooks individually. If this is happening with `buildNpmPackage`, please open an issue.
  npmDeps = fetchNpmDeps {
    inherit src;
    hash = "";
  };

  nativeBuildInputs = [
    nodejs
    npmHooks.npmConfigHook
  ];

I think the config hook runs before the fetcher.

@winterqt
Copy link
Member Author

winterqt commented Nov 10, 2022

@delroth Thanks for confirming!

@mweinelt Notice what derivation it's in -- it's the Go modules one, where it wouldn't be set. 😕

I'll get back to you with a solution on how to cleanly do that for now.

@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Nov 10, 2022
@winterqt
Copy link
Member Author

@lilyinstarlight What do you think of 4e730bbe4d567bbb65cc946fdbbadab0f4d99546, as opposed to having a separate npmPruneFlags? Or do you think I should adjust the diagnostic to suggest npmFlags = [ "--legacy-peer-deps" ]?

@lilyinstarlight
Copy link
Member

What do you think of 4e730bb, as opposed to having a separate npmPruneFlags? Or do you think I should adjust the diagnostic to suggest npmFlags = [ "--legacy-peer-deps" ]?

I assume --legacy-peer-deps would affect any subcommand that regenerates the package tree, so it might make sense as a general npmFlags option rather than only for ci and prune

But I also still think it would probably be good to otherwise keep both npmFlags and npmInstallFlags on the npm prune command (like you have in 4e730bb) to avoid unexpected differences in behavior when using a flag that should only matter for install-related stuff but still affects prune (e.g. adding another --omit to npmInstallFlags)

How do you feel about that? Keeping the change in 4e730bb but also adjusting the diagnostic to suggest npmFlags = [ "--legacy-peer-deps" ]

Copy link
Contributor

@tjni tjni left a comment

Choose a reason for hiding this comment

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

Transcribing comments over from #200475.

integrity: Option<String>,
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
enum UrlOrString {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I personally like naming this UrlLike to emphasize that it's still a URL, just maybe not a valid one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure on this one. I'm talking about URLs like github:NixOS/nixpkgs here, which technically are valid URLs, but... not.

Maybe yours is best, hm.

pkgs/build-support/node/fetch-npm-deps/src/main.rs Outdated Show resolved Hide resolved
pkgs/build-support/node/fetch-npm-deps/src/main.rs Outdated Show resolved Hide resolved
pkgs/build-support/node/fetch-npm-deps/src/main.rs Outdated Show resolved Hide resolved
@winterqt winterqt force-pushed the build-npm-package-fixes branch from 4e730bb to 1612525 Compare November 11, 2022 02:51
@winterqt winterqt requested a review from tjni November 11, 2022 02:51
@winterqt
Copy link
Member Author

@lilyinstarlight Done in 1612525f97d2101963833ba5f1aa1ef7b01df64c.

@tjni How do you feel about the commit progression here, with your changes applied throughout? It took... a fair bit amount of time to do the rebasing required for this, so let me know if anything seems weird.

@tjni
Copy link
Contributor

tjni commented Nov 11, 2022

Looks great! Thank you for addressing my comments.

@winterqt
Copy link
Member Author

My main concern is doing too much in 83d240907a69684436ca82df80675a3b0c81e260, specifically referring to the if to filter change here, where it really doesn't relate to the other changes, but it kind of does since the change of Package::resolved to UrlOrString allows this to happen, mostly. I don't know.

Am I overthinking this? 😅

@tjni
Copy link
Contributor

tjni commented Nov 11, 2022

I think you should do whatever makes you feel best about the change. If it feels unrelated, feel free to pull it out or leave it out. None of my comments ever need to be addressed, I like and can iterate on code all day, but I almost always prefer to commit something instead of nothing.

@reckenrode
Copy link
Contributor

Saw this mentioned on Discourse and thought I would try converting the FoundryVTT flake I maintain over to buildNpmPackage from node2nix. It went mostly smoothly, but I ran into a few issues. One is minor. I think the other was also reported in #189539.

  • I ran into trouble with the src. FoundryVTT is distributed as a zip file, so it took some time to figure out what I needed to override to let it unpack properly in fetchNpmDeps.
  • FoundryVTT uses a private fork of pdfjs. The source of their fork is available on GitHub, but the package itself is not. I work around this by changing the package.json to reference the GitHub fork, but that doesn’t work with buildNpmPackage. I get the following error and have to use that URL instead of the repo on GitHub.
Error: request to https://codeload.github.com/foundryvtt/pdfjs/tar.gz/2196ae9bcbd8d6a9b0b9c493d0e9f3aca13f2fd9 failed: cache mode is 'only-if-cached' but no cached response is available.

The revised flake is available at the buildNpmPackage-PoC branch of my repo for reference.

@winterqt
Copy link
Member Author

@reckenrode I can't look further into this right now, but as for the second point, can you please test if changing the lockfile is required when using this branch?

@reckenrode
Copy link
Contributor

@reckenrode I can't look further into this right now, but as for the second point, can you please test if changing the lockfile is required when using this branch?

I was was referencing the PR in my flake (github:nixos/nixpkgs/pull/200470/head). That should be the same thing as the branch, shouldn’t it?

@winterqt
Copy link
Member Author

winterqt commented Nov 12, 2022

Yup, you're right. (I think.)

I'll take a look when I can and see what's up, on both fronts. Thanks for reporting!

@winterqt winterqt marked this pull request as draft November 14, 2022 03:15
@winterqt
Copy link
Member Author

winterqt commented Nov 14, 2022

@reckenrode Please test the latest commits, which fix the issue by working around what might be an npm bug.

I've marked this PR as a draft until I can file an issue with npm about this and note it in the code.

@delroth
Copy link
Contributor

delroth commented Nov 15, 2022

I rebased my etherpad WIP on top of the latest changes here and --fixup-lockfile is failing to parse the package-lock.json:

Validating consistency between /build/source/src/package-lock.json and /nix/store/377pfxym8iy6dgv83a8bmmr9r668m39b-etherpad-lite-1.8.18-npm-deps/package-lock.json
Error: expected value at line 1 column 1

Haven't debugged this yet since I'm fighting with other stuff.

@winterqt
Copy link
Member Author

That's strange -- will look into it when I can.

@winterqt winterqt force-pushed the build-npm-package-fixes branch from 718616f to 0c84200 Compare November 20, 2022 18:04
@winterqt winterqt marked this pull request as ready for review November 20, 2022 18:24
@winterqt winterqt force-pushed the build-npm-package-fixes branch from 6b32f82 to 155bc54 Compare November 20, 2022 18:25
@ofborg ofborg bot requested a review from lilyinstarlight November 20, 2022 18:35
Previously, we stored the tarballs from the hosted Git providers directly in the cache. However, as we've seen with `fetchFromGitHub` etc, these files may change subtly.

Given this, this commit repacks the dependencies before storing them in the cache.
@winterqt winterqt force-pushed the build-npm-package-fixes branch from 155bc54 to 7e81e81 Compare November 20, 2022 22:12
@winterqt
Copy link
Member Author

Switched to packing with gzip -9 like npm does.

@@ -96,6 +107,8 @@ npmConfigHook() {
rm node_modules/.meow
fi

patchShebangs node_modules
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
patchShebangs node_modules
patchShebangs node_modules/.bin

Would that already be enough? Searching through everyfile in the blackhole could take a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

It could be enough, but who knows what files packages add in their install scripts that have hardcoded shebangs...

Copy link
Member

Choose a reason for hiding this comment

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

If patchShebangs would be free, we would just run it on every source file and patch everything we can. node_modules is notorious for being very big and with lots of files.

How about we just search for executable files and patch those?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe?

find node_modules -executable -exec patchShebangs {} \;

Copy link
Member

Choose a reason for hiding this comment

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

We'll get this in without addressing this for now.

@winterqt
Copy link
Member Author

One last sanity check.

@ofborg eval

@winterqt
Copy link
Member Author

Time is something we don't have right now, so let's just land this.

@winterqt winterqt merged commit 814a0bc into NixOS:master Nov 21, 2022
@winterqt winterqt deleted the build-npm-package-fixes branch November 21, 2022 20:00
@winterqt winterqt mentioned this pull request Dec 2, 2022
13 tasks
winterqt added a commit to winterqt/nixpkgs that referenced this pull request Dec 9, 2022
This was created before NixOS#200470, but wasn't tested after it was merged, leading to the hash being incorrect.
winterqt added a commit to winterqt/nixpkgs that referenced this pull request Dec 9, 2022
This was written before NixOS#200470, but wasn't tested after it was merged, leading to the hash being incorrect.
@winterqt winterqt mentioned this pull request Dec 9, 2022
13 tasks
winterqt added a commit that referenced this pull request Dec 9, 2022
This was written before #200470, but wasn't tested after it was merged, leading to the hash being incorrect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 1-10 10.rebuild-darwin: 1 10.rebuild-linux: 1-10 11.by: package-maintainer This PR was created by the maintainer of the package it changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants