Unverified Commit da28a7a3 authored by Ryan Lahfa's avatar Ryan Lahfa Committed by GitHub
Browse files

Merge pull request #228347 from NixOS/uefi-without-bootloaders

nixos/qemu-vm: make it possible to use UEFI without bootloaders
parents cc95744c 6e8248c8
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -169,19 +169,27 @@ let
      # Create a directory for exchanging data with the VM.
      mkdir -p "$TMPDIR/xchg"

      ${lib.optionalString cfg.useBootLoader
      ''
        NIX_EFI_VARS=$(readlink -f "''${NIX_EFI_VARS:-${config.system.name}-efi-vars.fd}")

      ${lib.optionalString cfg.useEFIBoot
      ''
        # Expose EFI variables, it's useful even when we are not using a bootloader (!).
        # We might be interested in having EFI variable storage present even if we aren't booting via UEFI, hence
        # no guard against `useBootLoader`.  Examples:
        # - testing PXE boot or other EFI applications
        # - directbooting LinuxBoot, which `kexec()s` into a UEFI environment that can boot e.g. Windows
        NIX_EFI_VARS=$(readlink -f "''${NIX_EFI_VARS:-${config.system.name}-efi-vars.fd}")
        # VM needs writable EFI vars
        if ! test -e "$NIX_EFI_VARS"; then
            cp ${systemImage}/efi-vars.fd "$NIX_EFI_VARS"
        ${if cfg.useBootLoader then
            # We still need the EFI var from the make-disk-image derivation
            # because our "switch-to-configuration" process might
            # write into it and we want to keep this data.
            ''cp ${systemImage}/efi-vars.fd "$NIX_EFI_VARS"''
            else
            ''cp ${cfg.efi.variables} "$NIX_EFI_VARS"''
          }
          chmod 0644 "$NIX_EFI_VARS"
        fi
      ''}
      ''}

      cd "$TMPDIR"