2020-09-25 04:45:31 +00:00
|
|
|
import ./make-test-python.nix ({pkgs, lib, ...}:
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
|
|
|
# A filesystem image with a (presumably) bootable debian
|
|
|
|
debianImage = pkgs.vmTools.diskImageFuns.debian9i386 {
|
|
|
|
# os-prober cannot detect systems installed on disks without a partition table
|
|
|
|
# so we create the disk ourselves
|
|
|
|
createRootFS = with pkgs; ''
|
|
|
|
${parted}/bin/parted --script /dev/vda mklabel msdos
|
|
|
|
${parted}/sbin/parted --script /dev/vda -- mkpart primary ext2 1M -1s
|
|
|
|
mkdir /mnt
|
|
|
|
${e2fsprogs}/bin/mkfs.ext4 /dev/vda1
|
2020-11-24 20:58:05 +00:00
|
|
|
${util-linux}/bin/mount -t ext4 /dev/vda1 /mnt
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
if test -e /mnt/.debug; then
|
|
|
|
exec ${bash}/bin/sh
|
|
|
|
fi
|
|
|
|
touch /mnt/.debug
|
|
|
|
|
|
|
|
mkdir /mnt/proc /mnt/dev /mnt/sys
|
|
|
|
'';
|
|
|
|
extraPackages = [
|
|
|
|
# /etc/os-release
|
|
|
|
"base-files"
|
|
|
|
# make the disk bootable-looking
|
|
|
|
"grub2" "linux-image-686"
|
|
|
|
];
|
|
|
|
# install grub
|
|
|
|
postInstall = ''
|
|
|
|
ln -sf /proc/self/mounts > /etc/mtab
|
|
|
|
PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \
|
|
|
|
grub-install /dev/vda --force
|
|
|
|
PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \
|
|
|
|
update-grub
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# a part of the configuration of the test vm
|
|
|
|
simpleConfig = {
|
|
|
|
boot.loader.grub = {
|
|
|
|
enable = true;
|
|
|
|
useOSProber = true;
|
|
|
|
device = "/dev/vda";
|
|
|
|
# vda is a filesystem without partition table
|
|
|
|
forceInstall = true;
|
|
|
|
};
|
|
|
|
nix.binaryCaches = lib.mkForce [ ];
|
|
|
|
nix.extraOptions = ''
|
|
|
|
hashed-mirrors =
|
|
|
|
connect-timeout = 1
|
|
|
|
'';
|
|
|
|
# save some memory
|
|
|
|
documentation.enable = false;
|
|
|
|
};
|
|
|
|
# /etc/nixos/configuration.nix for the vm
|
|
|
|
configFile = pkgs.writeText "configuration.nix" ''
|
2021-12-19 01:06:50 +00:00
|
|
|
{config, pkgs, lib, ...}: ({
|
2020-04-24 23:36:52 +00:00
|
|
|
imports =
|
|
|
|
[ ./hardware-configuration.nix
|
|
|
|
<nixpkgs/nixos/modules/testing/test-instrumentation.nix>
|
|
|
|
];
|
2021-12-19 01:06:50 +00:00
|
|
|
} // lib.importJSON ${
|
2020-04-24 23:36:52 +00:00
|
|
|
pkgs.writeText "simpleConfig.json" (builtins.toJSON simpleConfig)
|
2021-12-06 16:07:01 +00:00
|
|
|
})
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
in {
|
|
|
|
name = "os-prober";
|
|
|
|
|
|
|
|
machine = { config, pkgs, ... }: (simpleConfig // {
|
|
|
|
imports = [ ../modules/profiles/installation-device.nix
|
|
|
|
../modules/profiles/base.nix ];
|
2020-09-25 04:45:31 +00:00
|
|
|
virtualisation.memorySize = 1300;
|
2021-05-03 20:48:10 +00:00
|
|
|
# To add the secondary disk:
|
|
|
|
virtualisation.qemu.options = [ "-drive index=2,file=${debianImage}/disk-image.qcow2,read-only,if=virtio" ];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# The test cannot access the network, so any packages
|
|
|
|
# nixos-rebuild needs must be included in the VM.
|
|
|
|
system.extraDependencies = with pkgs;
|
|
|
|
[ sudo
|
|
|
|
libxml2.bin
|
|
|
|
libxslt.bin
|
|
|
|
desktop-file-utils
|
|
|
|
docbook5
|
|
|
|
docbook_xsl_ns
|
|
|
|
unionfs-fuse
|
|
|
|
ntp
|
|
|
|
nixos-artwork.wallpapers.simple-dark-gray-bottom
|
|
|
|
perlPackages.XMLLibXML
|
|
|
|
perlPackages.ListCompare
|
|
|
|
shared-mime-info
|
|
|
|
texinfo
|
|
|
|
xorg.lndir
|
|
|
|
grub2
|
|
|
|
|
|
|
|
# add curl so that rather than seeing the test attempt to download
|
|
|
|
# curl's tarball, we see what it's trying to download
|
|
|
|
curl
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
testScript = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
machine.start()
|
|
|
|
machine.succeed("udevadm settle")
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
print(machine.succeed("lsblk"))
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# check that os-prober works standalone
|
2020-09-25 04:45:31 +00:00
|
|
|
machine.succeed(
|
|
|
|
"${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1"
|
|
|
|
)
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# rebuild and test that debian is available in the grub menu
|
2020-09-25 04:45:31 +00:00
|
|
|
machine.succeed("nixos-generate-config")
|
|
|
|
machine.copy_from_host(
|
2020-04-24 23:36:52 +00:00
|
|
|
"${configFile}",
|
2020-09-25 04:45:31 +00:00
|
|
|
"/etc/nixos/configuration.nix",
|
|
|
|
)
|
2021-12-19 01:06:50 +00:00
|
|
|
machine.succeed("nixos-rebuild boot --show-trace >&2")
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
machine.succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg")
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
})
|