Skip to content

Instantly share code, notes, and snippets.

@samueldr
Created August 26, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueldr/63c54b1656401a0fcf59d0cbe1814a77 to your computer and use it in GitHub Desktop.
Save samueldr/63c54b1656401a0fcf59d0cbe1814a77 to your computer and use it in GitHub Desktop.
diff --git a/nixos/tests/installer-child.nix b/nixos/tests/installer-child.nix
index 80afafaae6d..0542fa52bf4 100644
--- a/nixos/tests/installer-child.nix
+++ b/nixos/tests/installer-child.nix
@@ -58,10 +58,19 @@ let
'';
- # The test script boots a NixOS VM, installs NixOS on an empty hard
- # disk, and then reboot from the hard disk. It's parameterized with
- # a test script fragment `createPartitions', which must create
- # partitions and filesystems.
+ # This test is derived from the basic configuration of the installer
+ # test.The test script boots a NixOS VM, installs NixOS on an empty hard
+ # disk. The NixOS configuration has two configurations.
+ #
+ # - Default configuration
+ # - Work configuration - This has an extra "/etc/gitconfig" file.
+ #
+ # Once the VM is setup,
+ # - reboot and verify that it has booted into default configuration.
+ # - Reboot into the "Work" configuration via grub.
+ # - Verify that we have booted into the "Work" configuration and that
+ # the extra config file is present.
+
testScriptFun = { bootLoader, createPartitions, grubVersion, grubDevice, grubUseEfi
, grubIdentifier, preBootCommands, extraConfig
}:
@@ -108,17 +117,41 @@ let
# Perform the installation.
$machine->succeed("nixos-install < /dev/null >&2");
- # This is handled as part of standard installer test
- # # Do it again to make sure it's idempotent.
- # $machine->succeed("nixos-install < /dev/null >&2");
-
- $machine->succeed("cat /mnt/boot/grub/grub.cfg >&2");
$machine->succeed("umount /mnt/boot || true");
$machine->succeed("umount /mnt");
$machine->succeed("sync");
$machine->shutdown;
+ # Reboot Machine
+ $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", name => "boot-after-install" });
+ $machine->waitForUnit("multi-user.target");
+
+ # Booted configuration name should be Default
+ $machine->succeed("cat /run/booted-system/configuration-name >&2");
+ $machine->succeed("cat /run/booted-system/configuration-name | grep Default");
+
+ # We should find **not** a file named /etc/gitconfig
+ $machine->fail("test -e /etc/gitconfig");
+
+ # Set grub to boot the second configuration
+ $machine->succeed("sudo grub-reboot 1");
+
+ $machine->shutdown;
+
+ # Reboot Machine
+ $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", name => "boot-after-install" });
+
+ $machine->waitForUnit("multi-user.target");
+ # Booted configuration name should be Work
+ $machine->succeed("cat /run/booted-system/configuration-name >&2");
+ $machine->succeed("cat /run/booted-system/configuration-name | grep Work");
+
+ # We should find a file named /etc/gitconfig
+ $machine->succeed("test -e /etc/gitconfig");
+
+ $machine->shutdown;
+
'';
@@ -226,21 +259,27 @@ in {
"mount LABEL=nixos /mnt",
);
'';
- extraConfig =
- ''
- nesting.clone = [
- {
- boot.loader.grub.configurationName = "Work";
-
- environment.etc = {
- "gitconfig".text = "
-[core]
- gitproxy = none for work.com
- ";
- };
- }
- ];
- '';
+ bootLoader = "grub";
+ grubVersion = 2;
+
+ # Set unique configuration names for the two configurations.
+ # Create an extra file for the "Work" configuration
+ extraConfig =
+ ''
+ boot.loader.grub.configurationName = "Default";
+ nesting.clone = [
+ {
+ boot.loader.grub.configurationName = lib.mkForce "Work";
+
+ environment.etc = {
+ "gitconfig".text = "
+ [core]
+ gitproxy = none for work.com
+ ";
+ };
+ }
+ ];
+ '';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment