2010-01-06 13:36:21 +00:00
|
|
|
{ pkgs, nixpkgs, system, ... }:
|
|
|
|
|
|
|
|
rec {
|
|
|
|
|
|
|
|
# Build the ISO. This is the regular installation CD but with test
|
|
|
|
# instrumentation.
|
|
|
|
iso =
|
|
|
|
(import ../lib/eval-config.nix {
|
|
|
|
inherit nixpkgs system;
|
|
|
|
modules =
|
2010-01-06 20:52:05 +00:00
|
|
|
[ ../modules/installer/cd-dvd/installation-cd-graphical.nix
|
2010-01-06 13:36:21 +00:00
|
|
|
../modules/testing/test-instrumentation.nix
|
|
|
|
{ key = "serial";
|
2010-01-06 16:46:21 +00:00
|
|
|
boot.loader.grub.timeout = pkgs.lib.mkOverride 0 {} 0;
|
2010-01-06 20:52:05 +00:00
|
|
|
|
2010-01-06 16:46:21 +00:00
|
|
|
# The test cannot access the network, so any sources we
|
|
|
|
# need must be included in the ISO.
|
2010-01-06 20:52:05 +00:00
|
|
|
isoImage.storeContents =
|
|
|
|
[ pkgs.hello.src
|
|
|
|
pkgs.glibcLocales
|
|
|
|
pkgs.sudo
|
|
|
|
pkgs.docbook5
|
|
|
|
];
|
2010-01-06 13:36:21 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}).config.system.build.isoImage;
|
|
|
|
|
2010-01-06 20:52:05 +00:00
|
|
|
# The configuration to install.
|
|
|
|
config = pkgs.writeText "configuration.nix"
|
|
|
|
''
|
|
|
|
{ config, pkgs, modulesPath, ... }:
|
|
|
|
|
|
|
|
{ require =
|
|
|
|
[ ./hardware.nix
|
|
|
|
"''${modulesPath}/testing/test-instrumentation.nix"
|
|
|
|
];
|
|
|
|
|
|
|
|
boot.loader.grub.version = 2;
|
|
|
|
boot.loader.grub.device = "/dev/vda";
|
|
|
|
boot.initrd.kernelModules = [ "ext3" ];
|
|
|
|
|
|
|
|
fileSystems =
|
|
|
|
[ { mountPoint = "/";
|
|
|
|
device = "/dev/disk/by-label/nixos";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
swapDevices =
|
|
|
|
[ { label = "swap"; } ];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2010-01-06 16:46:21 +00:00
|
|
|
# The test script boots the CD, installs NixOS on an empty hard
|
|
|
|
# disk, and then reboot from the hard disk.
|
2010-01-06 13:36:21 +00:00
|
|
|
testScript =
|
|
|
|
''
|
2010-01-06 14:37:23 +00:00
|
|
|
createDisk("harddisk", 4 * 1024);
|
2010-01-06 13:36:21 +00:00
|
|
|
|
|
|
|
my $machine = Machine->new({ hda => "harddisk", cdrom => glob("${iso}/iso/*.iso") });
|
|
|
|
|
|
|
|
$machine->mustSucceed("echo hello");
|
2010-01-06 14:37:23 +00:00
|
|
|
|
|
|
|
# Make sure that we get a login prompt etc.
|
|
|
|
$machine->waitForJob("tty1");
|
|
|
|
$machine->waitForJob("rogue");
|
|
|
|
$machine->waitForJob("nixos-manual");
|
|
|
|
|
2010-01-06 20:52:05 +00:00
|
|
|
# Make sure that we don't try to download anything.
|
|
|
|
$machine->stopJob("dhclient");
|
|
|
|
$machine->mustSucceed("rm /etc/resolv.conf");
|
|
|
|
|
2010-01-06 16:46:21 +00:00
|
|
|
# Test nix-env.
|
|
|
|
$machine->mustFail("hello");
|
|
|
|
$machine->mustSucceed("nix-env -i hello");
|
|
|
|
$machine->mustSucceed("hello") =~ /Hello, world/
|
|
|
|
or die "bad `hello' output";
|
|
|
|
|
2010-01-06 14:37:23 +00:00
|
|
|
# Partition the disk.
|
|
|
|
$machine->mustSucceed(
|
|
|
|
"parted /dev/vda mklabel msdos",
|
2010-01-06 20:52:05 +00:00
|
|
|
"parted /dev/vda -- mkpart primary linux-swap 1M 1024M",
|
|
|
|
"parted /dev/vda -- mkpart primary ext2 1024M -1s",
|
2010-01-06 14:37:23 +00:00
|
|
|
# It can take udev a moment to create /dev/vda*.
|
|
|
|
"udevadm settle",
|
|
|
|
"mkswap /dev/vda1 -L swap",
|
|
|
|
"swapon -L swap",
|
|
|
|
"mkfs.ext3 -L nixos /dev/vda2",
|
|
|
|
"mount LABEL=nixos /mnt",
|
|
|
|
);
|
|
|
|
|
2010-01-06 20:52:05 +00:00
|
|
|
# Create the NixOS configuration.
|
2010-01-06 16:46:21 +00:00
|
|
|
$machine->mustSucceed(
|
|
|
|
"mkdir -p /mnt/etc/nixos",
|
|
|
|
"nixos-hardware-scan > /mnt/etc/nixos/hardware.nix",
|
|
|
|
);
|
|
|
|
|
|
|
|
my $cfg = $machine->mustSucceed("cat /mnt/etc/nixos/hardware.nix");
|
2010-01-06 20:52:05 +00:00
|
|
|
print STDERR "Result of the hardware scan:\n$cfg\n";
|
|
|
|
|
|
|
|
$machine->copyFileFromHost("${config}", "/mnt/etc/nixos/configuration.nix");
|
2010-01-06 16:46:21 +00:00
|
|
|
|
2010-01-06 20:52:05 +00:00
|
|
|
# Perform the installation.
|
|
|
|
$machine->mustSucceed("nixos-install >&2");
|
|
|
|
|
2010-01-06 14:37:23 +00:00
|
|
|
$machine->shutdown;
|
2010-01-06 15:14:26 +00:00
|
|
|
|
|
|
|
# Now see if we can boot the installation.
|
|
|
|
my $machine = Machine->new({ hda => "harddisk" });
|
2010-01-06 20:52:05 +00:00
|
|
|
|
2010-01-06 15:14:26 +00:00
|
|
|
$machine->mustSucceed("echo hello");
|
2010-01-06 20:52:05 +00:00
|
|
|
|
2010-01-06 22:53:27 +00:00
|
|
|
$machine->mustSucceed("nix-env -i coreutils >&2");
|
2010-01-06 20:52:05 +00:00
|
|
|
$machine->mustSucceed("type -tP ls") =~ /profiles/
|
|
|
|
or die "nix-env failed";
|
|
|
|
|
2010-01-06 22:53:27 +00:00
|
|
|
$machine->mustSucceed("nixos-rebuild switch >&2");
|
2010-01-06 20:52:05 +00:00
|
|
|
|
2010-01-06 15:14:26 +00:00
|
|
|
$machine->shutdown;
|
2010-01-06 22:53:27 +00:00
|
|
|
|
|
|
|
# And just to be sure, check that the machine still boots after
|
|
|
|
# "nixos-rebuild switch".
|
|
|
|
my $machine = Machine->new({ hda => "harddisk" });
|
|
|
|
$machine->mustSucceed("echo hello");
|
|
|
|
$machine->shutdown;
|
2010-01-06 15:14:26 +00:00
|
|
|
'';
|
2010-01-06 16:46:21 +00:00
|
|
|
|
2010-01-06 13:36:21 +00:00
|
|
|
}
|