Skip to content

Commit

Permalink
fixup-yarn-lock: split out from prefetch-yarn-deps, cleanup installing
Browse files Browse the repository at this point in the history
To reduce dependencies (mainly nix-prefetch-git and through that git,
git-lfs) when we just need to fixup a lock file, eg when building electron.
This also tries to avoid needless rebuilds when eg. golang is updated.

Also this cleans up and combined the build/installPhase of both tools to
be a lot simpler.
  • Loading branch information
SuperSandro2000 authored and lilyinstarlight committed Apr 17, 2024
1 parent b6f3d24 commit 6181939
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
44 changes: 32 additions & 12 deletions pkgs/build-support/node/fetch-yarn-deps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,49 @@ in {
name = "prefetch-yarn-deps";

dontUnpack = true;
dontBuild = true;

nativeBuildInputs = [ makeWrapper ];
buildInputs = [ coreutils nix-prefetch-git nodejs-slim nix ];
buildInputs = [ nodejs-slim ];

buildPhase = ''
runHook preBuild
installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/libexec
mkdir libexec
tar --strip-components=1 -xf ${yarnpkg-lockfile-tar} package/index.js
mv index.js libexec/yarnpkg-lockfile.js
cp ${./.}/*.js libexec/
patchShebangs libexec
mv index.js $out/libexec/yarnpkg-lockfile.js
cp ${./.}/common.js ${./.}/index.js $out/libexec/
patchShebangs $out/libexec
makeWrapper $out/libexec/index.js $out/bin/prefetch-yarn-deps \
--prefix PATH : ${lib.makeBinPath [ coreutils nix-prefetch-git nix ]}
runHook postBuild
runHook postInstall
'';

passthru = { inherit tests; };
};

fixup-yarn-lock = stdenv.mkDerivation {
name = "fixup-yarn-lock";

dontUnpack = true;
dontBuild = true;

nativeBuildInputs = [ makeWrapper ];
buildInputs = [ nodejs-slim ];

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -r libexec $out
makeWrapper $out/libexec/index.js $out/bin/prefetch-yarn-deps \
--prefix PATH : ${lib.makeBinPath [ coreutils nix-prefetch-git nix ]}
mkdir -p $out/bin $out/libexec
tar --strip-components=1 -xf ${yarnpkg-lockfile-tar} package/index.js
mv index.js $out/libexec/yarnpkg-lockfile.js
cp ${./.}/common.js ${./.}/fixup.js $out/libexec/
patchShebangs $out/libexec
makeWrapper $out/libexec/fixup.js $out/bin/fixup-yarn-lock
runHook postInstall
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ with pkgs;
fetchpijul = callPackage ../build-support/fetchpijul { };

inherit (callPackages ../build-support/node/fetch-yarn-deps { })
fixup-yarn-lock
prefetch-yarn-deps
fetchYarnDeps;

Expand Down

0 comments on commit 6181939

Please sign in to comment.