{ lib, runCommand, fetchDepotFile }: name: caches: ps: with lib; let emitStep = { FileName, Flags, Chunks, ... }@file: if bitAnd Flags 64 != 0 || Chunks == [] then '' mkdir -p $out/'${FileName}' '' else let drv = fetchDepotFile file; in '' mkdir -p $out/'${drv.passthru.dirname}' ln -s '${drv}' $out/'${FileName}' ''; emitManifest = cache: with cache.passthru; let json = "${cache}/.DepotDownloader/${toString depot}_${manifest}.json"; mkStep = file: emitStep (file // { inherit cache; }); in concatMapStrings mkStep (importJSON json).Files; in runCommand name {} '' ${concatMapStringsSep "\n" emitManifest caches} ${ps} ''