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