Genode Packages collection https://git.sr.ht/~ehmry/genodepkgs/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

make-bootable-image.nix 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Builds a compressed EFI System Partition image
  2. { config, pkgs, espImage, storeFsImage }:
  3. pkgs.stdenv.mkDerivation {
  4. name = "boot.qcow2";
  5. nativeBuildInputs = with pkgs.buildPackages; [
  6. buildPackages.qemu_test
  7. utillinux
  8. zstd
  9. ];
  10. buildCommand = ''
  11. img=./temp.raw
  12. blockSize=512
  13. sectorSize=$(( $blockSize * 1 ))
  14. imgBytes=0
  15. espSectorOffset=2048
  16. esbByteOffset=$(( $espSectorOffset * $sectorSize ))
  17. # Pad the front of the image
  18. echo "Pad front of image with " $esbByteOffset " bytes"
  19. truncate --size=$esbByteOffset $img
  20. # Concatentenate the ESP
  21. echo "Concatenate ESP ${espImage}"
  22. zstdcat ${espImage} >> $img
  23. imgBytes=$(stat --format=%s $img)
  24. echo "Image is $(( $imgBytes >> 20 )) MiB with ESP partition"
  25. nixSectorOffset=$(( ($imgBytes + $sectorSize - 1) / $sectorSize ))
  26. nixByteOffset=$(( $nixSectorOffset * $sectorSize ))
  27. # Pad the ESP
  28. echo "Pad end of ESP with " $(( $nixByteOffset - $imgBytes )) " bytes"
  29. truncate --size=$nixByteOffset $img
  30. # Concatenate the nix partition
  31. echo "Concatenate store ${storeFsImage}"
  32. zstdcat ${storeFsImage} >> $img
  33. imgBytes=$(stat --format=%s $img)
  34. echo "Image is $(( $imgBytes >> 20 )) MiB with store partition"
  35. endSectorOffset=$(( ($(stat --format=%s $img) + $sectorSize + 1) / $sectorSize ))
  36. endByteOffset=$(( $endSectorOffset * $sectorSize ))
  37. # Pad the end of the image
  38. echo "Pad end of store with $(( $endByteOffset - $imgBytes )) bytes"
  39. truncate --size=$endByteOffset $img
  40. imgBytes=$(stat --format=%s $img)
  41. echo "Image is $(( $imgBytes >> 20 )) MiB with final padding"
  42. efiUuid=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
  43. # Create the partition table
  44. sfdisk $img <<EOF
  45. label: gpt
  46. label-id: 44444444-4444-4444-8888-888888888888
  47. start=$nixSectorOffset, type=${config.genode.boot.storePartUuid}
  48. start=$espSectorOffset, type=$efiUuid
  49. EOF
  50. qemu-img convert $img $out
  51. '';
  52. }