2023-09-02 14:54:37 +08:00
|
|
|
inputs:
|
|
|
|
{
|
|
|
|
options.nixos.system.grub = let inherit (inputs.lib) mkOption types; in
|
|
|
|
{
|
|
|
|
timeout = mkOption { type = types.int; default = 5; };
|
|
|
|
windowsEntries = mkOption { type = types.attrsOf types.nonEmptyStr; default = {}; };
|
|
|
|
# "efi" using efi, "efiRemovable" using efi with install grub removable, or dev path like "/dev/sda" using bios
|
|
|
|
installDevice = mkOption { type = types.str; };
|
|
|
|
};
|
2024-02-01 12:30:01 +08:00
|
|
|
config = let inherit (inputs.config.nixos.system) grub; in inputs.lib.mkMerge
|
|
|
|
[
|
|
|
|
# general settings
|
|
|
|
{ boot.loader.grub = { enable = true; useOSProber = false; }; }
|
|
|
|
# grub timeout
|
|
|
|
{ boot.loader.timeout = grub.timeout; }
|
|
|
|
# grub install
|
2023-09-02 14:54:37 +08:00
|
|
|
{
|
2024-02-01 12:30:01 +08:00
|
|
|
boot.loader =
|
2023-09-02 14:54:37 +08:00
|
|
|
{
|
2024-02-01 12:30:01 +08:00
|
|
|
grub =
|
|
|
|
{
|
|
|
|
device = if builtins.elem grub.installDevice [ "efi" "efiRemovable" ] then "nodev" else grub.installDevice;
|
|
|
|
efiSupport = builtins.elem grub.installDevice [ "efi" "efiRemovable" ];
|
|
|
|
efiInstallAsRemovable = grub.installDevice == "efiRemovable";
|
|
|
|
};
|
|
|
|
efi =
|
|
|
|
{
|
|
|
|
canTouchEfiVariables = grub.installDevice == "efi";
|
|
|
|
efiSysMountPoint = inputs.lib.mkIf (builtins.elem grub.installDevice [ "efi" "efiRemovable" ]) "/boot/efi";
|
|
|
|
};
|
2023-09-02 14:54:37 +08:00
|
|
|
};
|
2024-02-01 12:30:01 +08:00
|
|
|
}
|
|
|
|
# extra grub entries
|
|
|
|
{
|
|
|
|
boot.loader.grub =
|
2023-09-02 14:54:37 +08:00
|
|
|
{
|
2024-02-01 12:30:01 +08:00
|
|
|
memtest86.enable = true;
|
2024-02-01 12:38:52 +08:00
|
|
|
extraFiles = inputs.lib.mkIf (builtins.elem grub.installDevice [ "efi" "efiRemovable" ])
|
|
|
|
{ "shell.efi" = "${inputs.pkgs.edk2-uefi-shell}/shell.efi"; };
|
|
|
|
extraEntries = inputs.lib.mkMerge (builtins.concatLists
|
|
|
|
[
|
2024-02-01 12:30:01 +08:00
|
|
|
(builtins.map
|
|
|
|
(system:
|
|
|
|
''
|
|
|
|
menuentry "${system.value}" {
|
|
|
|
insmod part_gpt
|
|
|
|
insmod fat
|
|
|
|
insmod search_fs_uuid
|
|
|
|
insmod chain
|
|
|
|
search --fs-uuid --set=root ${system.name}
|
|
|
|
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
|
|
|
|
}
|
|
|
|
'')
|
|
|
|
(inputs.localLib.attrsToList grub.windowsEntries))
|
2024-02-01 12:38:52 +08:00
|
|
|
[
|
2024-02-01 12:30:01 +08:00
|
|
|
''
|
|
|
|
menuentry "System shutdown" {
|
|
|
|
echo "System shutting down..."
|
|
|
|
halt
|
|
|
|
}
|
|
|
|
menuentry "System restart" {
|
|
|
|
echo "System rebooting..."
|
|
|
|
reboot
|
|
|
|
}
|
|
|
|
''
|
|
|
|
(
|
|
|
|
inputs.lib.optionalString (builtins.elem grub.installDevice [ "efi" "efiRemovable" ])
|
|
|
|
''
|
|
|
|
menuentry 'UEFI Firmware Settings' --id 'uefi-firmware' {
|
|
|
|
fwsetup
|
|
|
|
}
|
2024-02-01 12:38:52 +08:00
|
|
|
menuentry "UEFI Shell" {
|
|
|
|
insmod fat
|
|
|
|
insmod chain
|
2024-02-04 11:37:36 +08:00
|
|
|
chainloader @bootRoot@/shell.efi
|
2024-02-01 12:38:52 +08:00
|
|
|
}
|
2024-02-01 12:30:01 +08:00
|
|
|
''
|
|
|
|
)
|
|
|
|
]
|
2024-02-01 12:38:52 +08:00
|
|
|
]);
|
2023-09-02 14:54:37 +08:00
|
|
|
};
|
2024-02-01 12:30:01 +08:00
|
|
|
}
|
|
|
|
];
|
2023-09-02 14:54:37 +08:00
|
|
|
}
|