···11+import ./make-test-python.nix ({ pkgs, ... }: {
22+ name = "nixos-rebuild-install-bootloader";
33+44+ nodes = {
55+ machine = { lib, pkgs, ... }: {
66+ imports = [
77+ ../modules/profiles/installation-device.nix
88+ ../modules/profiles/base.nix
99+ ];
1010+1111+ nix.settings = {
1212+ substituters = lib.mkForce [ ];
1313+ hashed-mirrors = null;
1414+ connect-timeout = 1;
1515+ };
1616+1717+ system.includeBuildDependencies = true;
1818+1919+ virtualisation = {
2020+ cores = 2;
2121+ memorySize = 2048;
2222+ };
2323+2424+ virtualisation.useBootLoader = true;
2525+ };
2626+ };
2727+2828+ testScript =
2929+ let
3030+ configFile = pkgs.writeText "configuration.nix" ''
3131+ { lib, pkgs, ... }: {
3232+ imports = [
3333+ ./hardware-configuration.nix
3434+ <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
3535+ ];
3636+3737+ boot.loader.grub = {
3838+ enable = true;
3939+ device = "/dev/vda";
4040+ forceInstall = true;
4141+ };
4242+4343+ documentation.enable = false;
4444+ }
4545+ '';
4646+4747+ in
4848+ ''
4949+ machine.start()
5050+ machine.succeed("udevadm settle")
5151+ machine.wait_for_unit("multi-user.target")
5252+5353+ machine.succeed("nixos-generate-config")
5454+ machine.copy_from_host(
5555+ "${configFile}",
5656+ "/etc/nixos/configuration.nix",
5757+ )
5858+ machine.succeed("nixos-rebuild switch")
5959+6060+ # Need to run `nixos-rebuild` twice because the first run will install
6161+ # GRUB anyway
6262+ with subtest("Switch system again and install bootloader"):
6363+ result = machine.succeed("nixos-rebuild switch --install-bootloader")
6464+ # install-grub2.pl messages
6565+ assert "updating GRUB 2 menu..." in result
6666+ assert "installing the GRUB 2 boot loader on /dev/vda..." in result
6767+ # GRUB message
6868+ assert "Installation finished. No error reported." in result
6969+ # at this point we've tested regression #262724, but haven't tested the bootloader itself
7070+ # TODO: figure out how to how to tell the test driver to start the bootloader instead of
7171+ # booting into the kernel directly.
7272+ '';
7373+})
+1
pkgs/os-specific/linux/nixos-rebuild/default.nix
···32323333 # run some a simple installer tests to make sure nixos-rebuild still works for them
3434 passthru.tests = {
3535+ install-bootloader = nixosTests.nixos-rebuild-install-bootloader;
3536 simple-installer = nixosTests.installer.simple;
3637 specialisations = nixosTests.nixos-rebuild-specialisations;
3738 };