From 6490219605e9551a41f42e5e4a3a4481e44f8113 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Thu, 6 Jun 2024 21:46:36 +0200 Subject: [PATCH] nixos/grub: add option to use `install-grub-ng` --- .../modules/system/boot/loader/grub/grub.nix | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix index 9c36651d687470..4b36fa8504ed14 100644 --- a/nixos/modules/system/boot/loader/grub/grub.nix +++ b/nixos/modules/system/boot/loader/grub/grub.nix @@ -694,6 +694,14 @@ in ''; }; + useInstallNg = mkOption { + default = false; + type = types.bool; + description = '' + Whether to use `install-grub-ng`, an experimental rewrite of `install-grub` + in Rust, with the goal of replacing the original Perl script. + ''; + }; }; }; @@ -738,13 +746,23 @@ in XMLLibXML XMLSAX XMLSAXBase ListCompare JSON ]); - in pkgs.writeScript "install-grub.sh" ('' - #!${pkgs.runtimeShell} - set -e - ${optionalString cfg.enableCryptodisk "export GRUB_ENABLE_CRYPTODISK=y"} - '' + flip concatMapStrings cfg.mirroredBoots (args: '' - ${perl}/bin/perl ${install-grub-pl} ${grubConfig args} $@ - '') + cfg.extraInstallCommands); + ng = pkgs.install-grub-ng.override { + inherit (config.system.nixos) distroName; + }; + genRun = args: if cfg.useInstallNg then + "${lib.getExe ng} ${grubConfig args} $@\n" + else + "${lib.getExe perl} ${install-grub-pl} ${grubConfig args} $@\n"; + in + pkgs.writeScript "install-grub.sh" ( + '' + #!${pkgs.runtimeShell} + set -e + ${optionalString cfg.enableCryptodisk "export GRUB_ENABLE_CRYPTODISK=y"} + '' + + flip concatMapStrings cfg.mirroredBoots genRun + + cfg.extraInstallCommands + ); system.build.grub = grub;