git.iko.soy/typeable/nixpkgs
on master help sign in
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`.

commitbf56388c92eeab2d44f8d64b545bb608f502efd4 authorLouis Blin <45168934+lbpdt@users.noreply.github.com> dateMon 8 Mar 2021, 11:24 (6 years ago) parent0124e87
2 files changed+9−5
pkgs/build-support/docker/default.nix+3−1 pkgs/build-support/docker/stream_layered_image.py+6−4
pkgs/build-support/docker/default.nix+3−1
@@ -841,12 +841,14 @@ rec {
841841
842842 cat ${baseJson} | jq '
843843 . + {
844+ "store_dir": $store_dir,
844845 "store_layers": $store_layers,
845846 "customisation_layer", $customisation_layer,
846847 "repo_tag": $repo_tag,
847848 "created": $created
848849 }
849− ' --argjson store_layers "$store_layers" \
850+ ' --arg store_dir "${storeDir}" \
851+ --argjson store_layers "$store_layers" \
850852 --arg customisation_layer ${customisationLayer} \
851853 --arg repo_tag "$imageName:$imageTag" \
852854 --arg created "$created" |
pkgs/build-support/docker/stream_layered_image.py+6−4
@@ -130,12 +130,13 @@ class ExtractChecksum:
130130LayerInfo = namedtuple("LayerInfo", ["size", "checksum", "path", "paths"])
131131
132132
133−def add_layer_dir(tar, paths, mtime):
133+def add_layer_dir(tar, paths, store_dir, mtime):
134134 """
135135 Appends given store paths to a TarFile object as a new layer.
136136
137137 tar: 'tarfile.TarFile' object for the new layer to be added to.
138138 paths: List of store paths.
139+ store_dir: the root directory of the nix store
139140 mtime: 'mtime' of the added files and the layer tarball.
140141 Should be an integer representing a POSIX time.
141142
@@ -143,9 +144,9 @@ def add_layer_dir(tar, paths, mtime):
143144 the layer added.
144145 """
145146
146− invalid_paths = [i for i in paths if not i.startswith("/nix/store/")]
147+ invalid_paths = [i for i in paths if not i.startswith(store_dir)]
147148 assert len(invalid_paths) == 0, \
148− "Expecting absolute store paths, but got: {invalid_paths}"
149+ f"Expecting absolute paths from {store_dir}, but got: {invalid_paths}"
149150
150151 # First, calculate the tarball checksum and the size.
151152 extract_checksum = ExtractChecksum()
@@ -245,6 +246,7 @@ def main():
245246 else datetime.fromisoformat(conf["created"])
246247 )
247248 mtime = int(created.timestamp())
249+ store_dir = conf["store_dir"]
248250
249251 with tarfile.open(mode="w|", fileobj=sys.stdout.buffer) as tar:
250252 layers = []
@@ -253,7 +255,7 @@ def main():
253255 "Creating layer", num,
254256 "from paths:", store_layer,
255257 file=sys.stderr)
256− info = add_layer_dir(tar, store_layer, mtime=mtime)
258+ info = add_layer_dir(tar, store_layer, store_dir, mtime=mtime)
257259 layers.append(info)
258260
259261 print("Creating the customisation layer...", file=sys.stderr)