Skip to content

Commit d2593f0

Browse files
runInLinuxVM: pass .attrs.sh explicitly instead of whole /build directory
The approach taken in [1] breaks down as soon as vmRunCommand is manually called with an overriden TMPDIR, like disko does it. /build will just not be available. By moving the .attrs.sh file into the xchg folder explicitly, we can all the "exchange infrastructure" the same as before, thus avoid more breakage. This reverts some parts of [1]. [1]: 97ed6b4
1 parent 58570e7 commit d2593f0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pkgs/build-support/vm/default.nix

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ rec {
125125
mkdir -p /fs${storeDir}
126126
mount -t 9p store /fs${storeDir} -o trans=virtio,version=9p2000.L,cache=loose,msize=131072
127127
128-
echo "mounting host's build directory..."
129-
mkdir -p /fs/build
130-
mount -t 9p sa /fs/build -o trans=virtio,version=9p2000.L,cache=loose,msize=131072
131-
132128
mkdir -p /fs/tmp /fs/run /fs/var
133129
mount -t tmpfs -o "mode=1777" none /fs/tmp
134130
mount -t tmpfs -o "mode=755" none /fs/run
135131
ln -sfn /run /fs/var/run
136132
133+
echo "mounting host's temporary directory..."
134+
mkdir -p /fs/tmp/xchg
135+
mount -t 9p xchg /fs/tmp/xchg -o trans=virtio,version=9p2000.L,msize=131072
136+
137137
mkdir -p /fs/proc
138138
mount -t proc none /fs/proc
139139
@@ -165,9 +165,11 @@ rec {
165165
stage2Init = writeScript "vm-run-stage2" ''
166166
#! ${bash}/bin/sh
167167
set -euo pipefail
168-
source /build/xchg/saved-env
169-
if [ -f "''${NIX_ATTRS_SH_FILE-}" ]; then
170-
source "$NIX_ATTRS_SH_FILE"
168+
source /tmp/xchg/saved-env
169+
if [ -f /tmp/xchg/.attrs.sh ]; then
170+
source /tmp/xchg/.attrs.sh
171+
export NIX_ATTRS_JSON_FILE=/tmp/xchg/.attrs.json
172+
export NIX_ATTRS_SH_FILE=/tmp/xchg/.attrs.sh
171173
fi
172174
173175
export NIX_STORE=${storeDir}
@@ -177,6 +179,7 @@ rec {
177179
cd "$NIX_BUILD_TOP"
178180
179181
source $stdenv/setup
182+
180183
if ! test -e /bin/sh; then
181184
${coreutils}/bin/mkdir -p /bin
182185
${coreutils}/bin/ln -s ${bash}/bin/sh /bin/sh
@@ -201,7 +204,7 @@ rec {
201204
declare -a argsArray=()
202205
concatTo argsArray origArgs
203206
"$origBuilder" "''${argsArray[@]}"
204-
echo $? > /build/xchg/in-vm-exit
207+
echo $? > /tmp/xchg/in-vm-exit
205208
206209
${busybox}/bin/mount -o remount,ro dummy /
207210
@@ -220,7 +223,7 @@ rec {
220223
-nographic -no-reboot \
221224
-device virtio-rng-pci \
222225
-virtfs local,path=${storeDir},security_model=none,mount_tag=store \
223-
-virtfs local,path=/build,security_model=none,mount_tag=sa \
226+
-virtfs local,path=xchg,security_model=none,mount_tag=xchg \
224227
''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
225228
-kernel ${kernel}/${img} \
226229
-initrd ${initrd}/initrd \
@@ -235,6 +238,7 @@ rec {
235238
PATH=${coreutils}/bin
236239
237240
if [ -f "''${NIX_ATTRS_SH_FILE-}" ]; then
241+
cp $NIX_ATTRS_JSON_FILE $NIX_ATTRS_SH_FILE xchg
238242
source "$NIX_ATTRS_SH_FILE"
239243
fi
240244
source $stdenv/setup

0 commit comments

Comments
 (0)