@@ -1,5 +1,5 @@
11{ stdenv, lib, callPackage, runCommand, writeReferencesToFile, writeText, vmTools, writeScript
2−, docker, shadow, utillinux, coreutils, jshon, e2fsprogs, go, pigz }:
2+, docker, shadow, utillinux, coreutils, jshon, e2fsprogs, go, pigz, findutils }:
33
44# WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future.
55
@@ -249,7 +249,7 @@ EOF
249249 then mkPureLayer { inherit baseJson contents extraCommands; }
250250 else mkRootLayer { inherit baseJson fromImage fromImageName fromImageTag contents runAsRoot diskSize extraCommands; });
251251 result = runCommand "${baseName}.tar.gz" {
252− buildInputs = [ jshon pigz ];
252+ buildInputs = [ jshon pigz coreutils findutils ];
253253
254254 imageName = name;
255255 imageTag = tag;
@@ -261,6 +261,18 @@ EOF
261261 buildArgs = args;
262262 };
263263 } ''
264+ # Print tar contents:
265+ # 1: Interpreted as relative to the root directory
266+ # 2: With no trailing slashes on directories
267+ # This is useful for ensuring that the output matches the values generated by the "find" command
268+ ls_tar() {
269+ for f in $(tar -tf $1 | xargs realpath -ms --relative-to=.); do
270+ if [ "$f" != "." ]; then
271+ echo "/$f"
272+ fi
273+ done
274+ }
275+
264276 mkdir image
265277 touch baseFiles
266278 if [ -n "$fromImage" ]; then
@@ -276,7 +288,7 @@ EOF
276288 parentID=$(jshon -e $fromImageName -e $fromImageTag -u < image/repositories)
277289
278290 for l in image/*/layer.tar; do
279− tar -tf $l >> baseFiles
291+ ls_tar $l >> baseFiles
280292 done
281293 fi
282294
@@ -297,8 +309,7 @@ EOF
297309 fi
298310
299311 echo Adding layer
300− tar -tf temp/layer.tar >> baseFiles
301− sed 's/^\.//' -i baseFiles
312+ ls_tar temp/layer.tar >> baseFiles
302313 comm <(sort -u baseFiles) <(sort -u layerFiles) -1 -3 > newFiles
303314 tar -rpf temp/layer.tar --mtime=0 --no-recursion --files-from newFiles 2>/dev/null || true
304315