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.

default.nix 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. { stdenv, lib, edk2, utillinux, nasm, iasl
  2. , csmSupport ? false, seabios ? null
  3. , secureBoot ? false
  4. }:
  5. assert csmSupport -> seabios != null;
  6. let
  7. projectDscPath = if stdenv.isi686 then
  8. "OvmfPkg/OvmfPkgIa32.dsc"
  9. else if stdenv.isx86_64 then
  10. "OvmfPkg/OvmfPkgX64.dsc"
  11. else if stdenv.isAarch64 then
  12. "ArmVirtPkg/ArmVirtQemu.dsc"
  13. else
  14. throw "Unsupported architecture";
  15. version = (builtins.parseDrvName edk2.name).version;
  16. in
  17. edk2.mkDerivation projectDscPath {
  18. name = "OVMF-${version}";
  19. outputs = [ "out" "fd" ];
  20. buildInputs = [ utillinux nasm iasl ];
  21. hardeningDisable = [ "format" "stackprotector" "pic" "fortify" ];
  22. buildFlags =
  23. lib.optional secureBoot "-DSECURE_BOOT_ENABLE=TRUE"
  24. ++ lib.optionals csmSupport [ "-D CSM_ENABLE" "-D FD_SIZE_2MB" ];
  25. postPatch = lib.optionalString csmSupport ''
  26. cp ${seabios}/Csm16.bin OvmfPkg/Csm/Csm16/Csm16.bin
  27. '';
  28. postFixup = if stdenv.isAarch64 then ''
  29. mkdir -vp $fd/FV
  30. mkdir -vp $fd/AAVMF
  31. mv -v $out/FV/QEMU_{EFI,VARS}.fd $fd/FV
  32. # Uses Fedora dir layout: https://src.fedoraproject.org/cgit/rpms/edk2.git/tree/edk2.spec
  33. # FIXME: why is it different from Debian dir layout? https://salsa.debian.org/qemu-team/edk2/blob/debian/debian/rules
  34. dd of=$fd/AAVMF/QEMU_EFI-pflash.raw if=/dev/zero bs=1M count=64
  35. dd of=$fd/AAVMF/QEMU_EFI-pflash.raw if=$fd/FV/QEMU_EFI.fd conv=notrunc
  36. dd of=$fd/AAVMF/vars-template-pflash.raw if=/dev/zero bs=1M count=64
  37. '' else ''
  38. mkdir -vp $fd/FV
  39. mv -v $out/FV/OVMF{,_CODE,_VARS}.fd $fd/FV
  40. '';
  41. dontPatchELF = true;
  42. meta = {
  43. description = "Sample UEFI firmware for QEMU and KVM";
  44. homepage = https://github.com/tianocore/tianocore.github.io/wiki/OVMF;
  45. license = stdenv.lib.licenses.bsd2;
  46. platforms = ["x86_64-linux" "i686-linux" "aarch64-linux"];
  47. };
  48. }