fix: aggregated fetching

This commit is contained in:
DavHau 2021-11-18 12:09:14 +07:00
parent 553d29724f
commit 5ad6855226
3 changed files with 20 additions and 12 deletions

View File

@ -97,38 +97,46 @@ let
else else
"" ""
else if lib.isList x then else if lib.isList x then
builtins.toString (lib.forEach x (y: toString y)) ''"${lib.concatStringsSep " " (lib.forEach x (y: toString' y))}"''
else if x == null then else if x == null then
"" ""
else else
builtins.toJSON x; b.toJSON x;
# generate script to fetch single item # set up nix build env for signle item
fetchItem = fetcherArgs: '' setupEnvForItem = fetcherArgs: ''
# export arguments for builder # export arguments for builder
${lib.concatStringsSep "\n" (lib.mapAttrsToList (argName: argVal: '' ${lib.concatStringsSep "\n" (lib.mapAttrsToList (argName: argVal: ''
export ${argName}=${toString' argVal} export ${argName}=${
lib.replaceStrings [ "$" ''\n'' ] [ ''\$'' "\n" ] (toString' argVal)}
'') fetcherArgs)} '') fetcherArgs)}
# run builder # run builder
bash ${fetcherArgs.builder} bash ${fetcherArgs.builder}
''; '';
mkScriptItem = fetcherArgs: '' mkScriptForItem = fetcherArgs: ''
# configure $out
OUT_ORIG=$out OUT_ORIG=$out
export out=$OUT_ORIG/${fetcherArgs.outPath} export out=$OUT_ORIG/${fetcherArgs.outPath}
mkdir -p $(dirname $out) mkdir -p $(dirname $out)
# set up TMP and TMPDIR
workdir=$(mktemp -d) workdir=$(mktemp -d)
TMP=$workdir/TMP
TMPDIR=$TMP
mkdir -p $TMP
# do the work
pushd $workdir pushd $workdir
${fetchItem fetcherArgs} ${setupEnvForItem fetcherArgs}
popd popd
rm -r $workdir rm -r $workdir
''; '';
# builder which wraps several other FOD builders # builder which wraps several other FOD builders
# and executes these after each other inside a single build # and executes these after each other inside a single build
# TODO: for some reason PATH is unset and we don't have access to the stdenv tools
builder = writeScript "multi-source-fetcher" '' builder = writeScript "multi-source-fetcher" ''
#!${bash}/bin/bash #!${bash}/bin/bash
export PATH=${coreutils}/bin:${bash}/bin export PATH=${coreutils}/bin:${bash}/bin
@ -142,13 +150,13 @@ let
${lib.concatStringsSep "\n" ${lib.concatStringsSep "\n"
(b.map (b.map
(fetcherArgs: '' (fetcherArgs: ''
$async -s="$S" cmd -- bash -c '${mkScriptItem fetcherArgs}' $async -s="$S" cmd -- bash -c '${mkScriptForItem fetcherArgs}'
'') '')
FODArgsAllList)} FODArgsAllList)}
$async -s="$S" wait $async -s="$S" wait
echo "FOD_HASH=$(${nix}/bin/nix hash-path $out)" echo "FOD_HASH=$(${nix}/bin/nix hash path $out)"
''; '';
FODAllSources = FODAllSources =

View File

@ -11,7 +11,7 @@ let
fetchAggrgatedGithub = fetchAggrgatedGithub =
dream2nix.utils.toDrv dream2nix.utils.toDrv
(dream2nix.fetchSources { (dream2nix.fetchSources {
dreamLock = ./prettier.json; dreamLock = ./prettier-github-aggregated.json;
}).fetchedSources.prettier."2.4.1"; }).fetchedSources.prettier."2.4.1";
in in

View File

@ -2,7 +2,7 @@
"_generic": { "_generic": {
"mainPackageName": "prettier", "mainPackageName": "prettier",
"mainPackageVersion": "2.4.1", "mainPackageVersion": "2.4.1",
"sourcesAggregatedHash": "sha256-AR5QtVJE15NCLJpjWdg6UxhIEwFGsCAne5TI3DcOMeI=", "sourcesAggregatedHash": "sha256-ro6ysaTWAtUtKO0w3y7YFMq99nkOwucuwlKLBiFyuZ0=",
"subsystem": "nodejs", "subsystem": "nodejs",
"translatedBy": "nodejs.pure.yarn-lock", "translatedBy": "nodejs.pure.yarn-lock",
"translator": "yarn-lock", "translator": "yarn-lock",