anchor.diff:  
         # Create the ESP and mount it. Unlike e2fsprogs, mkfs.vfat doesn't support an
         # '-E offset=X' option, so we can't do this outside the VM.
  -      ${optionalString (partitionTableType == "efi") ''
  +      ${optionalString (partitionTableType == "efi" || partitionTableType == "hybrid") ''
           mkdir -p /mnt/boot
           mkfs.vfat -n ESP /dev/vda1
           mount /dev/vda1 /mnt/boot
  
positive.code:   rootPartition = { # switch-case
      legacy = "1";
      efi = "2";
    }.${partitionTableType};
  
    partitionDiskScript = { # switch-case
  
negative.code:     echo "running nixos-install..."
      nixos-install --root $root --no-bootloader --no-root-passwd \
        --system ${config.system.build.toplevel} --channel ${channelSources} --substituters ""
  
      diskImage=nixos.raw
  
      ${if diskSize == "auto" then ''
        ${if partitionTableType == "efi" || partitionTableType == "hybrid" then ''
          additionalSpace=$(( ($(numfmt --from=iec '${additionalSpace}') + $(numfmt --from=iec '${bootSize}')) / 1000 ))
        '' else ''
          additionalSpace=$(( $(numfmt --from=iec '${additionalSpace}') / 1000 ))
        ''}
        diskSize=$(( $(set -- $(du -d0 $root); echo "$1") + $additionalSpace ))
        truncate -s "$diskSize"K $diskImage
      '' else ''
        truncate -s ${toString diskSize}M $diskImage
      ''}
  
      ${partitionDiskScript}
  
      ${if partitionTableType != "none" then ''
        # Get start & length of the root partition in sectors to $START and $SECTORS.
        eval $(partx $diskImage -o START,SECTORS --nr ${rootPartition} --pairs)
  
        mkfs.${fsType} -F -L ${label} $diskImage -E offset=$(sectorsToBytes $START) $(sectorsToKilobytes $SECTORS)K
      '' else ''
        mkfs.${fsType} -F -L ${label} $diskImage
      ''}
  
      echo "copying staging root to image..."
      cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} -t ${fsType} -i $diskImage $root/* /
  