Skip to content

Commit

Permalink
runInLinuxVM: fix for structured attrs
Browse files Browse the repository at this point in the history
Closes NixOS#334705
Addresses NixOS#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`.
  • Loading branch information
Ma27 committed Nov 8, 2024
1 parent 50f7983 commit d633c90
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkgs/build-support/vm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 /
Expand All @@ -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} \
Expand All @@ -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
Expand Down

0 comments on commit d633c90

Please sign in to comment.