diff --git a/pkgs/by-name/gr/grub2_pvgrub_image/package.nix b/pkgs/by-name/gr/grub2_pvgrub_image/package.nix deleted file mode 100644 index 3aa240ed9fee..000000000000 --- a/pkgs/by-name/gr/grub2_pvgrub_image/package.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ - lib, - stdenv, - grub2_xen, -}: - -let - efiSystemsBuild = { - i686-linux.target = "i386"; - x86_64-linux.target = "x86_64"; - armv7l-linux.target = "arm"; - aarch64-linux.target = "aarch64"; - riscv32-linux.target = "riscv32"; - riscv64-linux.target = "riscv64"; - }; - -in -( - - stdenv.mkDerivation rec { - name = "pvgrub-image"; - - configs = ./configs; - - buildInputs = [ grub2_xen ]; - - buildCommand = '' - 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/${ - 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/ - ''; - - meta = with lib; { - description = "PvGrub image for use for booting PV Xen guests"; - - longDescription = '' - This package provides a PvGrub image for booting Para-Virtualized (PV) - Xen guests - ''; - - platforms = platforms.gnu ++ platforms.linux; - }; - } -) diff --git a/pkgs/by-name/gr/grub2_pvgrub_image/configs/grub-bootstrap.cfg b/pkgs/by-name/gr/grub2_pvhgrub_image/configs/grub-bootstrap.cfg similarity index 100% rename from pkgs/by-name/gr/grub2_pvgrub_image/configs/grub-bootstrap.cfg rename to pkgs/by-name/gr/grub2_pvhgrub_image/configs/grub-bootstrap.cfg diff --git a/pkgs/by-name/gr/grub2_pvgrub_image/configs/grub.cfg b/pkgs/by-name/gr/grub2_pvhgrub_image/configs/grub.cfg similarity index 100% rename from pkgs/by-name/gr/grub2_pvgrub_image/configs/grub.cfg rename to pkgs/by-name/gr/grub2_pvhgrub_image/configs/grub.cfg diff --git a/pkgs/by-name/gr/grub2_pvhgrub_image/package.nix b/pkgs/by-name/gr/grub2_pvhgrub_image/package.nix new file mode 100644 index 000000000000..f65c0dffdc32 --- /dev/null +++ b/pkgs/by-name/gr/grub2_pvhgrub_image/package.nix @@ -0,0 +1,83 @@ +{ + lib, + stdenv, + grub2_xen, + grub2_xen_pvh, + grubPlatform ? "xen_pvh", +}: + +assert lib.assertOneOf "grubPlatform" grubPlatform [ + "xen" + "xen_pvh" +]; +let + targets = { + i686-linux.target = "i386"; + x86_64-linux.target = if grubPlatform == "xen_pvh" then "i386" else "x86_64"; + }; +in +stdenv.mkDerivation { + name = "grub2_${grubPlatform}_image"; + + env = { + GRUB_CONFIGS = "${./configs}"; + GRUB_FORMAT = "${targets.${stdenv.buildPlatform.system}.target}-${grubPlatform}"; + }; + + buildInputs = + lib.optional (grubPlatform == "xen") grub2_xen + ++ lib.optional (grubPlatform == "xen_pvh") grub2_xen_pvh; + + dontUnpack = true; + + buildPhase = '' + cp "$GRUB_CONFIGS"/* . + tar -cf memdisk.tar grub.cfg + grub-mkimage \ + -O "$GRUB_FORMAT" \ + -c grub-bootstrap.cfg \ + -m memdisk.tar \ + -o grub-"$GRUB_FORMAT".bin \ + ${if grubPlatform == "xen_pvh" then grub2_xen_pvh else grub2_xen}/lib/grub/"$GRUB_FORMAT"/*.mod + ''; + + installPhase = '' + mkdir -p "$out/lib/grub-${grubPlatform}" + cp grub-"$GRUB_FORMAT".bin $out/lib/grub-${grubPlatform}/ + ''; + + dontFixup = true; + + meta = { + description = "PvGrub2 image for booting ${ + if grubPlatform == "xen_pvh" then "PVH" else "PV" + } Xen guests"; + + longDescription = + if (grubPlatform == "xen_pvh") then + '' + This package provides a prebuilt PvGrub2 image for booting PVH Xen + guests (also commonly referred to as PvhGrub2), which searches for + `grub.cfg` on the guest disk and interprets it to load the kernel, + eliminating the need to copy the guest kernel to the Dom0. + + You will need `pkgs.grub2_xen_pvh` to build a customized PvhGrub2 + image. See [PvGrub2](https://wiki.xenproject.org/wiki/PvGrub2) for + more explanations. + '' + else + '' + This package provides a prebuilt PvGrub2 image for booting PV Xen + guests, which searches for `grub.cfg` on the guest disk and interprets + it to load the kernel, eliminating the need to copy the guest kernel + to the Dom0. + + You will need `pkgs.grub2_xen` to build a customized PvGrub2 image. + See [PvGrub2](https://wiki.xenproject.org/wiki/PvGrub2) for more + explanations. + ''; + + teams = [ lib.teams.xen ]; + platforms = lib.attrNames targets; + }; +} diff --git a/pkgs/tools/misc/grub/default.nix b/pkgs/tools/misc/grub/default.nix index e083c3e92ed0..66f7c981fff4 100644 --- a/pkgs/tools/misc/grub/default.nix +++ b/pkgs/tools/misc/grub/default.nix @@ -28,6 +28,7 @@ efiSupport ? false, zfsSupport ? false, xenSupport ? false, + xenPvhSupport ? false, kbdcompSupport ? false, ckbcomp, }: @@ -65,6 +66,11 @@ let x86_64-linux.target = "x86_64"; }; + xenPvhSystemsBuild = { + i686-linux.target = "i386"; + x86_64-linux.target = "i386"; # Xen PVH is only i386 on x86. + }; + inPCSystems = lib.any (system: stdenv.hostPlatform.system == system) (lib.attrNames pcSystems); gnulib = fetchgit { @@ -84,7 +90,8 @@ let in assert zfsSupport -> zfs != null; -assert !(efiSupport && xenSupport); +assert !(efiSupport && (xenSupport || xenPvhSupport)); +assert !(xenSupport && xenPvhSupport); stdenv.mkDerivation rec { pname = "grub"; @@ -609,6 +616,10 @@ stdenv.mkDerivation rec { ++ lib.optionals xenSupport [ "--with-platform=xen" "--target=${xenSystemsBuild.${stdenv.hostPlatform.system}.target}" + ] + ++ lib.optionals xenPvhSupport [ + "--with-platform=xen_pvh" + "--target=${xenPvhSystemsBuild.${stdenv.hostPlatform.system}.target}" ]; # save target that grub is compiled for @@ -660,6 +671,8 @@ stdenv.mkDerivation rec { lib.attrNames efiSystemsBuild else if xenSupport then lib.attrNames xenSystemsBuild + else if xenPvhSupport then + lib.attrNames xenPvhSystemsBuild else platforms.gnu ++ platforms.linux; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 17915b05cfcd..8ac4c5207e43 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3067,6 +3067,14 @@ with pkgs; xenSupport = true; }; + grub2_xen_pvh = grub2.override { + xenPvhSupport = true; + }; + + grub2_pvgrub_image = grub2_pvhgrub_image.override { + grubPlatform = "xen"; + }; + grub4dos = callPackage ../tools/misc/grub4dos { stdenv = stdenv_32bit; };