From 3b65b3f6d637c6576cd9a0fe954aced5aa70de12 Mon Sep 17 00:00:00 2001 From: Richard Wallace Date: Wed, 29 Jan 2020 14:56:05 -0700 Subject: [PATCH] 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. --- pkgs/build-support/docker/examples.nix | 1 + .../docker/store-path-to-layer.sh | 21 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index a1f71d35793c..f6520201a64a 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -246,4 +246,5 @@ rec { contents = [ pkgs.bash pkgs.hello ]; maxLayers = 2; }; + } diff --git a/pkgs/build-support/docker/store-path-to-layer.sh b/pkgs/build-support/docker/store-path-to-layer.sh index c808abab7a8a..7e8efeea1c10 100755 --- a/pkgs/build-support/docker/store-path-to-layer.sh +++ b/pkgs/build-support/docker/store-path-to-layer.sh @@ -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)