summary refs log tree commit diff
path: root/pkgs/build-support/docker
diff options
context:
space:
mode:
authorLouis Blin <45168934+lbpdt@users.noreply.github.com>2021-03-08 11:24:29 +0000
committerLouis Blin <45168934+lbpdt@users.noreply.github.com>2021-03-10 16:44:53 +0000
commitbf56388c92eeab2d44f8d64b545bb608f502efd4 (patch)
tree5e68a71ca14e08b8a3c97a03b2ca796128def87d /pkgs/build-support/docker
parent0124e874f62cb39dfde076b77eab8184dc1b622e (diff)
downloadnixpkgs-bf56388c92eeab2d44f8d64b545bb608f502efd4.tar
nixpkgs-bf56388c92eeab2d44f8d64b545bb608f502efd4.tar.gz
nixpkgs-bf56388c92eeab2d44f8d64b545bb608f502efd4.tar.bz2
nixpkgs-bf56388c92eeab2d44f8d64b545bb608f502efd4.tar.lz
nixpkgs-bf56388c92eeab2d44f8d64b545bb608f502efd4.tar.xz
nixpkgs-bf56388c92eeab2d44f8d64b545bb608f502efd4.tar.zst
nixpkgs-bf56388c92eeab2d44f8d64b545bb608f502efd4.zip
dockerTools.buildLayeredImage: configurable store root
`stream_layered_image.py` currently assumes that the store root will be
at `/nix/store`, although the user might have configured this
differently. This makes `buildLayeredImage` unusable with stores having
a different root, as they will fail an assertion in the python script.

This change updates that assertion to use `builtins.storeDir` as the
source of truth about where the store lives, instead of assuming
`/nix/store`.
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r--pkgs/build-support/docker/default.nix4
-rw-r--r--pkgs/build-support/docker/stream_layered_image.py10
2 files changed, 9 insertions, 5 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index e9014a88954..e0231f514a2 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -841,12 +841,14 @@ rec {
 
         cat ${baseJson} | jq '
           . + {
+            "store_dir": $store_dir,
             "store_layers": $store_layers,
             "customisation_layer", $customisation_layer,
             "repo_tag": $repo_tag,
             "created": $created
           }
-          ' --argjson store_layers "$store_layers" \
+          ' --arg store_dir "${storeDir}" \
+            --argjson store_layers "$store_layers" \
             --arg customisation_layer ${customisationLayer} \
             --arg repo_tag "$imageName:$imageTag" \
             --arg created "$created" |
diff --git a/pkgs/build-support/docker/stream_layered_image.py b/pkgs/build-support/docker/stream_layered_image.py
index e35bd0b0e8c..60d67442c16 100644
--- a/pkgs/build-support/docker/stream_layered_image.py
+++ b/pkgs/build-support/docker/stream_layered_image.py
@@ -130,12 +130,13 @@ class ExtractChecksum:
 LayerInfo = namedtuple("LayerInfo", ["size", "checksum", "path", "paths"])
 
 
-def add_layer_dir(tar, paths, mtime):
+def add_layer_dir(tar, paths, store_dir, mtime):
     """
     Appends given store paths to a TarFile object as a new layer.
 
     tar: 'tarfile.TarFile' object for the new layer to be added to.
     paths: List of store paths.
+    store_dir: the root directory of the nix store
     mtime: 'mtime' of the added files and the layer tarball.
            Should be an integer representing a POSIX time.
 
@@ -143,9 +144,9 @@ def add_layer_dir(tar, paths, mtime):
              the layer added.
     """
 
-    invalid_paths = [i for i in paths if not i.startswith("/nix/store/")]
+    invalid_paths = [i for i in paths if not i.startswith(store_dir)]
     assert len(invalid_paths) == 0, \
-        "Expecting absolute store paths, but got: {invalid_paths}"
+        f"Expecting absolute paths from {store_dir}, but got: {invalid_paths}"
 
     # First, calculate the tarball checksum and the size.
     extract_checksum = ExtractChecksum()
@@ -245,6 +246,7 @@ def main():
       else datetime.fromisoformat(conf["created"])
     )
     mtime = int(created.timestamp())
+    store_dir = conf["store_dir"]
 
     with tarfile.open(mode="w|", fileobj=sys.stdout.buffer) as tar:
         layers = []
@@ -253,7 +255,7 @@ def main():
               "Creating layer", num,
               "from paths:", store_layer,
               file=sys.stderr)
-            info = add_layer_dir(tar, store_layer, mtime=mtime)
+            info = add_layer_dir(tar, store_layer, store_dir, mtime=mtime)
             layers.append(info)
 
         print("Creating the customisation layer...", file=sys.stderr)