From d633c9038362b58414bb43e9497a0a1e7a5f8297 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 8 Nov 2024 17:26:17 +0100 Subject: [PATCH] runInLinuxVM: fix for structured attrs Closes #334705 Addresses #205690 The main issue was that the output variable (i.e. `$out` and friends) didn't exist. I figured the easiest way to add those is to source `stdenv` here. Given that we build another derivation in this builder, it's pretty likely that `stdenv` gets pulled already, so I don't expect a real overhead here. Also, this mounts `/build` into the VM: this is required to make sure `.attrs.json` & `.attrs.sh` are available. Dropped the mount of `xchg` into `/tmp` now since it's also part of `/build`. --- pkgs/build-support/vm/default.nix | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix index 7ba67af5cf5a1..45753efca25fb 100644 --- a/pkgs/build-support/vm/default.nix +++ b/pkgs/build-support/vm/default.nix @@ -130,15 +130,15 @@ rec { mkdir -p /fs${storeDir} mount -t 9p store /fs${storeDir} -o trans=virtio,version=9p2000.L,cache=loose,msize=131072 + echo "mounting host's build directory..." + mkdir -p /fs/build + mount -t 9p sa /fs/build -o trans=virtio,version=9p2000.L,cache=loose,msize=131072 + mkdir -p /fs/tmp /fs/run /fs/var mount -t tmpfs -o "mode=1777" none /fs/tmp mount -t tmpfs -o "mode=755" none /fs/run ln -sfn /run /fs/var/run - echo "mounting host's temporary directory..." - mkdir -p /fs/tmp/xchg - mount -t 9p xchg /fs/tmp/xchg -o trans=virtio,version=9p2000.L,msize=131072 - mkdir -p /fs/proc mount -t proc none /fs/proc @@ -169,7 +169,9 @@ rec { stage2Init = writeScript "vm-run-stage2" '' #! ${bash}/bin/sh - source /tmp/xchg/saved-env + source /build/xchg/saved-env + [ -f "''${NIX_ATTRS_SH_FILE-}" ] && source "$NIX_ATTRS_SH_FILE" + source $stdenv/setup # Set the system time from the hardware clock. Works around an # apparent KVM > 1.5.2 bug. @@ -203,8 +205,8 @@ rec { if test -n "$origBuilder" -a ! -e /.debug; then exec < /dev/null ${coreutils}/bin/touch /.debug - $origBuilder $origArgs - echo $? > /tmp/xchg/in-vm-exit + $origBuilder ''${origArgs[*]} + echo $? > /build/xchg/in-vm-exit ${busybox}/bin/mount -o remount,ro dummy / @@ -223,6 +225,7 @@ rec { -nographic -no-reboot \ -device virtio-rng-pci \ -virtfs local,path=${storeDir},security_model=none,mount_tag=store \ + -virtfs local,path=/build,security_model=none,mount_tag=sa \ -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \ ''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \ -kernel ${kernel}/${img} \ @@ -233,6 +236,8 @@ rec { vmRunCommand = qemuCommand: writeText "vm-run" '' + [ -f "''${NIX_ATTRS_SH_FILE-}" ] && source "$NIX_ATTRS_SH_FILE" + source $stdenv/setup export > saved-env PATH=${coreutils}/bin