The Spack package manager has excellent in-built capabilities for building on system disconnected form the internet. As part of this, this includes the capability to collect all of the required source code to build any package. For example the collected source code for building Tensorflow (without MPI or CUDA) amounts to around 2.4GB after compression. In essence all that of the functionality is provided by the spack mirror command with the spack concretize doing the calculation of what is actually needed in order to produce a particular final package.

An excellent way of being sure of reproducing the entire software system and supply chain in complex projects.

Here is a quick image summary of this works:

architecture