diff --git a/pkgs/build-support/node/fetch-yarn-deps/default.nix b/pkgs/build-support/node/fetch-yarn-deps/default.nix index 433dc17a75e3..0b6ecd9ea4f4 100644 --- a/pkgs/build-support/node/fetch-yarn-deps/default.nix +++ b/pkgs/build-support/node/fetch-yarn-deps/default.nix @@ -7,6 +7,9 @@ fetchurl, nodejs-slim, prefetch-yarn-deps, + fixup-yarn-lock, + yarn, + makeSetupHook, cacert, callPackage, nix, @@ -154,4 +157,15 @@ in ); in lib.setFunctionArgs f (lib.functionArgs f) // { inherit tests; }; + + yarnConfigHook = makeSetupHook { + name = "yarn-config-hook"; + propagatedBuildInputs = [ + yarn + fixup-yarn-lock + ]; + meta = { + description = "Install nodejs dependencies from an offline yarn cache produced by fetchYarnDeps"; + }; + } ./yarn-config-hook.sh; } diff --git a/pkgs/build-support/node/fetch-yarn-deps/yarn-config-hook.sh b/pkgs/build-support/node/fetch-yarn-deps/yarn-config-hook.sh new file mode 100644 index 000000000000..d11229aafc71 --- /dev/null +++ b/pkgs/build-support/node/fetch-yarn-deps/yarn-config-hook.sh @@ -0,0 +1,37 @@ +yarnConfigHook(){ + runHook preConfigure + echo "Executing yarnConfigHook" + + # Use a constant HOME directory + mkdir -p /tmp/home + export HOME=/tmp/home + if [[ -n "$yarnOfflineCache" ]]; then + offlineCache="$yarnOfflineCache" + fi + if [[ -z "$offlineCache" ]]; then + echo yarnConfigHook: No yarnOfflineCache or offlineCache were defined\! >&2 + exit 2 + fi + yarn config --offline set yarn-offline-mirror "$offlineCache" + fixup-yarn-lock yarn.lock + yarn install \ + --frozen-lockfile \ + --force \ + --production=false \ + --ignore-engines \ + --ignore-platform \ + --ignore-scripts \ + --no-progress \ + --non-interactive \ + --offline + + # TODO: Check if this is really needed + patchShebangs node_modules + + echo "finished yarnConfigHook" + runHook postConfigure +} + +if [[ -z "${dontYarnInstallDeps-}" && -z "${configurePhase-}" ]]; then + configurePhase=yarnConfigHook +fi diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4417e93bbcbe..c96a9b843688 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -986,6 +986,7 @@ with pkgs; inherit (callPackages ../build-support/node/fetch-yarn-deps { }) fixup-yarn-lock prefetch-yarn-deps + yarnConfigHook fetchYarnDeps; find-cursor = callPackage ../tools/X11/find-cursor { };