nixos/modules/boot/default.nix

85 lines
2.3 KiB
Nix
Raw Normal View History

2023-07-21 21:46:24 +08:00
inputs:
{
options.nixos.boot = let inherit (inputs.lib) mkOption types; in
{
grub =
{
timeout = mkOption { type = types.int; default = 5; };
2023-07-27 23:05:04 +08:00
windowsEntries = mkOption { type = types.attrsOf types.nonEmptyStr; default = {}; };
2023-08-22 16:53:33 +08:00
# "efi" using efi, "efiRemovable" using efi with install grub removable, or dev path like "/dev/sda" using bios
installDevice = mkOption { type = types.str; };
2023-07-21 21:46:24 +08:00
};
2023-08-01 13:05:10 +08:00
network.enable = mkOption { type = types.bool; default = false; };
2023-08-01 22:40:09 +08:00
sshd =
{
enable = mkOption { type = types.bool; default = false; };
hostKeys = mkOption { type = types.listOf types.nonEmptyStr; default = []; };
};
2023-07-21 21:46:24 +08:00
};
2023-07-26 23:36:12 +08:00
config =
let
inherit (inputs.lib) mkMerge mkIf;
2023-07-27 23:05:04 +08:00
inherit (inputs.localLib) mkConditional attrsToList stripeTabs;
2023-07-26 23:36:12 +08:00
inherit (inputs.config.nixos) boot;
2023-07-27 23:05:04 +08:00
inherit (builtins) concatStringsSep map;
2023-07-26 23:36:12 +08:00
in mkMerge
[
# generic
2023-07-22 14:06:41 +08:00
{
2023-07-26 23:36:12 +08:00
boot =
2023-07-21 21:46:24 +08:00
{
2023-07-26 23:36:12 +08:00
loader.grub = { enable = true; useOSProber = false; };
initrd.systemd.enable = true;
};
}
# grub.timeout
{ boot.loader.timeout = boot.grub.timeout; }
2023-07-27 23:05:04 +08:00
# grub.windowsEntries
{
boot.loader.grub.extraEntries = concatStringsSep "" (map (system: stripeTabs
''
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
}
'') (attrsToList boot.grub.windowsEntries));
}
2023-07-26 23:36:12 +08:00
# grub.installDevice
(
2023-08-22 16:53:33 +08:00
mkConditional (boot.grub.installDevice == "efi" || boot.grub.installDevice == "efiRemovable")
(
mkConditional (boot.grub.installDevice == "efi")
2023-07-26 23:36:12 +08:00
{
2023-08-22 16:53:33 +08:00
boot.loader =
{
efi = { canTouchEfiVariables = true; efiSysMountPoint = "/boot/efi"; };
grub = { device = "nodev"; efiSupport = true; };
};
}
{
boot.loader =
{
efi.efiSysMountPoint = "/boot/efi";
grub = { device = "nodev"; efiSupport = true; efiInstallAsRemovable = true; };
};
}
)
2023-07-26 23:36:12 +08:00
{ boot.loader.grub.device = boot.grub.installDevice; }
)
2023-08-01 13:05:10 +08:00
# network
(
2023-08-01 22:40:09 +08:00
mkIf boot.network.enable
{ boot = { initrd.network.enable = true; kernelParams = [ "ip=dhcp" ]; }; }
2023-08-01 13:05:10 +08:00
)
2023-08-01 02:05:48 +08:00
# sshd
(
2023-08-01 22:40:09 +08:00
mkIf boot.sshd.enable
{ boot.initrd.network.ssh = { enable = true; hostKeys = boot.sshd.hostKeys; };}
2023-08-01 02:05:48 +08:00
)
2023-07-26 23:36:12 +08:00
];
2023-07-21 22:02:48 +08:00
}