From 52184a7a624c3720a02661bbb12fbde208bc3cdb Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Sun, 9 Jun 2019 19:05:30 +0200 Subject: [PATCH 1/8] nixos/tests: add a test for os-prober --- nixos/tests/os-prober.nix | 125 ++++++++++++++++++++++++++++++ pkgs/build-support/vm/default.nix | 4 +- 2 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 nixos/tests/os-prober.nix diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix new file mode 100644 index 00000000000..29a6fa7676c --- /dev/null +++ b/nixos/tests/os-prober.nix @@ -0,0 +1,125 @@ +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 vim + 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; + }; + fileSystems."/mnt" = { + device = "/dev/vdb1"; + options = [ "ro" ]; + }; + 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 5d04302591e..10367957915 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;}; From 5c9634099d697eb78ef40f3825c875a09904fef1 Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Sun, 9 Jun 2019 20:02:40 +0200 Subject: [PATCH 2/8] os-prober: 1.76 -> 1.77 --- pkgs/tools/misc/os-prober/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/tools/misc/os-prober/default.nix b/pkgs/tools/misc/os-prober/default.nix index 59a60e356b8..21c434bb5a3 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, # 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"; - name = "os-prober-${version}"; - src = fetchurl { - url = "https://salsa.debian.org/philh/os-prober/-/archive/${version}/os-prober-${version}.tar.bz2"; - sha256 = "07rw3092pckh21vx6y4hzqcn3wn4cqmwxaaiq100lncnhmszg11g"; + version = "1.77"; + pname = "os-prober"; + src = fetchFromGitLab { + domain = "salsa.debian.org"; + owner = "installer-team"; + repo = pname; + rev = version; + sha256 = "05sji756xdl67pp2sf7rk0ih9h6f6kgk9nvxlyv1bzbmcizlh2d2"; }; buildInputs = [ makeWrapper ]; From 9e06a61cf09ce94404fae78fc62b773ddf6448ee Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Sun, 9 Jun 2019 20:26:05 +0200 Subject: [PATCH 3/8] mention the os-prober test in pkgs.os-prober.passthru.tests --- nixos/tests/all-tests.nix | 1 + nixos/tests/os-prober.nix | 2 +- pkgs/tools/misc/os-prober/default.nix | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 9bce49c9e30..20736d030e8 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -183,6 +183,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 index 29a6fa7676c..d166bfc8113 100644 --- a/nixos/tests/os-prober.nix +++ b/nixos/tests/os-prober.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({pkgs, lib}: +import ./make-test.nix ({pkgs, lib, ...}: let # A filesystem image with a (presumably) bootable debian debianImage = pkgs.vmTools.diskImageFuns.debian9i386 { diff --git a/pkgs/tools/misc/os-prober/default.nix b/pkgs/tools/misc/os-prober/default.nix index 21c434bb5a3..d68ed9c5cd3 100644 --- a/pkgs/tools/misc/os-prober/default.nix +++ b/pkgs/tools/misc/os-prober/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchFromGitLab, makeWrapper, +{ stdenv, fetchFromGitLab, makeWrapper, nixosTests, # optional dependencies, the command(s) they provide coreutils, # mktemp grub2, # grub-mount and grub-probe @@ -59,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; From f452d640f03de5246c2a0316c842b17ebac84472 Mon Sep 17 00:00:00 2001 From: symphorien Date: Sun, 9 Jun 2019 19:11:47 +0000 Subject: [PATCH 4/8] nixos/tests/os-prober.nix: apply review suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Léo Gaspard --- nixos/tests/os-prober.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix index d166bfc8113..b6acc499173 100644 --- a/nixos/tests/os-prober.nix +++ b/nixos/tests/os-prober.nix @@ -56,7 +56,7 @@ let hashed-mirrors = connect-timeout = 1 ''; - services.udisks2.enable = lib.mkForce false; + services.udisks2.enable = lib.mkForce false; }; # /etc/nixos/configuration.nix for the vm configFile = pkgs.writeText "configuration.nix" '' From 04c9866b6e29428ca3710523e04b420a72eea192 Mon Sep 17 00:00:00 2001 From: symphorien Date: Sun, 9 Jun 2019 19:12:07 +0000 Subject: [PATCH 5/8] nixos/tests/os-prober.nix: apply review suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Léo Gaspard --- nixos/tests/os-prober.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix index b6acc499173..2cfb3f5f690 100644 --- a/nixos/tests/os-prober.nix +++ b/nixos/tests/os-prober.nix @@ -65,7 +65,7 @@ let [ ./hardware-configuration.nix ]; - }// (builtins.fromJSON (builtins.readFile ${ + } // (builtins.fromJSON (builtins.readFile ${ pkgs.writeText "simpleConfig.json" (builtins.toJSON simpleConfig) }))) From 9a69fab1e315f05975a2cc0c573f1ee55258cde4 Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Sun, 9 Jun 2019 21:16:53 +0200 Subject: [PATCH 6/8] nixos/tests/os-prober.nix: apply review suggestions --- nixos/tests/os-prober.nix | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix index 2cfb3f5f690..eb62dd76312 100644 --- a/nixos/tests/os-prober.nix +++ b/nixos/tests/os-prober.nix @@ -51,11 +51,10 @@ let options = [ "ro" ]; }; nix.binaryCaches = lib.mkForce [ ]; - nix.extraOptions = - '' + nix.extraOptions = '' hashed-mirrors = connect-timeout = 1 - ''; + ''; services.udisks2.enable = lib.mkForce false; }; # /etc/nixos/configuration.nix for the vm @@ -66,16 +65,15 @@ let ]; } // (builtins.fromJSON (builtins.readFile ${ - pkgs.writeText "simpleConfig.json" - (builtins.toJSON simpleConfig) + 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 ]; + 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. From d1ac443ccaf2d5ee9bd4bc0a7155290bd8bba99f Mon Sep 17 00:00:00 2001 From: symphorien Date: Sun, 9 Jun 2019 19:18:30 +0000 Subject: [PATCH 7/8] nixos/tests/os-prober.nix: fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Léo Gaspard --- nixos/tests/os-prober.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix index eb62dd76312..a386a5d43bc 100644 --- a/nixos/tests/os-prober.nix +++ b/nixos/tests/os-prober.nix @@ -34,7 +34,7 @@ let ''; }; - # options to add the disk to the test vim + # 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 From 4cab05598c731b718513ae4e0a73026c42063e8a Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Sun, 21 Jul 2019 15:13:48 +0200 Subject: [PATCH 8/8] os-prober.tests: make the test stricter os-prober should be able to probe unmounted filesystems --- nixos/tests/os-prober.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nixos/tests/os-prober.nix b/nixos/tests/os-prober.nix index a386a5d43bc..9cd9f4ecd15 100644 --- a/nixos/tests/os-prober.nix +++ b/nixos/tests/os-prober.nix @@ -46,10 +46,6 @@ let # vda is a filesystem without partition table forceInstall = true; }; - fileSystems."/mnt" = { - device = "/dev/vdb1"; - options = [ "ro" ]; - }; nix.binaryCaches = lib.mkForce [ ]; nix.extraOptions = '' hashed-mirrors =