Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runInLinuxVM: fix for structured attrs #354535

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 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,12 @@ rec {

stage2Init = writeScript "vm-run-stage2" ''
#! ${bash}/bin/sh
source /tmp/xchg/saved-env
set -euo pipefail
source /build/xchg/saved-env
if [ -f "''${NIX_ATTRS_SH_FILE-}" ]; then
source "$NIX_ATTRS_SH_FILE"
fi
source $stdenv/setup
Ma27 marked this conversation as resolved.
Show resolved Hide resolved

# Set the system time from the hardware clock. Works around an
# apparent KVM > 1.5.2 bug.
Expand All @@ -179,7 +184,6 @@ rec {
export NIX_BUILD_TOP=/tmp
export TMPDIR=/tmp
export PATH=/empty
out="$1"
cd "$NIX_BUILD_TOP"

if ! test -e /bin/sh; then
Expand All @@ -203,8 +207,10 @@ rec {
if test -n "$origBuilder" -a ! -e /.debug; then
exec < /dev/null
${coreutils}/bin/touch /.debug
$origBuilder $origArgs
echo $? > /tmp/xchg/in-vm-exit
declare -a argsArray=()
concatTo argsArray origArgs
"$origBuilder" "''${argsArray[@]}"
echo $? > /build/xchg/in-vm-exit

${busybox}/bin/mount -o remount,ro dummy /

Expand All @@ -223,11 +229,12 @@ 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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this isn't backwards compatible and creates quite a few annoyances. Right now, it breaks disko, see nix-community/disko#900

Formatting 'main.raw', fmt=raw size=10737418240
qemu-kvm: -virtfs local,path=/build,security_model=none,mount_tag=sa: cannot initialize fsdev 'sa': failed to open '/build': No such file or directory

The other paths in this invocation are configurable, but /build requires me to do a switch_root before. I would like to allow adding a custom prefix in front of this path. I'll submit a PR for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently looking into this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I don't have the bandwidth for it this weekend, can take a look at this on ~Monday if needed (please ping me here if that's the case).

-virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \
''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
-kernel ${kernel}/${img} \
-initrd ${initrd}/initrd \
-append "console=${qemu-common.qemuSerialDevice} panic=1 command=${stage2Init} out=$out mountDisk=$mountDisk loglevel=4" \
-append "console=${qemu-common.qemuSerialDevice} panic=1 command=${stage2Init} mountDisk=$mountDisk loglevel=4" \
$QEMU_OPTS
'';

Expand Down Expand Up @@ -260,8 +267,6 @@ rec {
${qemuCommand}
EOF

mkdir -p -m 0700 $out

chmod +x ./run-vm
source ./run-vm

Expand Down