diff --git a/checks/default.nix b/checks/default.nix index 4113c534..8ac5cb06 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -8,6 +8,25 @@ let modules = [ { microvm.hypervisor = "qemu"; } ]; + } { + id = "qemu-tcg"; + modules = let + # Emulate a different guest system than the host one + guestSystem = if "${system}" == "x86_64-linux" then "aarch64-unknown-linux-gnu" + else "x86_64-linux"; + in [ + { + microvm = { + hypervisor = "qemu"; + # Force the CPU to be something else than the current + # system, and thus, emulated with qemu's Tiny Code Generator + # (TCG) + cpu = if "${system}" == "x86_64-linux" then "cortex-a53" + else "Westmere"; + }; + nixpkgs.crossSystem.config = guestSystem; + } + ]; } { id = "cloud-hypervisor"; modules = [ { diff --git a/checks/startup-shutdown.nix b/checks/startup-shutdown.nix index 774f9b83..3421f8f2 100644 --- a/checks/startup-shutdown.nix +++ b/checks/startup-shutdown.nix @@ -15,9 +15,9 @@ let }; microvm = { volumes = [ { - label = "var"; - mountPoint = "/var"; - image = "var.img"; + image = "output.img"; + label = "output"; + mountPoint = "/output"; size = 32; } ]; crosvm.pivotRoot = "/build/empty"; @@ -35,7 +35,9 @@ let kvmtool = "reboot"; }.${config.microvm.hypervisor}; in '' - ${pkgs.coreutils}/bin/uname > /var/OK + ${pkgs.coreutils}/bin/uname > /output/kernel-name + ${pkgs.coreutils}/bin/uname -m > /output/machine-name + ${exit} ''; }; @@ -53,14 +55,34 @@ builtins.mapAttrs (_: nixos: ]; requiredSystemFeatures = [ "kvm" ]; meta.timeout = 120; - } '' + } (let + expectedMachineName = (crossSystem: + if crossSystem == null then + expectedMachineName { config = system; } + else if crossSystem.config == "aarch64-unknown-linux-gnu" then + "aarch64" + else if crossSystem.config == "x86_64-linux" then + "x86_64" + else throw "unknown machine name (${crossSystem.config})" + ); + in '' microvm-run - 7z e var.img OK - if [ "$(cat OK)" != "Linux" ] ; then - echo Output does not match + 7z e output.img kernel-name machine-name + + EXPECTED_KERNEL_NAME="Linux" + if [ "$(cat kernel-name)" != "$EXPECTED_KERNEL_NAME" ] ; then + echo "Kernel does not match (got: $(cat kernel-name); expected: $EXPECTED_KERNEL_NAME)" + exit 1 + fi + + EXPECTED_MACHINE_NAME="${expectedMachineName nixos.config.nixpkgs.crossSystem}" + if [ "$(cat machine-name)" != "$EXPECTED_MACHINE_NAME" ] ; then + echo "Machine does not match (got: $(cat machine-name); expected: $EXPECTED_MACHINE_NAME)" exit 1 fi - cp OK $out - '' + + mkdir $out + cp {kernel-name,machine-name} $out + '') ) configs diff --git a/lib/default.nix b/lib/default.nix index 0e299cfc..7e3b34d4 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -56,9 +56,9 @@ rec { # Mark NOCOW chattr +C '${image}' || true fallocate -l${toString size}MiB '${image}' - mkfs.${fsType} ${pkgs.lib.optionalString (label != null) "-L '${label}'"} '${image}' + mkfs.${fsType} ${labelArgument} '${image}' fi - '')); + ''))); buildRunner = import ./runner.nix; diff --git a/lib/runner.nix b/lib/runner.nix index 263be794..f707a032 100644 --- a/lib/runner.nix +++ b/lib/runner.nix @@ -19,23 +19,23 @@ let preStart = hypervisorConfig.preStart or microvmConfig.preStart; tapMultiQueue = hypervisorConfig.tapMultiQueue or false; - runScriptBin = pkgs.writeScriptBin "microvm-run" '' - #! ${pkgs.runtimeShell} -e + runScriptBin = pkgs.buildPackages.writeScriptBin "microvm-run" '' + #! ${pkgs.buildPackages.runtimeShell} -e ${preStart} - ${createVolumesScript pkgs microvmConfig.volumes} + ${createVolumesScript pkgs.buildPackages microvmConfig.volumes} ${lib.optionalString (hypervisorConfig.requiresMacvtapAsFds or false) openMacvtapFds} exec ${command} ''; - shutdownScriptBin = pkgs.writeScriptBin "microvm-shutdown" '' + shutdownScriptBin = pkgs.buildPackages.writeScriptBin "microvm-shutdown" '' #! ${pkgs.runtimeShell} -e ${shutdownCommand} ''; - balloonScriptBin = pkgs.writeScriptBin "microvm-balloon" '' + balloonScriptBin = pkgs.buildPackages.writeScriptBin "microvm-balloon" '' #! ${pkgs.runtimeShell} -e if [ -z "$1" ]; then @@ -48,7 +48,7 @@ let ''; in -pkgs.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConfig.hostName}" +pkgs.buildPackages.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConfig.hostName}" { # for `nix run` meta.mainProgram = "microvm-run";