Skip to content

Commit a677a45

Browse files
hehongbocolemickens
authored andcommitted
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 <[email protected]>
1 parent 5b09dc4 commit a677a45

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

pkgs/tools/misc/grub/default.nix

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ let
6060
riscv64-linux.target = "riscv64";
6161
};
6262

63-
canEfi = lib.any (system: stdenv.hostPlatform.system == system) (
64-
lib.mapAttrsToList (name: _: name) efiSystemsBuild
65-
);
66-
inPCSystems = lib.any (system: stdenv.hostPlatform.system == system) (
67-
lib.mapAttrsToList (name: _: name) pcSystems
68-
);
63+
xenSystemsBuild = {
64+
i686-linux.target = "i386";
65+
x86_64-linux.target = "x86_64";
66+
};
67+
68+
inPCSystems = lib.any (system: stdenv.hostPlatform.system == system) (lib.attrNames pcSystems);
6969

7070
gnulib = fetchFromSavannah {
7171
repo = "gnulib";
@@ -88,6 +88,10 @@ let
8888
hash = "sha256-IoRiJHNQ58y0UhCAD0CrpFiI8Mz1upzAtyh5K4Njh/w=";
8989
};
9090
in
91+
92+
assert zfsSupport -> zfs != null;
93+
assert !(efiSupport && xenSupport);
94+
9195
stdenv.mkDerivation rec {
9296
pname = "grub";
9397
version = "2.12";
@@ -605,7 +609,7 @@ stdenv.mkDerivation rec {
605609
]
606610
++ lib.optionals xenSupport [
607611
"--with-platform=xen"
608-
"--target=${efiSystemsBuild.${stdenv.hostPlatform.system}.target}"
612+
"--target=${xenSystemsBuild.${stdenv.hostPlatform.system}.target}"
609613
];
610614

611615
# save target that grub is compiled for
@@ -653,16 +657,13 @@ stdenv.mkDerivation rec {
653657
license = licenses.gpl3Plus;
654658

655659
platforms =
656-
if xenSupport then
657-
[
658-
"x86_64-linux"
659-
"i686-linux"
660-
]
660+
if efiSupport then
661+
lib.attrNames efiSystemsBuild
662+
else if xenSupport then
663+
lib.attrNames xenSystemsBuild
661664
else
662665
platforms.gnu ++ platforms.linux;
663666

664667
maintainers = [ ];
665-
666-
broken = !(efiSupport -> canEfi) || !(zfsSupport -> zfs != null) || (efiSupport && xenSupport);
667668
};
668669
}

0 commit comments

Comments
 (0)