3

For modern versions of Yarn, aka Yarn Berry, the preferred installation is through Corepack, and Corepack is included by default with Node.js installs (>=16.10). See https://yarnpkg.com/getting-started/install

This is what I've tried to do corepack enable in default.nix, but it doesn't work.

with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "dev";
  dontUnpack = true;
  buildInputs = [ nodejs-17_x ];
  postPhases = ''
    corepack enable
  '';
}
mitchelllc
  • 1,607
  • 4
  • 20
  • 24

1 Answers1

4

For anyone else who ends up here via a search engine :)

corepack enable

corepack prepare yarn@3.2.2 --activate

(enable is needed to install the symlinks, and prepare + activate sets the correct version.)

This should work on v16.9.0+ (and even v14.19.0+)

source: https://nodejs.org/api/corepack.html#upgrading-the-global-versions

PAStheLoD
  • 943
  • 12
  • 22