diff options
author | Symphorien Gibol <symphorien+git@xlumurb.eu> | 2019-06-09 19:05:30 +0200 |
---|---|---|
committer | Symphorien Gibol <symphorien+git@xlumurb.eu> | 2019-06-09 19:05:30 +0200 |
commit | 52184a7a624c3720a02661bbb12fbde208bc3cdb (patch) | |
tree | 214eb32845d45290beeb5c187208871577bd98e1 /nixos/tests/os-prober.nix | |
parent | 61f0936d1cd73760312712615233cd80195a9b47 (diff) | |
download | nixpkgs-52184a7a624c3720a02661bbb12fbde208bc3cdb.tar nixpkgs-52184a7a624c3720a02661bbb12fbde208bc3cdb.tar.gz nixpkgs-52184a7a624c3720a02661bbb12fbde208bc3cdb.tar.bz2 nixpkgs-52184a7a624c3720a02661bbb12fbde208bc3cdb.tar.lz nixpkgs-52184a7a624c3720a02661bbb12fbde208bc3cdb.tar.xz nixpkgs-52184a7a624c3720a02661bbb12fbde208bc3cdb.tar.zst nixpkgs-52184a7a624c3720a02661bbb12fbde208bc3cdb.zip |
nixos/tests: add a test for os-prober
Diffstat (limited to 'nixos/tests/os-prober.nix')
-rw-r--r-- | nixos/tests/os-prober.nix | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix new file mode 100644 index 00000000000..29a6fa7676c --- /dev/null +++ b/nixos/tests/os-prober.nix @@ -0,0 +1,125 @@ +import ./make-test.nix ({pkgs, lib}: +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 + ${utillinux}/bin/mount -t ext4 /dev/vda1 /mnt + + 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 + ''; + }; + + # options to add the disk to the test vim + QEMU_OPTS = "-drive index=2,file=${debianImage}/disk-image.qcow2,read-only,if=virtio"; + + # 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; + }; + fileSystems."/mnt" = { + device = "/dev/vdb1"; + options = [ "ro" ]; + }; + nix.binaryCaches = lib.mkForce [ ]; + nix.extraOptions = + '' + hashed-mirrors = + connect-timeout = 1 + ''; + services.udisks2.enable = lib.mkForce false; + }; + # /etc/nixos/configuration.nix for the vm + configFile = pkgs.writeText "configuration.nix" '' + {config, pkgs, ...}: ({ + imports = + [ ./hardware-configuration.nix + <nixpkgs/nixos/modules/testing/test-instrumentation.nix> + ]; + }// (builtins.fromJSON (builtins.readFile ${ + pkgs.writeText "simpleConfig.json" + (builtins.toJSON simpleConfig) + }))) + ''; +in { + name = "os-prober"; + + machine = { config, pkgs, ... }: (simpleConfig // { + imports = [ ../modules/profiles/installation-device.nix + ../modules/profiles/base.nix ]; + virtualisation.memorySize = 1024; + # 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 = '' + # hack to add the secondary disk + $machine->{startCommand} = "QEMU_OPTS=\"\$QEMU_OPTS \"${lib.escapeShellArg QEMU_OPTS} ".$machine->{startCommand}; + + $machine->start; + $machine->succeed("udevadm settle"); + $machine->waitForUnit("multi-user.target"); + + # check that os-prober works standalone + $machine->succeed("${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1"); + + # rebuild and test that debian is available in the grub menu + $machine->succeed("nixos-generate-config"); + $machine->copyFileFromHost( + "${configFile}", + "/etc/nixos/configuration.nix"); + $machine->succeed("nixos-rebuild boot >&2"); + + $machine->succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg"); + ''; +}) |