Nixify yarn (v3) with flake

I’m trying to use yarn-plugin-nixify to write a flake.nix for a project at work. (An elm project that uses yarn to deal with JS dependencies.)

I’ve gotten everything to work fine on my machine, but building fails on my colleague’s machine and in CI with a message of

$ yarn pack [--install-if-needed] [-n,--dry-run] [--json] [-o,--out #0]
Packing @JohanWinther/svg2png@ from sources
No package manager configuration detected; defaulting to Yarn

Usage Error: Unrecognized or legacy configuration settings found: enableNixify - run "yarn config -v" to see the list of settings supported in Yarn (in <environment>)

$ yarn pack [--install-if-needed] [-n,--dry-run] [--json] [-o,--out #0]

according to this issue it happens when the plugin isn’t found. What it doesn’t mention is how to make it be found :disappointed:

Has anyone else seen this, and have a solution?

Alternatively, are there other ways to package a project using yarn+elm?

Cool project I never used before. Can’t help much, but two remarks:

  1. stupid question, but have you run:
yarn plugin import

to install the plugin at your collegues’s computer?
2. Do you/they run NixOs or another distribution?
3. Is yarn recent enough? Yarn >= 3.1.0 or >= 4.0.0.

Have you tried dream2nix? I’m not sure to understand the yarn’s state right now: this issue Trouble Using Yarn Lockfile (nodejs-package-lock-v3) · Issue #837 · nix-community/dream2nix · GitHub suggests that is is not supported yet, but this comment says something else:

Second on dream2nix. I’ve used it extensively to package extremely complex yarn-based monorepos with workspaces and a variety of other off use cases, with close to 100% success rate with nodejs-based packages. The nodejs ecosystem is pretty much solved for dream2nix. It has support for both pure (package-lock.json, yarn.lock) and impure translations and provides many paths to solve various problems, such as package overrides, dependency injections, building without devDependencies (so build from the outside with nix instead), etc.

Also, do you have strong reasons to use yarn? This posts suggests that yarn has some fundamental issues compared to npm Yarn Plug'n'Play and direnv/packaging - #2 by Growpotkin

1 Like

No, I thought that since yarn records what plugins are installed and where they come from that would be handled automatically. Especially since I’ve checked in the change to .yarnrc.yml as well as the plugin file itself, .yarn/plugins/yarn-plugin-nixify.cjs. Maybe that’s not the case, but then I’m not really sure how to handle the Catch 22 that arises

  1. To install the plugin one needs a dev environment, i.e. to run nix develop, but
  2. in order to get a dev environment one has to have the plugin installed.

Neither of us use NixOS.

Yes, it’s version 3.2 of Yarn.

No, I’ve never tried dream2nix, never even heard of it before, to be honest. Unfortunately I can’t make out how to use it at all though. It mentions nothing about Yarn and I don’t know enough about the JS ecosystem to understand if any of the existing modules would be useful to me

I don’t think we have strong reasons for it. It’s just what is there now, and as I don’t know the first thing about JS packaging/building I thought I’d stick to it. I mean, “how bad can it be”? Apparently plenty bad :laughing:

If possible, could you run your project in a “non-nix environment”? So you’ll know if it comes from yarn / project or nix.

As @tobiasBora mentioned, the plugin itself may be missing.
Have you tried to temporarily push all .yarn to your remote?

I would usually commit .yarn/releases and .yarn/plugins or create a npm post-install script to install these on yarn install.
Declaring in yarnrc.yml alone doesn’t install theses on e.g yarn install.
That also locks yarn and plugins versions (and avoid un-wanted upgrades).

Any chances that your colleague and you are using a different IDE / editor?
Some may require additional configurations to work well with yarn.
e.g VS code will throw some errors, extensions as well unless nodeLinker: node-modules is set

I’m pretty sure this is an issue with the setup of Yarn and the flake-ification of that. We’re not involving any IDEs or anything, only running nix build . and nix develop so far.

Anyway, I think I’ll do what @tobiasBora suggests and ditch Yarn completely. I started down the route of removing it and using npm instead and I have almost all things working already, just a few scripts that still mention yarn left to convert. Then I’ll see if flake-ifying becomes easier.

If you happen to still wanna check a solution for .yarn, feel free to share your configs

For possible solutions / things to check:

  • run yarn install --frozen-lockfile to ensure all dependencies are not updated
    yarn install | Yarn
  • commit .yarn/releases and .yarn/plugins directories to remote repository
  • delete yarn.lock and re-create with yarn install