diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 60762de76d33..e2c62cd306d1 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -204,6 +204,7 @@ in # openstack-image-userdata doesn't work in a sandbox as the simulated openstack instance needs network access #openstack-image-userdata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).userdata or {}; openstack-image-metadata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).metadata or {}; + os-prober = handleTestOn ["x86_64-linux"] ./os-prober.nix {}; osquery = handleTest ./osquery.nix {}; osrm-backend = handleTest ./osrm-backend.nix {}; ostree = handleTest ./ostree.nix {}; diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix new file mode 100644 index 000000000000..9cd9f4ecd150 --- /dev/null +++ b/nixos/tests/os-prober.nix @@ -0,0 +1,119 @@ +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 vm + 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; + }; + 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 + + ]; + } // (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"); + ''; +}) diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix index 371ab13c5281..335cab7c45e1 100644 --- a/pkgs/build-support/vm/default.nix +++ b/pkgs/build-support/vm/default.nix @@ -719,7 +719,7 @@ rec { { name, fullName, size ? 4096, urlPrefix , packagesList ? "", packagesLists ? [packagesList] , packages, extraPackages ? [], postInstall ? "" - , extraDebs ? [] + , extraDebs ? [], createRootFS ? defaultCreateRootFS , QEMU_OPTS ? "", memSize ? 512 }: let @@ -729,7 +729,7 @@ rec { }; in (fillDiskWithDebs { - inherit name fullName size postInstall QEMU_OPTS memSize; + inherit name fullName size postInstall createRootFS QEMU_OPTS memSize; debs = import expr {inherit fetchurl;} ++ extraDebs; }) // {inherit expr;}; diff --git a/pkgs/tools/misc/os-prober/default.nix b/pkgs/tools/misc/os-prober/default.nix index 78426329975c..d68ed9c5cd39 100644 --- a/pkgs/tools/misc/os-prober/default.nix +++ b/pkgs/tools/misc/os-prober/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, makeWrapper, +{ stdenv, fetchFromGitLab, makeWrapper, nixosTests, # optional dependencies, the command(s) they provide coreutils, # mktemp grub2, # grub-mount and grub-probe @@ -9,11 +9,14 @@ ntfs3g # ntfs3g }: stdenv.mkDerivation rec { - version = "1.76"; + version = "1.77"; pname = "os-prober"; - src = fetchurl { - url = "https://salsa.debian.org/philh/os-prober/-/archive/${version}/os-prober-${version}.tar.bz2"; - sha256 = "07rw3092pckh21vx6y4hzqcn3wn4cqmwxaaiq100lncnhmszg11g"; + src = fetchFromGitLab { + domain = "salsa.debian.org"; + owner = "installer-team"; + repo = pname; + rev = version; + sha256 = "05sji756xdl67pp2sf7rk0ih9h6f6kgk9nvxlyv1bzbmcizlh2d2"; }; buildInputs = [ makeWrapper ]; @@ -56,6 +59,9 @@ stdenv.mkDerivation rec { done; ''; + passthru.tests = { + os-prober = nixosTests.os-prober; + }; meta = with stdenv.lib; { description = "Utility to detect other OSs on a set of drives"; homepage = http://packages.debian.org/source/sid/os-prober;