@@ -405,6 +405,29 @@ rec {
405405 created = "now";
406406 };
407407
408+ # 23. Ensure that layers are unpacked in the correct order before the
409+ # runAsRoot script is executed.
410+ layersUnpackOrder =
411+ let
412+ layerOnTopOf = parent: layerName:
413+ pkgs.dockerTools.buildImage {
414+ name = "layers-unpack-order-${layerName}";
415+ tag = "latest";
416+ fromImage = parent;
417+ contents = [ pkgs.coreutils ];
418+ runAsRoot = ''
419+ #!${pkgs.runtimeShell}
420+ echo -n "${layerName}" >> /layer-order
421+ '';
422+ };
423+ # When executing the runAsRoot script when building layer C, if layer B is
424+ # not unpacked on top of layer A, the contents of /layer-order will not be
425+ # "ABC".
426+ layerA = layerOnTopOf null "a";
427+ layerB = layerOnTopOf layerA "b";
428+ layerC = layerOnTopOf layerB "c";
429+ in layerC;
430+
408431 # buildImage without explicit tag
409432 bashNoTag = pkgs.dockerTools.buildImage {
410433 name = "bash-no-tag";