Skip to content

Commit

Permalink
grub: build grub2_pvhgrub_image together with grub2_pvgrub_image
Browse files Browse the repository at this point in the history
The PvhGrub image requires the same steps to build compared to the PV one, so we
moved the old `grub2_pvgrub_image` package and shared that between PV and PVH.

Co-authored-by: William Johansson <[email protected]>
Signed-off-by: Hongbo <[email protected]>
  • Loading branch information
hehongbo and radhus committed Jan 18, 2025
1 parent a6632ec commit 6c05e79
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
54 changes: 30 additions & 24 deletions pkgs/by-name/gr/grub2-xen-images/package.nix
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
{
lib,
stdenv,
grub2_xen,
}:
{ lib, stdenv, buildPvImage ? false, grub2_xen, buildPvhImage ? false
, grub2_xen_pvh, }:

assert (buildPvImage != buildPvhImage);
let
efiSystemsBuild = {
i686-linux.target = "i386";
x86_64-linux.target = "x86_64";
x86_64-linux.target = if buildPvhImage then "i386" else "x86_64";
armv7l-linux.target = "arm";
aarch64-linux.target = "aarch64";
riscv32-linux.target = "riscv32";
riscv64-linux.target = "riscv64";
};

in
(
in (

stdenv.mkDerivation rec {
name = "pvgrub-image";
name = "grub2-xen-images";

configs = ./configs;

buildInputs = [ grub2_xen ];
buildInputs = lib.optional buildPvImage grub2_xen
++ lib.optional buildPvhImage grub2_xen_pvh;

buildCommand = ''
buildCommand = let grubVariant = if buildPvImage then "xen" else "xen_pvh";
in ''
cp "${configs}"/* .
tar -cf memdisk.tar grub.cfg
# We include all modules except all_video.mod as otherwise grub will fail printing "no symbol table"
# if we include it.
grub-mkimage -O "${
efiSystemsBuild.${stdenv.hostPlatform.system}.target
}-xen" -c grub-bootstrap.cfg \
-m memdisk.tar -o "grub-${efiSystemsBuild.${stdenv.hostPlatform.system}.target}-xen.bin" \
$(ls "${grub2_xen}/lib/grub/${
grub-mkimage \
-O "${
efiSystemsBuild.${stdenv.hostPlatform.system}.target
}-${grubVariant}" \
-c grub-bootstrap.cfg \
-m memdisk.tar \
-o "grub-${
efiSystemsBuild.${stdenv.hostPlatform.system}.target
}-xen/" |grep 'mod''$'|grep -v '^all_video\.mod''$')
mkdir -p "$out/lib/grub-xen"
cp "grub-${efiSystemsBuild.${stdenv.hostPlatform.system}.target}-xen.bin" $out/lib/grub-xen/
}-${grubVariant}.bin" \
$(ls "${if buildPvImage then grub2_xen else grub2_xen_pvh}/lib/grub/${
efiSystemsBuild.${stdenv.hostPlatform.system}.target
}-${grubVariant}/" | grep 'mod$' | grep -v '^all_video\.mod$')
mkdir -p "$out/lib/grub-${grubVariant}"
cp "grub-${
efiSystemsBuild.${stdenv.hostPlatform.system}.target
}-${grubVariant}.bin" $out/lib/grub-${grubVariant}/
'';

meta = with lib; {
description = "PvGrub image for use for booting PV Xen guests";
description =
"PvGrub and PvhGrub images for use for booting PV/PVH Xen guests";

longDescription = ''
This package provides a PvGrub image for booting Para-Virtualized (PV)
Xen guests
This package provides PvGrub/PvhGrub images for booting
Paravirtualized (PV) or Paravirtualized Hardware (PVH) Xen guests
'';

platforms = platforms.gnu ++ platforms.linux;
};
}
)
})
8 changes: 8 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3572,6 +3572,14 @@ with pkgs;
xenPvhSupport = true;
};

grub2_pvgrub_image = callPackage ../by-name/gr/grub2-xen-images/package.nix {
buildPvImage = true;
};

grub2_pvhgrub_image = callPackage ../by-name/gr/grub2-xen-images/package.nix {
buildPvhImage = true;
};

grub4dos = callPackage ../tools/misc/grub4dos {
stdenv = stdenv_32bit;
};
Expand Down

0 comments on commit 6c05e79

Please sign in to comment.