Skip to content

Comments

Yarn fetcher#138233

Closed
happysalada wants to merge 5 commits intoNixOS:masterfrom
happysalada:yarn_fetcher
Closed

Yarn fetcher#138233
happysalada wants to merge 5 commits intoNixOS:masterfrom
happysalada:yarn_fetcher

Conversation

@happysalada
Copy link
Contributor

Motivation for this change

This is work in progress for a proposal around a yarn fetcher.
This is an alternative to #128749 to generate discussions about the good and bad parts of each approach

Please note that the plausible modification is not a proposition to modify the plausible package, but just to illustrate planned usage.

This includes

  • handles package-lock.json and yarn.lock (using the import feature from yarn)

There are still some things I am not sure about

  • I didn't include the --ignore-scripts flag, as I'm still weighing pros and cons about it, happy to get more informations regarding it.
  • I haven't tested with other packages, I would be happy to get more feedback.
  • this only includes a yarn fetcher, no yarn builder. Meaning that it's a way to get node_modules, however usage is not as straightforward as the buildRustCrate or the buildGoModule. Ideally this can be merged and tested as is for a while, if it actually works, then a follow up PR can happen to make a yarnBuilder which would make usage easier.
  • This is just providing a tarball (potential smaller downloads). I find usage from a tarball a bit awkward so far. Also I'm having trouble figuring out when would a dependency tarball actually be downloaded. I'm considering at the moment going back to just files and directories in $out (I would like a single way to proceed, so potentially no way to make tarball at all).
  • I'm not sure yet how the dependency override would work, haven't given that any consideration.

This is mostly for a short term solution so that more JS things can be merged, I'm not too attached to this, so feel free to critize!
(the other alternatve for things with lockfiles, npmlock2nix currently doesn't have a precise date as to when it will be available).

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 via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.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
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) label Sep 17, 2021
@happysalada happysalada mentioned this pull request Sep 17, 2021
11 tasks
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/future-of-npm-packages-in-nixpkgs/14285/18

@ofborg ofborg bot requested a review from Ma27 September 17, 2021 06:10
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Sep 17, 2021
@Ma27
Copy link
Member

Ma27 commented Sep 17, 2021

I have to admit, I'm not really sure if we want yet another FOD-based fetcher (which is essentially a big blackbox IMHO) in nixpkgs. For reference, see NixOS/nix#2270

(Please note that there isn't a final decision, I generally support this - and try to only use FOD for dependency fetching if there's no way around it - but there are a lot of people against this).

I didn't include the --ignore-scripts flag, as I'm still weighing pros and cons about it, happy to get more informations regarding it.

The problem is that it has sometimes scripts that download random stuff from the internet (e.g. electron IIRC) which would make the fixed-output hash unstable.

@r-rmcgibbo
Copy link

r-rmcgibbo commented Sep 17, 2021

Result of nixpkgs-review pr 138233 at 85e36f3 run on x86_64-linux 1

1 package failed to build:
6 suggestions:
  • warning: unused-argument

    Unused argument: moreutils.
    Near pkgs/servers/web-apps/plausible/default.nix:13:3:

       |
    13 | , moreutils
       |   ^
    
  • warning: unused-argument

    Unused argument: glibcLocales.
    Near pkgs/servers/web-apps/plausible/default.nix:5:3:

      |
    5 | , glibcLocales
      |   ^
    
  • warning: unused-argument

    Unused argument: stdenv.
    Near pkgs/servers/web-apps/plausible/default.nix:2:3:

      |
    2 | , stdenv
      |   ^
    
  • warning: unused-argument

    Unused argument: jq.
    Near pkgs/servers/web-apps/plausible/default.nix:12:3:

       |
    12 | , jq
       |   ^
    
  • warning: unused-argument

    Unused argument: cacert.
    Near pkgs/servers/web-apps/plausible/default.nix:6:3:

      |
    6 | , cacert
      |   ^
    
  • warning: unused-argument

    Unused argument: mkYarnModules.
    Near pkgs/servers/web-apps/plausible/default.nix:7:3:

      |
    7 | , mkYarnModules
      |   ^
    

Note that build failures may predate this PR, and could be nondeterministic or hardware dependent.
Please exercise your independent judgement. Does something look off? Please file an issue or reach out on IRC.


Result of nixpkgs-review pr 138233 at 85e36f3 run on aarch64-linux 1

1 package failed to build:
6 suggestions:
  • warning: unused-argument

    Unused argument: stdenv.
    Near pkgs/servers/web-apps/plausible/default.nix:2:3:

      |
    2 | , stdenv
      |   ^
    
  • warning: unused-argument

    Unused argument: cacert.
    Near pkgs/servers/web-apps/plausible/default.nix:6:3:

      |
    6 | , cacert
      |   ^
    
  • warning: unused-argument

    Unused argument: mkYarnModules.
    Near pkgs/servers/web-apps/plausible/default.nix:7:3:

      |
    7 | , mkYarnModules
      |   ^
    
  • warning: unused-argument

    Unused argument: glibcLocales.
    Near pkgs/servers/web-apps/plausible/default.nix:5:3:

      |
    5 | , glibcLocales
      |   ^
    
  • warning: unused-argument

    Unused argument: jq.
    Near pkgs/servers/web-apps/plausible/default.nix:12:3:

       |
    12 | , jq
       |   ^
    
  • warning: unused-argument

    Unused argument: moreutils.
    Near pkgs/servers/web-apps/plausible/default.nix:13:3:

       |
    13 | , moreutils
       |   ^
    

Note that build failures may predate this PR, and could be nondeterministic or hardware dependent.
Please exercise your independent judgement. Does something look off? Please file an issue or reach out on IRC.

@Mic92 Mic92 marked this pull request as draft September 19, 2021 12:16
@Mic92 Mic92 changed the title [WIP]: Yarn fetcher Yarn fetcher Sep 19, 2021
@Mic92
Copy link
Member

Mic92 commented Sep 19, 2021

I have to admit, I'm not really sure if we want yet another FOD-based fetcher (which is essentially a big blackbox IMHO) in nixpkgs. For reference, see NixOS/nix#2270

(Please note that there isn't a final decision, I generally support this - and try to only use FOD for dependency fetching if there's no way around it - but there are a lot of people against this).

I didn't include the --ignore-scripts flag, as I'm still weighing pros and cons about it, happy to get more informations regarding it.

The problem is that it has sometimes scripts that download random stuff from the internet (e.g. electron IIRC) which would make the fixed-output hash unstable.

To be honest for me a reviewing a 100K lines of node-packages.nix is the bigger blackbox. With FOD I can be sure at least the pull request author did not temper with the source after running the update script.

@Ma27
Copy link
Member

Ma27 commented Sep 19, 2021

I didn't say that, my preferred solution is to read from an existing lockfile and re-use these results (such as at least import-cargo does it).

@happysalada
Copy link
Contributor Author

I think we all agree that npmlock2nix is a better solution with a lock file.

The idea here would be to use something like this until npmlock2nix gets merged into nixpkgs. It could be another 3 months or more until we have a better solution.

I still have to add the ignore-scripts flag on that PR and verify that the hash does not change accross platforms. (if it does it might make usage more problematic). At the moment the current ci failure is because of a hash mismatch on linux vs darwin.

I'm also thinking about opening an RFC to have a discussion more in the open and see what people would think. (the only reason I haven't done it yet, is that it seems to me that the discussion is only valid for 3 months, so the RFC might not be over before we have another solution merged. That said, npmlock2nix is only a solution for a package.lock (for now at least), so it might be good to open an RFC to discuss the alternatives for yarn. It might be good also to discuss an alternative if npm changes in such a way that npmlock2nix is not usable anymore. (which is what I think happened to the previous iteration called npm2nix))

@Ma27
Copy link
Member

Ma27 commented Sep 19, 2021

That said, npmlock2nix is only a solution for a package.lock (for now at least), so it might be good to open an RFC to discuss the alternatives for yarn

I think that this shouldn't be Yarn-specific, but a more general decision about how we want to package language-specific stuff. I'm btw sure that there a a few more discussions about this that you may want to read before opening such an RFC, but in general I think that this is a great idea 👍 .

The idea here would be to use something like this until npmlock2nix gets merged into nixpkgs. It could be another 3 months or more until we have a better solution.

Well, as I said, using the lock-data from language-specific package managers in general is IMHO the ideal solution for the problem we have, so I have to admit I don't really understand your concern here. I don't think we should rush now with yet another fetcher (we have 2 yarn2nix implementations, npmlock2nix, node2nix and pnpm2nix and a similar amount of fetchers for Rust), but focus on getting a somewhat standardized approach that's applicable to different language-ecosystems.

In case of Yarn, we'll also have the question how to deal with the lockfile, though (in contrast to cargo using TOML, NPM using JSON and Go using something that doesn't seem too hard to parse in contrast to a yarn.lock), perhaps that's what you had in mind while talking about Yarn fetchers above. IIRC Yarn doesn't intend to change the format, so we'll either need to parse it in Nix (though that'll be very painful, but people have written parsers already such as https://github.com/mozilla/nixpkgs-mozilla/blob/master/lib/parseTOML.nix), try to get it in Nix as a builtin (don't think that's fairly likely) or discuss how to deal with FOD in such an RFC (cross-ref NixOS/nix#5253).

Please note that especially what I mentioned in the paragraph above is just some brainstorming and not completely thought through, but I thought it's still worth to share this here :)

@happysalada
Copy link
Contributor Author

After my change to add the --ignore-scripts, it seems there is still a hash mismatch between the different platforms. The hash on the same platform this was built (darwin-x86_64) does not even match, it doesn't bode well for this approach.

@Ma27 my approach here was to try to get something quickly that could be potentially used in case approaches with parsing the lock files do not work. The potential problems with approach parsing the lock file is that the time this lands in nixpkgs is still incertain and there are still cases where this is known to be impossible. In some cases, for some reason yarn doesn't even respect it's own format and doesn't include the integrity hashes. One such examle is the peertube PR attracting so much attention recently. Originally it included a patch to yarn.lock to add the missing integrity hashes. I've tried to re-generate the lock-file locally and there where no ways to get those hashes to show up.

I'm a little afraid that the parsing the lock file approach might take longer than we think, and up until now there is only a solution for package-lock.json. (npmlock2nix, the stronger contender in the race doesn't do yarn.lock as of now).

There is an attempt at the moment to parse several lock file formats, I'm going to see what I can do to help there.

@happysalada
Copy link
Contributor Author

I forgot to say.
I'm closing this for now as I don't have ideas as to how to fix the hash mismatch on the same platform as it was built on.
I'm keeping the branch around however in case there are new ideas or for reference for others.

@happysalada happysalada deleted the yarn_fetcher branch April 28, 2023 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants