dockerTools.buildLayeredImage: store all paths passed in final layer

Fixes #78744

My previous change broke when there are more packages than the maximum
number of layers. I had assumed that the `store-path-to-layer.sh` was
only ever passed a single store path, but that is not the case if
there are multiple packages going into the final layer. To fix this, we
loop through the paths going into the final layer, appending them to the
tar file and making sure they end up at the right path.
This commit is contained in:
Richard Wallace 2020-01-29 14:56:05 -07:00 committed by Antoine Eiche
parent 8979d2dde5
commit 3b65b3f6d6
2 changed files with 11 additions and 11 deletions

View file

@ -246,4 +246,5 @@ rec {
contents = [ pkgs.bash pkgs.hello ];
maxLayers = 2;
};
}

View file

@ -5,11 +5,8 @@ set -eu
layerNumber=$1
shift
storePath="$1"
shift
layerPath="./layers/$layerNumber"
echo "Creating layer #$layerNumber for $storePath"
echo "Creating layer #$layerNumber for $@"
mkdir -p "$layerPath"
@ -35,13 +32,15 @@ tar -cf "$layerPath/layer.tar" \
# to /nix/store. In order to create the correct structure
# in the tar file, we transform the relative nix store
# path to the absolute store path.
n=$(basename "$storePath")
tar -C /nix/store -rpf "$layerPath/layer.tar" \
--hard-dereference --sort=name \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 --group=0 \
--transform="s,$n,/nix/store/$n," \
$n
for storePath in "$@"; do
n=$(basename "$storePath")
tar -C /nix/store -rpf "$layerPath/layer.tar" \
--hard-dereference --sort=name \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 --group=0 \
--transform="s,$n,/nix/store/$n," \
$n
done
# Compute a checksum of the tarball.
tarhash=$(tarsum < $layerPath/layer.tar)