Yarn fails to do a local install

I use a default.nix shell to work on a monorepo at work. I need to use node 12 and yarn.

with import <nixpkgs> { };

stdenv.mkDerivation {
  name = "stuart-frontend-dev-shell";

  buildInputs = [
    zlib
    (yarn.override { nodejs = nodejs-12_x; })
  ];

  shellHook = ''
    yarn
  '';
}

and it returns this error:

WARN  Moving @babel/cli that was installed by a different package manager to "node_modules/.ignored
 WARN  Moving @babel/core that was installed by a different package manager to "node_modules/.ignored
 WARN  Moving @rollup/plugin-alias that was installed by a different package manager to "node_modules/.ignored
 WARN  Moving @rollup/plugin-babel that was installed by a different package manager to "node_modules/.ignored
 WARN  Moving @rollup/plugin-commonjs that was installed by a different package manager to "node_modules/.ignored
 WARN  68 other warnings
 WARN  deprecated rollup-plugin-babel@4.4.0: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-babel.
 WARN  deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
 WARN  deprecated intl-messageformat-parser@5.5.1: We've written a new parser that's 6x faster and is backwards compatible. Please use @formatjs/icu-messageformat-parser
 WARN  deprecated @formatjs/intl-utils@3.8.4: the package is rather renamed to @formatjs/ecma-abstract with some changes in functionality (primarily selectUnit is removed and we don't plan to make anyfurther changes to this package
 WARN  deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
 WARN  deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
 WARN  deprecated intl-messageformat-parser@5.5.1: We've written a new parser that's 6x faster and is backwards compatible. Please use @formatjs/icu-messageformat-parser
 WARN  deprecated @formatjs/intl-utils@3.8.4: the package is rather renamed to @formatjs/ecma-abstract with some changes in functionality (primarily selectUnit is removed and we don't plan to make anyfurther changes to this package
 WARN  deprecated @formatjs/intl-utils@3.8.4: the package is rather renamed to @formatjs/ecma-abstract with some changes in functionality (primarily selectUnit is removed and we don't plan to make anyfurther changes to this package
 WARN  deprecated @formatjs/intl-utils@3.8.4: the package is rather renamed to @formatjs/ecma-abstract with some changes in functionality (primarily selectUnit is removed and we don't plan to make anyfurther changes to this package
 WARN  deprecated @formatjs/intl-utils@3.8.4: the package is rather renamed to @formatjs/ecma-abstract with some changes in functionality (primarily selectUnit is removed and we don't plan to make anyfurther changes to this package
 WARN  deprecated @formatjs/intl-utils@3.8.4: the package is rather renamed to @formatjs/ecma-abstract with some changes in functionality (primarily selectUnit is removed and we don't plan to make anyfurther changes to this package
 WARN  deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
 WARN  deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
 WARN  deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
 WARN  deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
 WARN  deprecated har-validator@5.1.5: this library is no longer supported
 WARN  deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
 WARN  deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
 WARN  deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
 WARN  deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
 WARN  deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
 WARN  deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
 WARN  deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
 WARN  deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
 WARN  deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
 WARN  deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
 WARN  deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
Packages: +2055
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 2057, reused 2055, downloaded 0, added 0, done
node_modules/.pnpm/core-js@3.22.0/node_modules/core-js: Running postinstall script, done in 74ms
node_modules/.pnpm/core-js-pure@3.22.0/node_modules/core-js-pure: Running postinstall script, done in 75ms
node_modules/.pnpm/cwebp-bin@5.1.0/node_modules/cwebp-bin: Running postinstall script...
node_modules/.pnpm/gifsicle@4.0.1/node_modules/gifsicle: Running postinstall script...
node_modules/.pnpm/husky@4.3.8/node_modules/husky: Running install script, done in 122ms
node_modules/.pnpm/mozjpeg@6.0.1/node_modules/mozjpeg: Running postinstall script...
node_modules/.pnpm/node-sass@4.14.1/node_modules/node-sass: Running install script, done in 240ms
node_modules/.pnpm/husky@4.3.8/node_modules/husky: Running postinstall script, done in 75ms
node_modules/.pnpm/optipng-bin@6.0.0/node_modules/optipng-bin: Running postinstall script, failed in 2.2s
.../node_modules/optipng-bin postinstall$ node lib/install.js
│   ⚠ spawn /home/marcel/clones/work/ui/node_modules/.pnpm/optipng-bin@6.0.0/node_modules/optipng-bin/vendor/optipng ENOENT
│   ⚠ optipng pre-build test failed
│   ℹ compiling from source
│   ✖ Error: Command failed: /bin/sh -c make install
│ pngrtran.c:99:1: warning: ‘png_rtran_ok’ defined but not used [-Wunused-function]
│    99 | png_rtran_ok(png_structrp png_ptr, int need_IHDR)
│       | ^~~~~~~~~~~~
│ ar: `u' modifier ignored since `D' is the default (see `U')
│ /nix/store/cimp3vp40msz4afq1c3602p2rn9bff0d-binutils-2.35.2/bin/ld: pngtest.o: undefined reference to symbol 'stdout@@GLIBC_2.2.5'
│ /nix/store/cimp3vp40msz4afq1c3602p2rn9bff0d-binutils-2.35.2/bin/ld: /nix/store/6w8g7njm4mck5dmjxws0z1xnrxvl81xa-glibc-2.34-115/lib/libc.so.6: error adding symbols: DSO missing from command line
│ make[2]: *** [Makefile:66: pngtest] Error 1
│ make[1]: *** [Makefile:129: ../libpng/libpng.a] Error 2
│ make: *** [Makefile:14: install] Error 2
│ cd src/optipng && \
│ make install && \
│ cd ../..
│ make[1]: Entering directory '/run/user/1000/b7494102-1171-4338-9d39-9cb813b83231/src/optipng'
│ cd ../libpng && \
│ make -f Makefile PNGLIBCONF_H_PREBUILT=pnglibconf.h.optipng && \
│ cd ../optipng
│ make[2]: Entering directory '/run/user/1000/b7494102-1171-4338-9d39-9cb813b83231/src/libpng'
│ cp pnglibconf.h.optipng pnglibconf.h
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o png.o png.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngerror.o pngerror.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngget.o pngget.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngmem.o pngmem.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngpread.o pngpread.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngread.o pngread.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngrio.o pngrio.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngrtran.o pngrtran.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngrutil.o pngrutil.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngset.o pngset.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngtrans.o pngtrans.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngwio.o pngwio.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngwrite.o pngwrite.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngwtran.o pngwtran.c
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngwutil.o pngwutil.c
│ ar cru libpng.a png.o pngerror.o pngget.o pngmem.o pngpread.o pngread.o pngrio.o pngrtran.o pngrutil.o pngset.o pngtrans.o pngwio.o pngwrite.o pngwtran.o pngwutil.o
│ ranlib libpng.a
│ gcc -c -I../zlib  -O2 -Wall -Wextra -o pngtest.o pngtest.c
│ ld  -L../zlib -o pngtest pngtest.o libpng.a -lz -lm
│ make[2]: Leaving directory '/run/user/1000/b7494102-1171-4338-9d39-9cb813b83231/src/libpng'
│ make[1]: Leaving directory '/run/user/1000/b7494102-1171-4338-9d39-9cb813b83231/src/optipng'
│     at /home/marcel/clones/work/ui/node_modules/.pnpm/execa@0.7.0/node_modules/execa/index.js:231:11
│     at runMicrotasks (<anonymous>)
│     at processTicksAndRejections (internal/process/task_queues.js:95:5)
│     at async /home/marcel/clones/work/ui/node_modules/.pnpm/optipng-bin@6.0.0/node_modules/optipng-bin/lib/install.js:18:4
└─ Failed in 2.2s
node_modules/.pnpm/node-sass@4.14.1/node_modules/node-sass: Running postinstall script, done in 270ms
node_modules/.pnpm/pngquant-bin@5.0.2/node_modules/pngquant-bin: Running postinstall script, done in 487ms
 ELIFECYCLE  Command failed with exit code 1.

If I use LC=$CC, on the shellHook before the yarn command, it passes the yarn install but fails in the webpack build, this is the error that returns in that case:

ℹ 「wdm」: Failed to compile.
bundler Something went wrong while creating hot development instance. Hash: 1d8bf68faeef8455aaf0
Version: webpack 4.46.0
Time: 35779ms
Built at: 04/16/2022 4:18:52 PM
                               Asset      Size  Chunks               Chunk Names
02789ca1ae21880aea3a661063bbbe2b.svg  8.24 KiB          [immutable]
037f49f22fc17c034ef2300d9c17151a.svg  10.8 KiB          [immutable]
2343bc699b4c266e0b3e31297920907c.svg  8.92 KiB          [immutable]
2344b01e76d1dc856b2f022722d5f49f.svg  18.8 KiB          [immutable]
2d54dad4072d86c801bc556d43a416a9.svg  6.26 KiB          [immutable]
3dd66b03a6653c0247d3ec40331870ef.svg  14.1 KiB          [immutable]
4c300c65cee63eab4672cfe2a409dcc0.svg  8.74 KiB          [immutable]
54bcc5baa2692228127058a22e708c19.svg  7.84 KiB          [immutable]
64f25341fb370ec3ab6c1f5af4f5a21b.svg  8.96 KiB          [immutable]
68bbcf3b4984706d1b4f3095d1d4a813.svg  8.74 KiB          [immutable]
6bd95d3cbaca6c8d46ab6a915cdfb61d.svg   6.8 KiB          [immutable]
7151c00db6740df4cac4aca2f3376187.svg   6.1 KiB          [immutable]
822eda0177798d2c72bc42005f725845.svg  15.6 KiB          [immutable]
85b4af173cefaddff69187169c3bbfdb.svg  10.9 KiB          [immutable]
8cd92410a40717a46e7fd5936cee435f.svg  12.5 KiB          [immutable]
93ab0bc3416966553ef7b6f05fd0aedb.svg  9.45 KiB          [immutable]
961887b503af0c516e50c1c83e60c873.svg  11.9 KiB          [immutable]
9b9e82e977a03fbe4c7c2d01ed637375.svg  13.5 KiB          [immutable]
9ef0f189f1c6dfe013f7f51e15e905a4.svg  34.9 KiB          [immutable]
a21adb0bd067abfb49946d70a61a4c32.svg  32.9 KiB          [immutable]
a25be01d8bc0d9cb10a730de8d595b7e.svg  11.4 KiB          [immutable]
b869118b57c580fdc6e4791de148a68f.svg  18.4 KiB          [immutable]
bd8ce5578a9533b6a11eeceb7782ffb9.svg  26.1 KiB          [immutable]
cb7c942d80e1ed0541997380f97ed5a4.svg  9.67 KiB          [immutable]
f3b1fa548b6e4100b6b72bb6b4ba3d91.svg  18.5 KiB          [immutable]
fc2656ab3fb8702c5ff072d0f4acb690.svg  15.1 KiB          [immutable]
      index-1d8bf68faeef8455aaf0.css   950 KiB   index  [immutable]  index
  index-1d8bf68faeef8455aaf0.css.map  1.07 MiB   index  [dev]        index
                            index.js  11.1 MiB   index               index
                        index.js.map  9.84 MiB   index  [dev]        index
Entrypoint index = index-1d8bf68faeef8455aaf0.css index.js index-1d8bf68faeef8455aaf0.css.map index.js.map
[0] multi webpack-hot-middleware/client?reload=false&path=http://localhost:7331/__webpack_hmr @babel/polyfill ./apps/dashboard-v2/client 52 bytes {index} [built]
[./apps/dashboard-v2/client/index.js] 7.96 KiB {index} [built]
[./apps/dashboard-v2/shared/containers/LocationAnalytics/index.js] 2.56 KiB {index} [built]
[./apps/dashboard-v2/shared/links/ToasterLink.js] 5.21 KiB {index} [built]
[./apps/dashboard-v2/shared/routes.js] 6.12 KiB {index} [built]
[./apps/dashboard-v2/shared/schema/index.js] 960 bytes {index} [built]
[./apps/dashboard-v2/shared/schema/typePolicies.js] 5.72 KiB {index} [built]
[./node_modules/@apollo/client/index.js] 100 bytes {index} [built]
[./node_modules/@babel/polyfill/lib/index.js] 686 bytes {index} [built]
[./node_modules/@babel/polyfill/lib/noConflict.js] 567 bytes {index} [built]
[./node_modules/@babel/runtime/helpers/defineProperty.js] 367 bytes {index} [built]
[./node_modules/@babel/runtime/helpers/taggedTemplateLiteral.js] 330 bytes {index} [built]
[./node_modules/@hot-loader/react-dom/index.js] 1.33 KiB {index} [built]
[./node_modules/@sentry/browser/esm/index.js] 740 bytes {index} [built]
[./node_modules/webpack-hot-middleware/client.js?reload=false&path=http://localhost:7331/__webpack_hmr] (webpack)-hot-middleware/client.js?reload=false&path=http://localhost:7331/__webpack_hmr 7.69 KiB {index} [built]
    + 2314 hidden modules

ERROR in ./assets/images/marketing/stuartSignupProfessionalPlaceholder.jpg
Module build failed (from ./node_modules/image-webpack-loader/index.js):
Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:156:25)
    at writeGeneric (internal/stream_base_commons.js:147:3)
    at Socket._writeGeneric (net.js:787:11)
    at Socket._write (net.js:799:8)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Socket.Writable.write (_stream_writable.js:318:11)
    at Socket.Writable.end (_stream_writable.js:585:10)
    at Socket.end (net.js:591:31)
    at handleInput (/home/marcel/clones/work/stuart-frontend/node_modules/execa/index.js:87:17)
 @ ./apps/dashboard-v2/shared/components/AuthPageAside/index.js 26:0-134 88:17-57
 @ ./apps/dashboard-v2/shared/containers/LogInPage/index.js
 @ ./apps/dashboard-v2/shared/routes.js
 @ ./apps/dashboard-v2/client/index.js
 @ multi webpack-hot-middleware/client?reload=false&path=http://localhost:7331/__webpack_hmr @babel/polyfill ./apps/dashboard-v2/client