Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions nixos/modules/system/boot/loader/grub/grub.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ let
let
efiSysMountPoint = if args.efiSysMountPoint == null then args.path else args.efiSysMountPoint;
efiSysMountPoint' = replaceStrings [ "/" ] [ "-" ] efiSysMountPoint;
writer =
if cfg.useInstallNg then
(pkgs.formats.json {}).generate "grub-config.json"
else
(s: pkgs.writeText "grub-config.xml" (builtins.toXML s));
in
pkgs.writeText "grub-config.xml" (builtins.toXML
writer
{ splashImage = f cfg.splashImage;
splashMode = f cfg.splashMode;
backgroundColor = f cfg.backgroundColor;
Expand All @@ -79,6 +84,7 @@ let
timeout = if config.boot.loader.timeout == null then -1 else config.boot.loader.timeout;
theme = f cfg.theme;
inherit efiSysMountPoint;
inherit (builtins) storeDir;
inherit (args) devices;
inherit (efi) canTouchEfiVariables;
inherit (cfg)
Expand All @@ -97,7 +103,7 @@ let
if lib.last (lib.splitString "." cfg.font) == "pf2"
then cfg.font
else "${convertedFont}");
});
};

bootDeviceCounters = foldr (device: attr: attr // { ${device} = (attr.${device} or 0) + 1; }) {}
(concatMap (args: args.devices) cfg.mirroredBoots);
Expand Down Expand Up @@ -694,6 +700,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.
'';
};
};

};
Expand Down Expand Up @@ -738,13 +752,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;

Expand Down
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ in {
grocy = handleTest ./grocy.nix {};
grow-partition = runTest ./grow-partition.nix;
grub = handleTest ./grub.nix {};
grub-ng = handleTest ./grub.nix { ng = true; };
guacamole-server = handleTest ./guacamole-server.nix {};
guix = handleTest ./guix {};
gvisor = handleTest ./gvisor.nix {};
Expand Down
4 changes: 3 additions & 1 deletion nixos/tests/grub.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ./make-test-python.nix ({ lib, ... }: {
import ./make-test-python.nix ({ lib, ng ? false, ... }: {
name = "grub";

meta = with lib.maintainers; {
Expand All @@ -13,6 +13,8 @@ import ./make-test-python.nix ({ lib, ... }: {
enable = true;
users.alice.password = "supersecret";

useInstallNg = ng;

# OCR is not accurate enough
extraConfig = "serial; terminal_output serial";
};
Expand Down
Loading