grub2: refactor platforms logic, avoid abusing meta.broken

Previously, we used `platforms.gnu` and `platforms.linux` for Grub2's available
platforms, but blocking unsupported platforms via asserts. An attempt has been
made through marking unsupported platforms "broken" for EFI, but it would be
better if we just document the supported platforms in `meta.platforms` in the
first place. Also, the Grub2 package already has platform support for
PC/EFI/Xen, which deserves to be restructured in a unified way.

Regarding `meta.broken`, it shouldn't be used on invalid combinations of
arguments, as it will cause misunderstandings.

Changes have been made:
- Remove `meta.broken`, along with the 3 conditions in it.
- Remove `canEfi`, chain `efiSystemsBuild` on `meta.platform` if
  `pkgs.grub2_efi` is asked (building with `efiSupport = true;`)
- Avoid reusing `efiSystemsBuild` for Xen (PV), build a dedicated
  `xenSystemsBuild` for Xen, and chain that into `meta.platforms` in the same
  format.
- Revert the other 2 conditions (building with invalid arguments) back to
  asserts.

Signed-off-by: Hongbo <hehongbo@mail.com>
This commit is contained in:
Hongbo 2025-07-27 18:50:25 +08:00
parent 63ba1c64e6
commit f92169c861

View File

@ -60,12 +60,12 @@ let
riscv64-linux.target = "riscv64";
};
canEfi = lib.any (system: stdenv.hostPlatform.system == system) (
lib.mapAttrsToList (name: _: name) efiSystemsBuild
);
inPCSystems = lib.any (system: stdenv.hostPlatform.system == system) (
lib.mapAttrsToList (name: _: name) pcSystems
);
xenSystemsBuild = {
i686-linux.target = "i386";
x86_64-linux.target = "x86_64";
};
inPCSystems = lib.any (system: stdenv.hostPlatform.system == system) (lib.attrNames pcSystems);
gnulib = fetchFromSavannah {
repo = "gnulib";
@ -88,6 +88,10 @@ let
hash = "sha256-IoRiJHNQ58y0UhCAD0CrpFiI8Mz1upzAtyh5K4Njh/w=";
};
in
assert zfsSupport -> zfs != null;
assert !(efiSupport && xenSupport);
stdenv.mkDerivation rec {
pname = "grub";
version = "2.12";
@ -605,7 +609,7 @@ stdenv.mkDerivation rec {
]
++ lib.optionals xenSupport [
"--with-platform=xen"
"--target=${efiSystemsBuild.${stdenv.hostPlatform.system}.target}"
"--target=${xenSystemsBuild.${stdenv.hostPlatform.system}.target}"
];
# save target that grub is compiled for
@ -653,16 +657,13 @@ stdenv.mkDerivation rec {
license = licenses.gpl3Plus;
platforms =
if xenSupport then
[
"x86_64-linux"
"i686-linux"
]
if efiSupport then
lib.attrNames efiSystemsBuild
else if xenSupport then
lib.attrNames xenSystemsBuild
else
platforms.gnu ++ platforms.linux;
maintainers = [ ];
broken = !(efiSupport -> canEfi) || !(zfsSupport -> zfs != null) || (efiSupport && xenSupport);
};
}