2020-03-29 13:00:00 +01:00
|
|
|
import ./make-test-python.nix ({pkgs, lib, ...}:
|
2019-06-09 18:05:30 +01:00
|
|
|
let
|
|
|
|
# A filesystem image with a (presumably) bootable debian
|
2022-11-26 20:53:24 +00:00
|
|
|
debianImage = pkgs.vmTools.diskImageFuns.debian11i386 {
|
2019-06-09 18:05:30 +01:00
|
|
|
# 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
|
2023-06-11 20:13:48 +01:00
|
|
|
${e2fsprogs}/bin/mkfs.ext4 -O '^metadata_csum_seed' /dev/vda1
|
2020-11-24 15:29:28 +00:00
|
|
|
${util-linux}/bin/mount -t ext4 /dev/vda1 /mnt
|
2019-06-09 18:05:30 +01: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;
|
|
|
|
};
|
2021-11-19 22:36:26 +00:00
|
|
|
nix.settings = {
|
|
|
|
substituters = lib.mkForce [];
|
|
|
|
hashed-mirrors = null;
|
|
|
|
connect-timeout = 1;
|
|
|
|
};
|
2020-03-29 13:00:00 +01:00
|
|
|
# save some memory
|
|
|
|
documentation.enable = false;
|
2019-06-09 18:05:30 +01:00
|
|
|
};
|
|
|
|
# /etc/nixos/configuration.nix for the vm
|
|
|
|
configFile = pkgs.writeText "configuration.nix" ''
|
2021-12-09 12:00:00 +00:00
|
|
|
{config, pkgs, lib, ...}: ({
|
2018-10-27 15:08:17 +01:00
|
|
|
imports =
|
2019-06-09 18:05:30 +01:00
|
|
|
[ ./hardware-configuration.nix
|
|
|
|
<nixpkgs/nixos/modules/testing/test-instrumentation.nix>
|
|
|
|
];
|
2021-12-09 12:00:00 +00:00
|
|
|
} // lib.importJSON ${
|
2019-06-09 20:16:53 +01:00
|
|
|
pkgs.writeText "simpleConfig.json" (builtins.toJSON simpleConfig)
|
2021-11-03 12:43:23 +00:00
|
|
|
})
|
2019-06-09 18:05:30 +01:00
|
|
|
'';
|
|
|
|
in {
|
|
|
|
name = "os-prober";
|
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = { config, pkgs, ... }: (simpleConfig // {
|
2019-06-09 20:16:53 +01:00
|
|
|
imports = [ ../modules/profiles/installation-device.nix
|
|
|
|
../modules/profiles/base.nix ];
|
2020-03-29 13:00:00 +01:00
|
|
|
virtualisation.memorySize = 1300;
|
2021-05-01 19:15:42 +01:00
|
|
|
# To add the secondary disk:
|
|
|
|
virtualisation.qemu.options = [ "-drive index=2,file=${debianImage}/disk-image.qcow2,read-only,if=virtio" ];
|
|
|
|
|
2019-06-09 18:05:30 +01:00
|
|
|
# The test cannot access the network, so any packages
|
|
|
|
# nixos-rebuild needs must be included in the VM.
|
|
|
|
system.extraDependencies = with pkgs;
|
2022-05-21 13:00:00 +01:00
|
|
|
[
|
2023-08-23 14:50:44 +01:00
|
|
|
bintools
|
2022-05-21 13:00:00 +01:00
|
|
|
brotli
|
|
|
|
brotli.dev
|
|
|
|
brotli.lib
|
2019-06-09 18:05:30 +01:00
|
|
|
desktop-file-utils
|
|
|
|
docbook5
|
|
|
|
docbook_xsl_ns
|
2022-05-21 13:00:00 +01:00
|
|
|
grub2
|
2023-06-20 11:20:37 +01:00
|
|
|
kbd
|
|
|
|
kbd.dev
|
2022-05-21 13:00:00 +01:00
|
|
|
kmod.dev
|
|
|
|
libarchive
|
|
|
|
libarchive.dev
|
|
|
|
libxml2.bin
|
|
|
|
libxslt.bin
|
2019-06-09 18:05:30 +01:00
|
|
|
nixos-artwork.wallpapers.simple-dark-gray-bottom
|
2022-05-21 13:00:00 +01:00
|
|
|
ntp
|
2019-06-09 18:05:30 +01:00
|
|
|
perlPackages.ListCompare
|
2022-05-21 13:00:00 +01:00
|
|
|
perlPackages.XMLLibXML
|
|
|
|
python3Minimal
|
2019-06-09 18:05:30 +01:00
|
|
|
shared-mime-info
|
2022-05-21 13:00:00 +01:00
|
|
|
stdenv
|
|
|
|
sudo
|
2019-06-09 18:05:30 +01:00
|
|
|
texinfo
|
2022-05-21 13:00:00 +01:00
|
|
|
unionfs-fuse
|
2019-06-09 18:05:30 +01:00
|
|
|
xorg.lndir
|
|
|
|
|
|
|
|
# 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-03-29 13:00:00 +01:00
|
|
|
machine.start()
|
|
|
|
machine.succeed("udevadm settle")
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
print(machine.succeed("lsblk"))
|
2019-06-09 18:05:30 +01:00
|
|
|
|
|
|
|
# check that os-prober works standalone
|
2020-03-29 13:00:00 +01:00
|
|
|
machine.succeed(
|
|
|
|
"${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1"
|
|
|
|
)
|
2019-06-09 18:05:30 +01:00
|
|
|
|
|
|
|
# rebuild and test that debian is available in the grub menu
|
2020-03-29 13:00:00 +01:00
|
|
|
machine.succeed("nixos-generate-config")
|
|
|
|
machine.copy_from_host(
|
2019-06-09 18:05:30 +01:00
|
|
|
"${configFile}",
|
2020-03-29 13:00:00 +01:00
|
|
|
"/etc/nixos/configuration.nix",
|
|
|
|
)
|
2021-12-09 12:00:00 +00:00
|
|
|
machine.succeed("nixos-rebuild boot --show-trace >&2")
|
2019-06-09 18:05:30 +01:00
|
|
|
|
2020-03-29 13:00:00 +01:00
|
|
|
machine.succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg")
|
2019-06-09 18:05:30 +01:00
|
|
|
'';
|
|
|
|
})
|