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-esp-fs.nix 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Builds a compressed EFI System Partition image
  2. { config, pkgs }:
  3. let
  4. grub' = pkgs.buildPackages.grub2_efi;
  5. # Name used by UEFI for architectures.
  6. targetArch = if pkgs.stdenv.isi686 || config.boot.loader.grub.forcei686 then
  7. "ia32"
  8. else if pkgs.stdenv.isx86_64 then
  9. "x64"
  10. else if pkgs.stdenv.isAarch64 then
  11. "aa64"
  12. else
  13. throw "Unsupported architecture";
  14. in pkgs.stdenv.mkDerivation {
  15. name = "esp.img.zst";
  16. nativeBuildInputs = with pkgs.buildPackages; [ grub' dosfstools mtools zstd ];
  17. MODULES = [
  18. "configfile"
  19. "efi_gop"
  20. "efi_uga"
  21. "ext2"
  22. "gzio"
  23. "multiboot"
  24. "multiboot2"
  25. "normal"
  26. "part_gpt"
  27. "search_fs_uuid"
  28. ];
  29. buildCommand = ''
  30. img=tmp.raw
  31. bootdir=EFI/boot/
  32. mkdir -p $bootdir
  33. cat <<EOF > embedded.cfg
  34. insmod configfile
  35. insmod efi_gop
  36. insmod efi_uga
  37. insmod ext2
  38. insmod normal
  39. insmod part_gpt
  40. insmod search_fs_uuid
  41. search.fs_uuid ${config.genode.boot.storeFsUuid} root
  42. set prefix=($root)/boot/grub
  43. configfile /boot/grub/grub.cfg
  44. EOF
  45. grub-script-check embedded.cfg
  46. ${grub'}/bin/grub-mkimage \
  47. --config=embedded.cfg \
  48. --output=$bootdir/boot${targetArch}.efi \
  49. --prefix=/boot/grub \
  50. --format=${grub'.grubTarget} \
  51. $MODULES
  52. # Make the ESP image twice as large as necessary
  53. imageBytes=$(du --summarize --block-size=4096 --total $bootdir | tail -1 | awk '{ print int($1 * 8192) }')
  54. truncate --size=$imageBytes $img
  55. mkfs.vfat -n EFIBOOT --invariant $img
  56. mcopy -sv -i $img EFI ::
  57. fsck.vfat -nv $img
  58. zstd --verbose --no-progress ./$img -o $out
  59. '';
  60. }