anchor.diff:        mount /dev/${vmTools.hd} disk
         cd disk
   
  -      layers=""
         if [[ -n "$fromImage" ]]; then
           echo "Unpacking base image..."
           mkdir image
           tar -C image -xpf "$fromImage"
  -        layers=$(jq -r '.[0].Layers | join(" ")' image/manifest.json)
  +
  +        # If the image name isn't set, read it from the image repository json.
  +        if [[ -z "$fromImageName" ]]; then
  +          fromImageName=$(jshon -k < image/repositories | head -n 1)
  +          echo "From-image name wasn't set. Read $fromImageName."
  +        fi
  +
  +        # If the tag isn't set, use the name as an index into the json
  +        # and read the first key found.
  +        if [[ -z "$fromImageTag" ]]; then
  +          fromImageTag=$(jshon -e $fromImageName -k < image/repositories \
  +                         | head -n1)
  +          echo "From-image tag wasn't set. Read $fromImageTag."
  +        fi
  +
  +        # Use the name and tag to get the parent ID field.
  +        parentID=$(jshon -e $fromImageName -e $fromImageTag -u \
  +                   < image/repositories)
         fi
   
  -      # Unpack all of the layers into the image.
  -      # Layer list is ordered starting from the base image
  +      # Unpack all of the parent layers into the image.
         lowerdir=""
  -      for layer in $layers; do
  -        echo "Unpacking layer $layer"
  -        layerDir=image/$(echo $layer | cut -d':' -f2)"_unpacked"
  -        mkdir -p $layerDir
  -        tar -C $layerDir -xpf image/$layer
  -        chmod a+w image/$layer
  -        rm image/$layer
  -
  -        find $layerDir -name ".wh.*" -exec bash -c 'name="$(basename {}|sed "s/^.wh.//")"; mknod "$(dirname {})/$name" c 0 0; rm {}' \;
  +      while [[ -n "$parentID" ]]; do
  +        echo "Unpacking layer $parentID"
  +        mkdir -p image/$parentID/layer
  +        tar -C image/$parentID/layer -xpf image/$parentID/layer.tar
  +        rm image/$parentID/layer.tar
  +
  +        find image/$parentID/layer -name ".wh.*" -exec bash -c 'name="$(basename {}|sed "s/^.wh.//")"; mknod "$(dirname {})/$name" c 0 0; rm {}' \;
   
           # Get the next lower directory and continue the loop.
  -        lowerdir=$lowerdir''${lowerdir:+:}$layerDir
  +        lowerdir=$lowerdir''${lowerdir:+:}image/$parentID/layer
  +        parentID=$(cat image/$parentID/json \
  +                  | (jshon -e parent -u 2>/dev/null || true))
         done
   
         mkdir work
  
positive.code: 
          mkdir image
          touch baseFiles
          layers=""
          if [[ -n "$fromImage" ]]; then
            echo "Unpacking base image..."
            tar -C image -xpf "$fromImage"
            config=$(jq -r '.[0].Config' image/manifest.json)
            layers=$(jq -r '.[0].Layers | join(" ")' image/manifest.json)
            for l in $layers; do
              ls_tar image/$l >> baseFiles
            done
            chmod u+w image image/$config
            rm image/$config
          fi
  
          chmod -R ug+rw image
  
negative.code:         };
          inherit fromImage fromImageName fromImageTag;
  
          buildInputs = [ utillinux e2fsprogs jshon rsync ];
        } ''
        rm -rf $out
  
  