diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-01-26 22:39:25 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-01-26 22:39:25 +0000 |
commit | bd2ad77e38991af0d7a3a5d82bd3f41a077ce401 (patch) | |
tree | d1e26d039eb5004eb7c836aafff259cc198626d4 /pkgs/build-support/docker/store-path-to-layer.sh | |
parent | e5d8381542a8d084371d26013fab199f52474be7 (diff) | |
parent | ad3f0d9829119b611350a9be1c226fb625f1f310 (diff) | |
download | nixpkgs-bd2ad77e38991af0d7a3a5d82bd3f41a077ce401.tar nixpkgs-bd2ad77e38991af0d7a3a5d82bd3f41a077ce401.tar.gz nixpkgs-bd2ad77e38991af0d7a3a5d82bd3f41a077ce401.tar.bz2 nixpkgs-bd2ad77e38991af0d7a3a5d82bd3f41a077ce401.tar.lz nixpkgs-bd2ad77e38991af0d7a3a5d82bd3f41a077ce401.tar.xz nixpkgs-bd2ad77e38991af0d7a3a5d82bd3f41a077ce401.tar.zst nixpkgs-bd2ad77e38991af0d7a3a5d82bd3f41a077ce401.zip |
Merge remote-tracking branch 'nixpkgs/master' into master
Diffstat (limited to 'pkgs/build-support/docker/store-path-to-layer.sh')
-rwxr-xr-x | pkgs/build-support/docker/store-path-to-layer.sh | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/pkgs/build-support/docker/store-path-to-layer.sh b/pkgs/build-support/docker/store-path-to-layer.sh index bcad9e83e06..c808abab7a8 100755 --- a/pkgs/build-support/docker/store-path-to-layer.sh +++ b/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) |