at 23.11-beta 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 -O '^metadata_csum_seed' /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 bintools 80 brotli 81 brotli.dev 82 brotli.lib 83 desktop-file-utils 84 docbook5 85 docbook_xsl_ns 86 grub2 87 kbd 88 kbd.dev 89 kmod.dev 90 libarchive 91 libarchive.dev 92 libxml2.bin 93 libxslt.bin 94 nixos-artwork.wallpapers.simple-dark-gray-bottom 95 ntp 96 perlPackages.ListCompare 97 perlPackages.XMLLibXML 98 python3Minimal 99 shared-mime-info 100 stdenv 101 sudo 102 texinfo 103 unionfs-fuse 104 xorg.lndir 105 106 # add curl so that rather than seeing the test attempt to download 107 # curl's tarball, we see what it's trying to download 108 curl 109 ]; 110 }); 111 112 testScript = '' 113 machine.start() 114 machine.succeed("udevadm settle") 115 machine.wait_for_unit("multi-user.target") 116 print(machine.succeed("lsblk")) 117 118 # check that os-prober works standalone 119 machine.succeed( 120 "${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1" 121 ) 122 123 # rebuild and test that debian is available in the grub menu 124 machine.succeed("nixos-generate-config") 125 machine.copy_from_host( 126 "${configFile}", 127 "/etc/nixos/configuration.nix", 128 ) 129 machine.succeed("nixos-rebuild boot --show-trace >&2") 130 131 machine.succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg") 132 ''; 133})