diff --git a/nixos/lib/testing/nixos-test-base.nix b/nixos/lib/testing/nixos-test-base.nix index 65fe15c6162e..c8b15a0ecce4 100644 --- a/nixos/lib/testing/nixos-test-base.nix +++ b/nixos/lib/testing/nixos-test-base.nix @@ -23,10 +23,10 @@ in }; } ({ config, ... }: { - # Don't pull in switch-to-configuration by default, except when specialisations are involved. + # Don't pull in switch-to-configuration by default, except when specialisations or early boot shenanigans are involved. # This is mostly a Hydra optimization, so we don't rebuild all the tests every time switch-to-configuration-ng changes. key = "no-switch-to-configuration"; - system.switch.enable = mkDefault (config.isSpecialisation || config.specialisation != {}); + system.switch.enable = mkDefault (config.isSpecialisation || config.specialisation != {} || config.virtualisation.installBootLoader); }) ]; } diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 153dc877352a..b48f9e64c235 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -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 =