From e79eed4840f9064c50259143b722c603d8006f84 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 5 Oct 2020 15:36:37 +0200 Subject: [PATCH 1/9] qemu: strip down the features for the test runner This allows much faster VM-test based systemd testing as the closure of qemu suddenly shrinks to reasonable sizes again. --- pkgs/applications/virtualization/qemu/default.nix | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/virtualization/qemu/default.nix b/pkgs/applications/virtualization/qemu/default.nix index 535f8371153..f019bf46583 100644 --- a/pkgs/applications/virtualization/qemu/default.nix +++ b/pkgs/applications/virtualization/qemu/default.nix @@ -6,12 +6,13 @@ , CoreServices, Cocoa, Hypervisor, rez, setfile , numaSupport ? stdenv.isLinux && !stdenv.isAarch32, numactl , seccompSupport ? stdenv.isLinux, libseccomp -, pulseSupport ? !stdenv.isDarwin, libpulseaudio -, sdlSupport ? !stdenv.isDarwin, SDL2 -, gtkSupport ? !stdenv.isDarwin && !xenSupport, gtk3, gettext, vte, wrapGAppsHook -, vncSupport ? true, libjpeg, libpng -, smartcardSupport ? true, libcacard -, spiceSupport ? !stdenv.isDarwin, spice, spice-protocol +, alsaSupport ? stdenv.lib.hasSuffix "linux" stdenv.hostPlatform.system && !nixosTestRunner +, pulseSupport ? !stdenv.isDarwin && !nixosTestRunner, libpulseaudio +, sdlSupport ? !stdenv.isDarwin && !nixosTestRunner, SDL2 +, gtkSupport ? !stdenv.isDarwin && !xenSupport && !nixosTestRunner, gtk3, gettext, vte, wrapGAppsHook +, vncSupport ? !nixosTestRunner, libjpeg, libpng +, smartcardSupport ? !nixosTestRunner, libcacard +, spiceSupport ? !stdenv.isDarwin && !nixosTestRunner, spice, spice-protocol , usbredirSupport ? spiceSupport, usbredir , xenSupport ? false, xen , cephSupport ? false, ceph @@ -29,7 +30,7 @@ with stdenv.lib; let - audio = optionalString (hasSuffix "linux" stdenv.hostPlatform.system) "alsa," + audio = optionalString alsaSupport "alsa," + optionalString pulseSupport "pa," + optionalString sdlSupport "sdl,"; From c096880d46115c43ea254efc52de32dc3fe58913 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 5 Oct 2020 15:52:27 +0200 Subject: [PATCH 2/9] nixos/tests: make the `driver` attribute use a rich qemu Since we previously stripped down the features of `qemu_test` some of the features users are used to while running tests through the (impure) driver didn't work anymore. Most notably we lost support for graphical output and audio. With this change the `driver` attribute uses are more feature complete version of QEmu compared to the one used in the pure Nix builds. This gives us the best of both worlds. Users are able to see the graphical windows of VMs while CI and regular nix builds do not have to download all the (unnecessary) dependencies. --- nixos/lib/testing-python.nix | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index 498f97336c0..69cad8cdceb 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -17,9 +17,9 @@ rec { inherit pkgs; - testDriver = let + mkTestDriver = let testDriverScript = ./test-driver/test-driver.py; - in stdenv.mkDerivation { + in qemu_pkg: stdenv.mkDerivation { name = "nixos-test-driver"; nativeBuildInputs = [ makeWrapper ]; @@ -47,10 +47,12 @@ rec { # TODO: copy user script part into this file (append) wrapProgram $out/bin/nixos-test-driver \ - --prefix PATH : "${lib.makeBinPath [ qemu_test vde2 netpbm coreutils ]}" \ + --prefix PATH : "${lib.makeBinPath [ qemu_pkg vde2 netpbm coreutils ]}" \ ''; }; + testDriver = mkTestDriver qemu_test; + testDriverInteractive = mkTestDriver qemu_kvm; # Run an automated test suite in the given virtual network. # `driver' is the script that runs the network. @@ -113,7 +115,11 @@ rec { # Generate convenience wrappers for running the test driver # interactively with the specified network, and for starting the # VMs from the command line. - driver = let warn = if skipLint then lib.warn "Linting is disabled!" else lib.id; in warn (runCommand testDriverName + driver = testDriver: + let + warn = if skipLint then lib.warn "Linting is disabled!" else lib.id; + in + warn (runCommand testDriverName { buildInputs = [ makeWrapper]; testScript = testScript'; preferLocalBuild = true; @@ -148,7 +154,7 @@ rec { meta = (drv.meta or {}) // t.meta; }; - test = passMeta (runTests driver); + test = passMeta (runTests (driver testDriver)); nodeNames = builtins.attrNames nodes; invalidNodeNames = lib.filter @@ -165,7 +171,8 @@ rec { '' else test // { - inherit nodes driver test; + inherit nodes test; + driver = driver testDriverInteractive; }; runInMachine = From 20893b3a700a5818aa4769b1c00c1a99c171af02 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 19 Oct 2020 17:20:27 +0200 Subject: [PATCH 3/9] nixos/tests: expose both the interactive and non-interactive driver For a lot of the work the non-interactive drivers are enough and it is probably a good idea to keep it accessible for debugging without touching the Nix expression. --- .../manual/development/running-nixos-tests-interactively.xml | 4 ++-- nixos/lib/testing-python.nix | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/nixos/doc/manual/development/running-nixos-tests-interactively.xml b/nixos/doc/manual/development/running-nixos-tests-interactively.xml index a11a9382764..a6044d5f89e 100644 --- a/nixos/doc/manual/development/running-nixos-tests-interactively.xml +++ b/nixos/doc/manual/development/running-nixos-tests-interactively.xml @@ -9,7 +9,7 @@ The test itself can be run interactively. This is particularly useful when developing or debugging a test: -$ nix-build nixos/tests/login.nix -A driver +$ nix-build nixos/tests/login.nix -A driverInteractive $ ./result/bin/nixos-test-driver starting VDE switch for network 1 > @@ -30,7 +30,7 @@ starting VDE switch for network 1 To just start and experiment with the VMs, run: -$ nix-build nixos/tests/login.nix -A driver +$ nix-build nixos/tests/login.nix -A driverInteractive $ ./result/bin/nixos-run-vms The script nixos-run-vms starts the virtual machines diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index 69cad8cdceb..302c7f78bf8 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -172,7 +172,8 @@ rec { else test // { inherit nodes test; - driver = driver testDriverInteractive; + driver = driver testDriver; + driverInteractive = driver testDriverInteractive; }; runInMachine = From 2451796b49a6b1b46d02e9c40ecf9de8acaba7b2 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 19 Oct 2020 17:49:31 +0200 Subject: [PATCH 4/9] qemu: make ncurses optional for the test runner This shaves another 3MB off the closure size of QEMU. --- pkgs/applications/virtualization/qemu/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/virtualization/qemu/default.nix b/pkgs/applications/virtualization/qemu/default.nix index f019bf46583..3c867205799 100644 --- a/pkgs/applications/virtualization/qemu/default.nix +++ b/pkgs/applications/virtualization/qemu/default.nix @@ -1,5 +1,5 @@ { stdenv, fetchurl, fetchpatch, python, zlib, pkgconfig, glib -, ncurses, perl, pixman, vde2, alsaLib, texinfo, flex +, perl, pixman, vde2, alsaLib, texinfo, flex , bison, lzo, snappy, libaio, gnutls, nettle, curl , makeWrapper , attr, libcap, libcap_ng @@ -13,6 +13,7 @@ , vncSupport ? !nixosTestRunner, libjpeg, libpng , smartcardSupport ? !nixosTestRunner, libcacard , spiceSupport ? !stdenv.isDarwin && !nixosTestRunner, spice, spice-protocol +, ncursesSupport ? !nixosTestRunner, ncurses , usbredirSupport ? spiceSupport, usbredir , xenSupport ? false, xen , cephSupport ? false, ceph @@ -51,10 +52,11 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ python python.pkgs.sphinx pkgconfig flex bison ] ++ optionals gtkSupport [ wrapGAppsHook ]; buildInputs = - [ zlib glib ncurses perl pixman + [ zlib glib perl pixman vde2 texinfo makeWrapper lzo snappy gnutls nettle curl ] + ++ optionals ncursesSupport [ ncurses ] ++ optionals stdenv.isDarwin [ CoreServices Cocoa Hypervisor rez setfile ] ++ optionals seccompSupport [ libseccomp ] ++ optionals numaSupport [ numactl ] From e127ba7873cf3979da00cbc691155c0a87ecfc36 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 19 Oct 2020 17:58:10 +0200 Subject: [PATCH 5/9] nixos/qemu-guest-agent: make the QEMU guest agent package configurable --- nixos/modules/virtualisation/qemu-guest-agent.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/qemu-guest-agent.nix b/nixos/modules/virtualisation/qemu-guest-agent.nix index 665224e35d8..6a735f451a7 100644 --- a/nixos/modules/virtualisation/qemu-guest-agent.nix +++ b/nixos/modules/virtualisation/qemu-guest-agent.nix @@ -12,6 +12,11 @@ in { default = false; description = "Whether to enable the qemu guest agent."; }; + package = mkOption { + type = types.package; + default = pkgs.qemu.ga; + description = "The QEMU guest agent package."; + }; }; config = mkIf cfg.enable ( @@ -25,7 +30,7 @@ in { systemd.services.qemu-guest-agent = { description = "Run the QEMU Guest Agent"; serviceConfig = { - ExecStart = "${pkgs.qemu.ga}/bin/qemu-ga"; + ExecStart = "${cfg.package}/bin/qemu-ga"; Restart = "always"; RestartSec = 0; }; From 8ed57ac9166c3b0fcde9e8e6d2a379e501bcb7e5 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 19 Oct 2020 18:03:01 +0200 Subject: [PATCH 6/9] nixos/tests: make sure we use the qemu_test package to provide the Guest Agent This reduces the closure size for the minimal test by a lot since we no longer have to build the regular QEMU for even the simplest test. --- nixos/modules/testing/test-instrumentation.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/testing/test-instrumentation.nix b/nixos/modules/testing/test-instrumentation.nix index c0ec76e8a3a..dbbcb0bed5b 100644 --- a/nixos/modules/testing/test-instrumentation.nix +++ b/nixos/modules/testing/test-instrumentation.nix @@ -116,6 +116,10 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; }; users.users.root.initialHashedPassword = mkOverride 150 ""; services.xserver.displayManager.job.logToJournal = true; + + # Make sure we use the Guest Agent from the QEMU package for testing + # to reduce the closure size required for the tests. + services.qemuGuest.package = pkgs.qemu_test.ga; }; } From 54e6cfc1efd8e563371fee815389e51554998eef Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 19 Oct 2020 21:41:53 +0200 Subject: [PATCH 7/9] iptuils: Remove systemd from dependencies In our case systemd is only used to figure out if the unit files should be generated. --- pkgs/os-specific/linux/iputils/default.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/linux/iputils/default.nix b/pkgs/os-specific/linux/iputils/default.nix index e12c44888a0..665ec372e93 100644 --- a/pkgs/os-specific/linux/iputils/default.nix +++ b/pkgs/os-specific/linux/iputils/default.nix @@ -1,6 +1,6 @@ { stdenv, fetchFromGitHub , meson, ninja, pkgconfig, gettext, libxslt, docbook_xsl_ns -, libcap, systemd, libidn2 +, libcap, libidn2 }: with stdenv.lib; @@ -22,6 +22,12 @@ in stdenv.mkDerivation rec { sha256 = "1jhbcz75a4ij1myyyi110ma1d8d5hpm3scz9pyw7js6qym50xvh4"; }; + postPatch = '' + # Enable the systemd units even without systemd being an input. We set the + # unitdir manually anyway. + sed -e 's/systemd\.found()/true/g' -i meson.build + ''; + mesonFlags = [ "-DBUILD_RARPD=true" "-DBUILD_TRACEROUTE6=true" @@ -33,7 +39,7 @@ in stdenv.mkDerivation rec { ++ optional stdenv.hostPlatform.isMusl "-DUSE_IDN=false"; nativeBuildInputs = [ meson ninja pkgconfig gettext libxslt.bin docbook_xsl_ns ]; - buildInputs = [ libcap systemd ] + buildInputs = [ libcap ] ++ optional (!stdenv.hostPlatform.isMusl) libidn2; meta = { From 0a55c5dada75480342ee9b58932d612438793302 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 19 Oct 2020 22:02:46 +0200 Subject: [PATCH 8/9] iputils: apply proposed upstream patch to get rid of systemd dependency This allows us to get rid of the hack and the systemd dependency and thus reduces the rebuild closure whenever systemd changes. --- pkgs/os-specific/linux/iputils/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/os-specific/linux/iputils/default.nix b/pkgs/os-specific/linux/iputils/default.nix index 665ec372e93..3bb653ebcf7 100644 --- a/pkgs/os-specific/linux/iputils/default.nix +++ b/pkgs/os-specific/linux/iputils/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchFromGitHub +{ stdenv, fetchFromGitHub, fetchpatch , meson, ninja, pkgconfig, gettext, libxslt, docbook_xsl_ns , libcap, libidn2 }: @@ -22,11 +22,13 @@ in stdenv.mkDerivation rec { sha256 = "1jhbcz75a4ij1myyyi110ma1d8d5hpm3scz9pyw7js6qym50xvh4"; }; - postPatch = '' - # Enable the systemd units even without systemd being an input. We set the - # unitdir manually anyway. - sed -e 's/systemd\.found()/true/g' -i meson.build - ''; + patches = [ + # Proposed upstream patch to reduce dependency on systemd: https://github.com/iputils/iputils/pull/297 + (fetchpatch { + url = "https://github.com/iputils/iputils/commit/13d6aefd57fd471ecad06e19073dcc44608dff5e.patch"; + sha256 = "1n62zxmzp7hgz9qapbbpqv3fxqvc3qyd2a73jhp357x6by84kj49"; + }) + ]; mesonFlags = [ "-DBUILD_RARPD=true" @@ -34,6 +36,7 @@ in stdenv.mkDerivation rec { "-DBUILD_TFTPD=true" "-DNO_SETCAP_OR_SUID=true" "-Dsystemdunitdir=etc/systemd/system" + "-DINSTALL_SYSTEMD_UNITS=true" ] # Disable idn usage w/musl (https://github.com/iputils/iputils/pull/111): ++ optional stdenv.hostPlatform.isMusl "-DUSE_IDN=false"; From 16a7ff5b867f6e9cb615eac7a136421a197921c0 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Mon, 19 Oct 2020 23:11:28 +0200 Subject: [PATCH 9/9] libndctl: clarify that it needs udev not systemd While (currently) it is the same package it carries more information if we explicitly state that we want udev. --- pkgs/development/libraries/libndctl/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/libndctl/default.nix b/pkgs/development/libraries/libndctl/default.nix index 7c4c49baffa..be5c75806d8 100644 --- a/pkgs/development/libraries/libndctl/default.nix +++ b/pkgs/development/libraries/libndctl/default.nix @@ -1,6 +1,6 @@ { stdenv, fetchFromGitHub, autoreconfHook , asciidoctor, pkgconfig, xmlto, docbook_xsl, docbook_xml_dtd_45, libxslt -, json_c, kmod, which, utillinux, systemd, keyutils +, json_c, kmod, which, utillinux, udev, keyutils }: stdenv.mkDerivation rec { @@ -22,7 +22,7 @@ stdenv.mkDerivation rec { ]; buildInputs = - [ json_c kmod utillinux systemd keyutils + [ json_c kmod utillinux udev keyutils ]; configureFlags =