# Nix-shell: How to run \`corepack enable\` to install modern Yarn?

**URL:** https://discourse.nixos.org/t/nix-shell-how-to-run-corepack-enable-to-install-modern-yarn/18791
**Category:** Help
**Created:** [April 23, 2022, 12:55am UTC](https://discourse.nixos.org/t/nix-shell-how-to-run-corepack-enable-to-install-modern-yarn/18791 "2022-04-23T00:55:45Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![grossbart](https://discourse.nixos.org/user_avatar/discourse.nixos.org/grossbart/32/454_2.png) [@grossbart](https://discourse.nixos.org/u/grossbart)
#### Post date: [January 6, 2023, 10:29am UTC](https://discourse.nixos.org/t/nix-shell-how-to-run-corepack-enable-to-install-modern-yarn/18791/6 "2023-01-06T10:29:55Z")

</div>

This confused me as well at first, but then I read in the [Yarn docs](https://yarnpkg.com/cli/set/version) that recent versions of Yarn 1.x can install newer versions itself. So that might be a reason why there is only the 1.x package in nixpkgs.

Anyway, here’s what works for me in `shell.nix`:

```auto
let
  pkgs = import (fetchTarball https://channels.nixos.org/nixpkgs-22.11-darwin/nixexprs.tar.xz) {};
  nodejs = pkgs.nodejs-16_x;
  yarn = pkgs.yarn.override { inherit nodejs; };

in pkgs.mkShell {
  buildInputs = [
    nodejs
    yarn
  ];

  shellHook = ''
    yarn set version 3.x
  '';
}

```

---

_[View the full topic](https://discourse.nixos.org/t/nix-shell-how-to-run-corepack-enable-to-install-modern-yarn/18791)._
