nixos/qemu-vm: expose installBootLoader as an option, assert when it's enabled without stc

We need stc to actually, well, install the bootloader.
This commit is contained in:
K900 2024-09-12 07:11:44 +03:00
parent 111ed8812c
commit 5cef278170

View file

@ -276,15 +276,7 @@ let
onlyNixStore = false;
label = rootFilesystemLabel;
partitionTableType = selectPartitionTableLayout { inherit (cfg) useDefaultFilesystems useEFIBoot; };
# Bootloader should be installed on the system image only if we are booting through bootloaders.
# Though, if a user is not using our default filesystems, it is possible to not have any ESP
# or a strange partition table that's incompatible with GRUB configuration.
# As a consequence, this may lead to disk image creation failures.
# To avoid this, we prefer to let the user find out about how to install the bootloader on its ESP/disk.
# Usually, this can be through building your own disk image.
# TODO: If a user is interested into a more fine grained heuristic for `installBootLoader`
# by examining the actual contents of `cfg.fileSystems`, please send a PR.
installBootLoader = cfg.useBootLoader && cfg.useDefaultFilesystems;
installBootLoader = cfg.installBootLoader;
touchEFIVars = cfg.useEFIBoot;
diskSize = "auto";
additionalSpace = "0M";
@ -840,6 +832,19 @@ in
'';
};
virtualisation.installBootLoader =
mkOption {
type = types.bool;
default = cfg.useBootLoader && cfg.useDefaultFilesystems;
defaultText = "cfg.useBootLoader && cfg.useDefaultFilesystems";
description = ''
Install boot loader to target image.
This is best-effort and may break with unconventional partition setups.
Use `virtualisation.useDefaultFilesystems` for a known-working configuration.
'';
};
virtualisation.useEFIBoot =
mkOption {
type = types.bool;
@ -999,6 +1004,13 @@ in
If you have a more advanced usecase, please open an issue or a pull request.
'';
}
{
assertion = cfg.installBootLoader -> config.system.switch.enable;
message = ''
`system.switch.enable` must be enabled for `virtualisation.installBootLoader` to work.
Please enable it in your configuration.
'';
}
];
warnings =