From cf47294b9ee7887ca1f21db34d48c346e89f9cec Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 18 Mar 2024 12:09:49 +0200 Subject: feat(tvix/boot): boot nixos VM This makes use of the vmCmdline and assertVMOutput to boot a NixOS VM off of `tvix-store virtiofs` have it write a message on successful bootup, then have it shut down again. We check we see the message in the output. Seeding the store with the closure it's what's currently taking most of the time (as it's all linear still), so log a message before booting the VM. Change-Id: I6887d935f589eb0ad6507033c01337e1ec500a0b Reviewed-on: https://cl.tvl.fyi/c/depot/+/11191 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/boot/tests/default.nix | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tvix/boot/tests/default.nix b/tvix/boot/tests/default.nix index 949be35ccf53..d16dba79f140 100644 --- a/tvix/boot/tests/default.nix +++ b/tvix/boot/tests/default.nix @@ -70,12 +70,38 @@ let tvix-store --otlp=false copy '' + '' # Invoke a VM using tvix as the backing store, ensure the outpath appears in its listing. + echo "Starting VM…" CH_CMDLINE="${vmCmdline}" run-tvix-vm 2>&1 | tee output.txt grep "${assertVMOutput}" output.txt ''; requiredSystemFeatures = [ "kvm" ]; }; + + systemFor = sys: (depot.ops.nixos.nixosFor sys).system; + + testSystem = systemFor ({ modulesPath, pkgs, ... }: { + # Set some options necessary to evaluate. + boot.loader.systemd-boot.enable = true; + # TODO: figure out how to disable this without causing eval to fail + fileSystems."/" = { + device = "/dev/root"; + fsType = "tmpfs"; + }; + + services.getty.helpLine = "Onwards and upwards."; + systemd.services.do-shutdown = { + after = [ "getty.target" ]; + description = "Shut down again"; + wantedBy = [ "multi-user.target" ]; + serviceConfig.Type = "oneshot"; + script = "/run/current-system/sw/bin/systemctl poweroff --when=+10s"; + }; + + # Don't warn about stateVersion. + system.stateVersion = "24.05"; + }); + in depot.nix.readTree.drvTargets { @@ -101,4 +127,12 @@ depot.nix.readTree.drvTargets path = depot.tvix.store; isClosure = true; }); + + closure-nixos = (mkBootTest { + blobServiceAddr = "objectstore+file://$PWD/blobs"; + path = testSystem; + isClosure = true; + vmCmdline = "init=${testSystem}/init panic=-1"; # reboot immediately on panic + assertVMOutput = "Onwards and upwards."; + }); } -- cgit 1.4.1