at 23.11-pre 3.9 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.debian11i386 { 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.settings = { 47 substituters = lib.mkForce []; 48 hashed-mirrors = null; 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, lib, ...}: ({ 57 imports = 58 [ ./hardware-configuration.nix 59 <nixpkgs/nixos/modules/testing/test-instrumentation.nix> 60 ]; 61 } // lib.importJSON ${ 62 pkgs.writeText "simpleConfig.json" (builtins.toJSON simpleConfig) 63 }) 64 ''; 65in { 66 name = "os-prober"; 67 68 nodes.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 [ 79 brotli 80 brotli.dev 81 brotli.lib 82 desktop-file-utils 83 docbook5 84 docbook_xsl_ns 85 grub2 86 kmod.dev 87 libarchive 88 libarchive.dev 89 libxml2.bin 90 libxslt.bin 91 nixos-artwork.wallpapers.simple-dark-gray-bottom 92 ntp 93 perlPackages.ListCompare 94 perlPackages.XMLLibXML 95 python3Minimal 96 shared-mime-info 97 stdenv 98 sudo 99 texinfo 100 unionfs-fuse 101 xorg.lndir 102 103 # add curl so that rather than seeing the test attempt to download 104 # curl's tarball, we see what it's trying to download 105 curl 106 ]; 107 }); 108 109 testScript = '' 110 machine.start() 111 machine.succeed("udevadm settle") 112 machine.wait_for_unit("multi-user.target") 113 print(machine.succeed("lsblk")) 114 115 # check that os-prober works standalone 116 machine.succeed( 117 "${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1" 118 ) 119 120 # rebuild and test that debian is available in the grub menu 121 machine.succeed("nixos-generate-config") 122 machine.copy_from_host( 123 "${configFile}", 124 "/etc/nixos/configuration.nix", 125 ) 126 machine.succeed("nixos-rebuild boot --show-trace >&2") 127 128 machine.succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg") 129 ''; 130})