nixos-config/modules/system/boot/default.nix

87 lines
1.9 KiB
Nix
Raw Normal View History

2021-10-07 09:59:54 +02:00
{ pkgs, config, lib, modulesPath, ... }:
2021-10-05 23:45:02 +02:00
with lib;
let
cfg = config.eb.boot;
in
{
2021-10-05 23:45:02 +02:00
options.eb.boot = {
type = mkOption {
description = "Type of boot. Default bios.";
default = null;
type = types.enum [ "bios" "uefi" ];
};
qemu = mkEnableOption {
2021-10-05 23:45:02 +02:00
description = "Set to true if running in qemu";
};
grubInstallDevice = mkOption {
description = "The disk to install Grub to";
type = types.nullOr types.str;
default = null;
};
};
config = mkMerge [
{
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
swapDevices = [{ device = "/dev/disk/by-label/swap"; }];
}
(mkIf (cfg.type == "bios") {
boot.loader = {
grub = {
enable = true;
version = 2;
device = cfg.grubInstallDevice;
efiSupport = false;
useOSProber = true;
extraEntries = ''
menuentry "Reboot" {
reboot
}
menuentry "Power off" {
halt
}
'';
};
};
})
(mkIf (cfg.type == "uefi") {
boot.loader = {
systemd-boot = {
enable = true;
editor = false;
configurationLimit = 10;
};
efi.canTouchEfiVariables = true;
};
fileSystems."/boot" = {
device = "/dev/disk/by-label/boot";
fsType = "vfat";
};
})
(mkIf (cfg.qemu) {
2021-10-07 09:59:54 +02:00
boot.initrd = {
availableKernelModules = [ "virtio_net" "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_scsi" "9p" "9pnet_virtio" ];
kernelModules = [ "virtio_balloon" "virtio_console" "virtio_rng" ];
postDeviceCommands =
''
hwclock -s
2021-10-07 09:59:54 +02:00
'';
};
2021-10-05 23:45:02 +02:00
services.qemuGuest.enable = true;
services.spice-vdagentd.enable = true;
2021-10-05 23:45:02 +02:00
})
];
}