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
'';
}
For anyone else who ends up here via a search engine :)
(
enableis 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