at 22.05-pre 3.7 kB view raw
1import ./make-test-python.nix ({pkgs, lib, ...}: 2let 3 # A filesystem image with a (presumably) bootable debian 4 debianImage = pkgs.vmTools.diskImageFuns.debian9i386 { 5 # os-prober cannot detect systems installed on disks without a partition table 6 # so we create the disk ourselves 7 createRootFS = with pkgs; '' 8 ${parted}/bin/parted --script /dev/vda mklabel msdos 9 ${parted}/sbin/parted --script /dev/vda -- mkpart primary ext2 1M -1s 10 mkdir /mnt 11 ${e2fsprogs}/bin/mkfs.ext4 /dev/vda1 12 ${util-linux}/bin/mount -t ext4 /dev/vda1 /mnt 13 14 if test -e /mnt/.debug; then 15 exec ${bash}/bin/sh 16 fi 17 touch /mnt/.debug 18 19 mkdir /mnt/proc /mnt/dev /mnt/sys 20 ''; 21 extraPackages = [ 22 # /etc/os-release 23 "base-files" 24 # make the disk bootable-looking 25 "grub2" "linux-image-686" 26 ]; 27 # install grub 28 postInstall = '' 29 ln -sf /proc/self/mounts > /etc/mtab 30 PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \ 31 grub-install /dev/vda --force 32 PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \ 33 update-grub 34 ''; 35 }; 36 37 # a part of the configuration of the test vm 38 simpleConfig = { 39 boot.loader.grub = { 40 enable = true; 41 useOSProber = true; 42 device = "/dev/vda"; 43 # vda is a filesystem without partition table 44 forceInstall = true; 45 }; 46 nix.binaryCaches = lib.mkForce [ ]; 47 nix.extraOptions = '' 48 hashed-mirrors = 49 connect-timeout = 1 50 ''; 51 # save some memory 52 documentation.enable = false; 53 }; 54 # /etc/nixos/configuration.nix for the vm 55 configFile = pkgs.writeText "configuration.nix" '' 56 {config, pkgs, ...}: ({ 57 imports = 58 [ ./hardware-configuration.nix 59 <nixpkgs/nixos/modules/testing/test-instrumentation.nix> 60 ]; 61 } // pkgs.lib.importJSON ${ 62 pkgs.writeText "simpleConfig.json" (builtins.toJSON simpleConfig) 63 }) 64 ''; 65in { 66 name = "os-prober"; 67 68 machine = { config, pkgs, ... }: (simpleConfig // { 69 imports = [ ../modules/profiles/installation-device.nix 70 ../modules/profiles/base.nix ]; 71 virtualisation.memorySize = 1300; 72 # To add the secondary disk: 73 virtualisation.qemu.options = [ "-drive index=2,file=${debianImage}/disk-image.qcow2,read-only,if=virtio" ]; 74 75 # The test cannot access the network, so any packages 76 # nixos-rebuild needs must be included in the VM. 77 system.extraDependencies = with pkgs; 78 [ sudo 79 libxml2.bin 80 libxslt.bin 81 desktop-file-utils 82 docbook5 83 docbook_xsl_ns 84 unionfs-fuse 85 ntp 86 nixos-artwork.wallpapers.simple-dark-gray-bottom 87 perlPackages.XMLLibXML 88 perlPackages.ListCompare 89 shared-mime-info 90 texinfo 91 xorg.lndir 92 grub2 93 94 # add curl so that rather than seeing the test attempt to download 95 # curl's tarball, we see what it's trying to download 96 curl 97 ]; 98 }); 99 100 testScript = '' 101 machine.start() 102 machine.succeed("udevadm settle") 103 machine.wait_for_unit("multi-user.target") 104 print(machine.succeed("lsblk")) 105 106 # check that os-prober works standalone 107 machine.succeed( 108 "${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1" 109 ) 110 111 # rebuild and test that debian is available in the grub menu 112 machine.succeed("nixos-generate-config") 113 machine.copy_from_host( 114 "${configFile}", 115 "/etc/nixos/configuration.nix", 116 ) 117 machine.succeed("nixos-rebuild boot >&2") 118 119 machine.succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg") 120 ''; 121})