diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-01-14 23:59:31 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-01-14 23:59:31 +0000 |
commit | 388bd5ecef704d7aa423878e28cf46820ba42aaa (patch) | |
tree | f56964e1b059a3400259b2a6c9274f0bd58e5648 /nixpkgs/pkgs/build-support/docker | |
parent | a5e4eba0a2066e541c1e81938655cbf62067804e (diff) | |
parent | 100012e55bc2a82fc680cba31a426ad38ead6fab (diff) | |
download | nixlib-388bd5ecef704d7aa423878e28cf46820ba42aaa.tar nixlib-388bd5ecef704d7aa423878e28cf46820ba42aaa.tar.gz nixlib-388bd5ecef704d7aa423878e28cf46820ba42aaa.tar.bz2 nixlib-388bd5ecef704d7aa423878e28cf46820ba42aaa.tar.lz nixlib-388bd5ecef704d7aa423878e28cf46820ba42aaa.tar.xz nixlib-388bd5ecef704d7aa423878e28cf46820ba42aaa.tar.zst nixlib-388bd5ecef704d7aa423878e28cf46820ba42aaa.zip |
Merge commit '100012e55bc2a82fc680cba31a426ad38ead6fab'
Diffstat (limited to 'nixpkgs/pkgs/build-support/docker')
-rw-r--r-- | nixpkgs/pkgs/build-support/docker/default.nix | 18 | ||||
-rwxr-xr-x | nixpkgs/pkgs/build-support/docker/store-path-to-layer.sh | 37 |
2 files changed, 48 insertions, 7 deletions
diff --git a/nixpkgs/pkgs/build-support/docker/default.nix b/nixpkgs/pkgs/build-support/docker/default.nix index e10ff269950d..3fcae13e20d7 100644 --- a/nixpkgs/pkgs/build-support/docker/default.nix +++ b/nixpkgs/pkgs/build-support/docker/default.nix @@ -325,7 +325,6 @@ rec { | jshon -d config \ | jshon -s "1970-01-01T00:00:01Z" -i created > generic.json - # WARNING! # The following code is fiddly w.r.t. ensuring every layer is # created, and that no paths are missed. If you change the @@ -625,7 +624,22 @@ rec { -i "$imageName" > image/repositories echo "Cooking the image..." - tar -C image --dereference --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0 --mode=a-w --xform s:'^./':: -c . | pigz -nT > $out + # tar exits with an exit code of 1 if files changed while it was + # reading them. It considers a change in the number of hard links + # to be a "change", which can cause this to fail if images are being + # built concurrently and the auto-optimise-store nix option is turned on. + # Since the contents of these files will not change, we can reasonably + # ignore this exit code. + set +e + tar -C image --dereference --hard-dereference --sort=name \ + --mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0 \ + --mode=a-w --xform s:'^./':: --use-compress-program='pigz -nT' \ + --warning=no-file-changed -cf $out . + RET=$? + if [ $RET -ne 0 ] && [ $RET -ne 1 ]; then + exit $RET + fi + set -e echo "Finished." ''; diff --git a/nixpkgs/pkgs/build-support/docker/store-path-to-layer.sh b/nixpkgs/pkgs/build-support/docker/store-path-to-layer.sh index bcad9e83e06f..c808abab7a8a 100755 --- a/nixpkgs/pkgs/build-support/docker/store-path-to-layer.sh +++ b/nixpkgs/pkgs/build-support/docker/store-path-to-layer.sh @@ -5,16 +5,43 @@ set -eu layerNumber=$1 shift +storePath="$1" +shift + layerPath="./layers/$layerNumber" -echo "Creating layer #$layerNumber for $@" +echo "Creating layer #$layerNumber for $storePath" mkdir -p "$layerPath" -tar --no-recursion -rf "$layerPath/layer.tar" \ + +# Make sure /nix and /nix/store appear first in the archive. +# We create the directories here and use them because +# when there are other things being added to the +# nix store, tar could fail, saying, +# "tar: /nix/store: file changed as we read it" +mkdir -p nix/store +tar -cf "$layerPath/layer.tar" \ --mtime="@$SOURCE_DATE_EPOCH" \ - --owner=0 --group=0 /nix /nix/store -tar -rpf "$layerPath/layer.tar" --hard-dereference --sort=name \ + --owner=0 --group=0 \ + --transform='s,nix,/nix,' \ + nix + +# We change into the /nix/store in order to avoid a similar +# "file changed as we read it" error as above. Namely, +# if we use the absolute path of /nix/store/123-pkg +# and something new is added to the nix store while tar +# is running, it will detect a change to /nix/store and +# fail. Instead, if we cd into the nix store and copy +# the relative nix store path, tar will ignore changes +# 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 "$@" + --owner=0 --group=0 \ + --transform="s,$n,/nix/store/$n," \ + $n # Compute a checksum of the tarball. tarhash=$(tarsum < $layerPath/layer.tar) |