-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bun: init configHook and fetchDeps; bun 1.1.43 -> 1.2.0; bun: switch …
…to finalAttrs from rec bun: switch to finalAttrs from rec Could speed up hydra? bun: added hook tests and improve passthru for hooks
- Loading branch information
1 parent
4b85446
commit bb19900
Showing
6 changed files
with
430 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# shellcheck shell=bash | ||
|
||
bunConfigHook() { | ||
echo "Executing bunConfigHook" | ||
|
||
if [ -n "${bunRoot-}" ]; then | ||
pushd "$bunRoot" | ||
fi | ||
|
||
if [ -z "${bunDeps-}" ]; then | ||
echo "Error: 'bunDeps' must be set when using bunConfigHook." | ||
exit 1 | ||
fi | ||
|
||
echo "Configuring bun store" | ||
|
||
export HOME=$(mktemp -d) | ||
export BUN_INSTALL_CACHE_DIR=$(mktemp -d) | ||
|
||
cp -Tr "$bunDeps" "$BUN_INSTALL_CACHE_DIR" | ||
chmod -R +w "$BUN_INSTALL_CACHE_DIR" | ||
|
||
echo "Installing dependencies" | ||
if [[ -n "$bunWorkspaces" ]]; then | ||
local IFS=" " | ||
for ws in $bunWorkspaces; do | ||
bunInstallFlags+=("--filter=$ws") | ||
done | ||
fi | ||
|
||
runHook preBunInstall | ||
|
||
bun install \ | ||
--offline \ | ||
--ignore-scripts \ | ||
"${bunInstallFlags[@]}" \ | ||
--frozen-lockfile | ||
|
||
echo "Patching scripts" | ||
|
||
patchShebangs node_modules/{*,.*} | ||
|
||
if [ -n "${bunRoot-}" ]; then | ||
popd | ||
fi | ||
|
||
echo "Finished bunConfigHook" | ||
} | ||
|
||
postConfigureHooks+=(pnpmConfigHook) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
lib, | ||
stdenvNoCC, | ||
callPackage, | ||
jq, | ||
moreutils, | ||
cacert, | ||
makeSetupHook, | ||
bun, | ||
yq, | ||
}: | ||
|
||
{ | ||
fetchDeps = | ||
{ | ||
hash ? "", | ||
pname, | ||
bunWorkspaces ? [ ], | ||
preBunInstall ? "", | ||
bunInstallFlags ? [ ], | ||
... | ||
}@args: | ||
let | ||
args' = builtins.removeAttrs args [ | ||
"hash" | ||
"pname" | ||
]; | ||
hash' = | ||
if hash != "" then | ||
{ outputHash = hash; } | ||
else | ||
{ | ||
outputHash = ""; | ||
outputHashAlgo = "sha256"; | ||
}; | ||
|
||
filterFlags = lib.map (package: "--filter=${package}") bunWorkspaces; | ||
in | ||
stdenvNoCC.mkDerivation ( | ||
finalAttrs: | ||
( | ||
args' | ||
// { | ||
name = "${pname}-bun-deps"; | ||
|
||
nativeBuildInputs = [ | ||
cacert | ||
jq | ||
moreutils | ||
bun | ||
]; | ||
|
||
installPhase = '' | ||
runHook preInstall | ||
lockfileVersion="$(jq -r .lockfileVersion bun.lock)" | ||
if [[ ''${lockfileVersion:0:1} -gt ${lib.versions.major bun.version} ]]; then | ||
echo "ERROR: lockfileVersion $lockfileVersion in bun.lock is too new for the provided bun version ${lib.versions.major bun.version}!" | ||
exit 1 | ||
fi | ||
export HOME=$(mktemp -d) | ||
export BUN_INSTALL_CACHE_DIR = $out | ||
${preBunInstall} | ||
bun install \ | ||
--force \ | ||
${lib.escapeShellArgs filterFlags} \ | ||
${lib.escapeShellArgs bunInstallFlags} \ | ||
--frozen-lockfile | ||
runHook postInstall | ||
''; | ||
|
||
fixupPhase = '' | ||
runHook preFixup | ||
# Remove timestamp and sort the json files | ||
# rm -rf $out/v3/tmp | ||
# for f in $(find $out -name "*.json"); do | ||
# jq --sort-keys "del(.. | .checkedAt?)" $f | sponge $f | ||
# done | ||
runHook postFixup | ||
''; | ||
|
||
dontConfigure = true; | ||
dontBuild = true; | ||
outputHashMode = "recursive"; | ||
} | ||
// hash' | ||
) | ||
); | ||
|
||
configHook = makeSetupHook { | ||
name = "bun-config-hook"; | ||
propagatedBuildInputs = [ bun ]; | ||
} ./bun-config-hook.sh; | ||
} |
Oops, something went wrong.