From fc0cc3fe27f92a67b709233afbaffc0d0a7883d7 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sat, 27 May 2023 11:11:49 -0600 Subject: [PATCH] nixos/tests/systemd-binfmt: Add chroot test --- nixos/tests/systemd-binfmt.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nixos/tests/systemd-binfmt.nix b/nixos/tests/systemd-binfmt.nix index b16fda0ddb1a..a5e46a455d32 100644 --- a/nixos/tests/systemd-binfmt.nix +++ b/nixos/tests/systemd-binfmt.nix @@ -87,4 +87,29 @@ in { ).lower() ''; }; + + chroot = makeTest { + name = "systemd-binfmt-chroot"; + nodes.machine = { pkgs, lib, ... }: { + boot.binfmt.emulatedSystems = [ + "aarch64-linux" "wasm32-wasi" + ]; + boot.binfmt.preferStaticEmulators = true; + + environment.systemPackages = [ + (pkgs.writeShellScriptBin "test-chroot" '' + set -euo pipefail + mkdir -p /tmp/chroot + cp ${lib.getExe' pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic.busybox "busybox"} /tmp/chroot/busybox + cp ${lib.getExe pkgs.pkgsCross.wasi32.yaml2json} /tmp/chroot/yaml2json # wasi binaries that build are hard to come by + chroot /tmp/chroot /busybox uname -m | grep aarch64 + echo 42 | chroot /tmp/chroot /yaml2json | grep 42 + '') + ]; + }; + testScript = '' + machine.start() + machine.succeed("test-chroot") + ''; + }; }