diff options
Diffstat (limited to 'pkgs/build-support/node/fetch-yarn-deps/default.nix')
-rw-r--r-- | pkgs/build-support/node/fetch-yarn-deps/default.nix | 161 |
1 files changed, 116 insertions, 45 deletions
diff --git a/pkgs/build-support/node/fetch-yarn-deps/default.nix b/pkgs/build-support/node/fetch-yarn-deps/default.nix index 4ef74c0cab884..d0caa42dade16 100644 --- a/pkgs/build-support/node/fetch-yarn-deps/default.nix +++ b/pkgs/build-support/node/fetch-yarn-deps/default.nix @@ -1,4 +1,19 @@ -{ stdenv, lib, makeWrapper, coreutils, nix-prefetch-git, fetchurl, nodejs-slim, prefetch-yarn-deps, cacert, callPackage, nix }: +{ + stdenv, + lib, + makeWrapper, + coreutils, + nix-prefetch-git, + fetchurl, + nodejs-slim, + prefetch-yarn-deps, + fixup-yarn-lock, + yarn, + makeSetupHook, + cacert, + callPackage, + nix, +}: let yarnpkg-lockfile-tar = fetchurl { @@ -6,9 +21,9 @@ let hash = "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ=="; }; - tests = callPackage ./tests {}; - -in { + tests = callPackage ./tests { }; +in +{ prefetch-yarn-deps = stdenv.mkDerivation { name = "prefetch-yarn-deps"; @@ -30,12 +45,20 @@ in { patchShebangs $out/libexec makeWrapper $out/libexec/index.js $out/bin/prefetch-yarn-deps \ - --prefix PATH : ${lib.makeBinPath [ coreutils nix-prefetch-git nix ]} + --prefix PATH : ${ + lib.makeBinPath [ + coreutils + nix-prefetch-git + nix + ] + } runHook postInstall ''; - passthru = { inherit tests; }; + passthru = { + inherit tests; + }; }; fixup-yarn-lock = stdenv.mkDerivation { @@ -63,45 +86,93 @@ in { runHook postInstall ''; - passthru = { inherit tests; }; + passthru = { + inherit tests; + }; }; - fetchYarnDeps = let - f = { - name ? "offline", - src ? null, - hash ? "", - sha256 ? "", - ... - }@args: let - hash_ = - if hash != "" then { outputHashAlgo = null; outputHash = hash; } - else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; } - else { outputHashAlgo = "sha256"; outputHash = lib.fakeSha256; }; - in stdenv.mkDerivation ({ - inherit name; - - dontUnpack = src == null; - dontInstall = true; - - nativeBuildInputs = [ prefetch-yarn-deps cacert ]; - GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; - NODE_EXTRA_CA_CERTS = "${cacert}/etc/ssl/certs/ca-bundle.crt"; - - buildPhase = '' - runHook preBuild - - yarnLock=''${yarnLock:=$PWD/yarn.lock} - mkdir -p $out - (cd $out; prefetch-yarn-deps --verbose --builder $yarnLock) - - runHook postBuild - ''; - - outputHashMode = "recursive"; - } // hash_ // (removeAttrs args (["name" "hash" "sha256"] ++ (lib.optional (src == null) "src")))); - - in lib.setFunctionArgs f (lib.functionArgs f) // { - inherit tests; - }; + fetchYarnDeps = + let + f = + { + name ? "offline", + src ? null, + hash ? "", + sha256 ? "", + ... + }@args: + let + hash_ = + if hash != "" then + { + outputHashAlgo = null; + outputHash = hash; + } + else if sha256 != "" then + { + outputHashAlgo = "sha256"; + outputHash = sha256; + } + else + { + outputHashAlgo = "sha256"; + outputHash = lib.fakeSha256; + }; + in + stdenv.mkDerivation ( + { + inherit name; + + dontUnpack = src == null; + dontInstall = true; + + nativeBuildInputs = [ + prefetch-yarn-deps + cacert + ]; + GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + NODE_EXTRA_CA_CERTS = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + + buildPhase = '' + runHook preBuild + + yarnLock=''${yarnLock:=$PWD/yarn.lock} + mkdir -p $out + (cd $out; prefetch-yarn-deps --verbose --builder $yarnLock) + + runHook postBuild + ''; + + outputHashMode = "recursive"; + } + // hash_ + // (removeAttrs args ( + [ + "name" + "hash" + "sha256" + ] + ++ (lib.optional (src == null) "src") + )) + ); + 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; + + yarnBuildHook = makeSetupHook { + name = "yarn-build-hook"; + meta = { + description = "Run yarn build in buildPhase"; + }; + } ./yarn-build-hook.sh; } |