8888 set -- $(IFS==; echo $o)
8989 command=$2
9090 ;;
91- out=*)
92- set -- $(IFS==; echo $o)
93- export out=$2
94- ;;
9591 esac
9692 done
9793
@@ -129,15 +125,15 @@ rec {
129125 mkdir -p /fs${ storeDir }
130126 mount -t 9p store /fs${ storeDir } -o trans=virtio,version=9p2000.L,cache=loose,msize=131072
131127
132- echo "mounting host's build directory..."
133- mkdir -p /fs/build
134- mount -t 9p sa /fs/build -o trans=virtio,version=9p2000.L,cache=loose,msize=131072
135-
136128 mkdir -p /fs/tmp /fs/run /fs/var
137129 mount -t tmpfs -o "mode=1777" none /fs/tmp
138130 mount -t tmpfs -o "mode=755" none /fs/run
139131 ln -sfn /run /fs/var/run
140132
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+
141137 mkdir -p /fs/proc
142138 mount -t proc none /fs/proc
143139
@@ -153,7 +149,7 @@ rec {
153149 fi
154150
155151 echo "starting stage 2 ($command)"
156- exec switch_root /fs $command $out
152+ exec switch_root /fs $command
157153 '' ;
158154
159155
@@ -169,18 +165,21 @@ rec {
169165 stage2Init = writeScript "vm-run-stage2" ''
170166 #! ${ bash } /bin/sh
171167 set -euo pipefail
172- source /build/xchg/saved-env
173- if [ -f "'' ${NIX_ATTRS_SH_FILE-}" ]; then
174- 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
175173 fi
176- source $stdenv/setup
177174
178175 export NIX_STORE=${ storeDir }
179176 export NIX_BUILD_TOP=/tmp
180177 export TMPDIR=/tmp
181178 export PATH=/empty
182179 cd "$NIX_BUILD_TOP"
183180
181+ source $stdenv/setup
182+
184183 if ! test -e /bin/sh; then
185184 ${ coreutils } /bin/mkdir -p /bin
186185 ${ coreutils } /bin/ln -s ${ bash } /bin/sh /bin/sh
@@ -205,7 +204,7 @@ rec {
205204 declare -a argsArray=()
206205 concatTo argsArray origArgs
207206 "$origBuilder" "'' ${argsArray[@]}"
208- echo $? > /build /xchg/in-vm-exit
207+ echo $? > /tmp /xchg/in-vm-exit
209208
210209 ${ busybox } /bin/mount -o remount,ro dummy /
211210
@@ -224,8 +223,7 @@ rec {
224223 -nographic -no-reboot \
225224 -device virtio-rng-pci \
226225 -virtfs local,path=${ storeDir } ,security_model=none,mount_tag=store \
227- -virtfs local,path=/build,security_model=none,mount_tag=sa \
228- -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \
226+ -virtfs local,path=xchg,security_model=none,mount_tag=xchg \
229227 '' ${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
230228 -kernel ${ kernel } /${ img } \
231229 -initrd ${ initrd } /initrd \
@@ -235,15 +233,15 @@ rec {
235233
236234
237235 vmRunCommand = qemuCommand : writeText "vm-run" ''
236+ ${ coreutils } /bin/mkdir xchg
237+ export > xchg/saved-env
238+ PATH=${ coreutils } /bin
239+
238240 if [ -f "'' ${NIX_ATTRS_SH_FILE-}" ]; then
241+ cp $NIX_ATTRS_JSON_FILE $NIX_ATTRS_SH_FILE xchg
239242 source "$NIX_ATTRS_SH_FILE"
240243 fi
241244 source $stdenv/setup
242- export > saved-env
243-
244- PATH=${ coreutils } /bin
245- mkdir xchg
246- mv saved-env xchg/
247245
248246 eval "$preVM"
249247
@@ -261,8 +259,6 @@ rec {
261259 cat > ./run-vm <<EOF
262260 #! ${ bash } /bin/sh
263261 '' ${diskImage:+diskImage=$diskImage}
264- TMPDIR=$TMPDIR
265- cd $TMPDIR
266262 ${ qemuCommand }
267263 EOF
268264
0 commit comments