Skip to content

Commit

Permalink
runInLinuxVM: pass .attrs.sh explicitly instead of whole /build direc…
Browse files Browse the repository at this point in the history
…tory

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
  • Loading branch information
wolfgangwalther committed Nov 30, 2024
1 parent 58570e7 commit d2593f0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pkgs/build-support/vm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,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 @@ -165,9 +165,11 @@ rec {
stage2Init = writeScript "vm-run-stage2" ''
#! ${bash}/bin/sh
set -euo pipefail
source /build/xchg/saved-env
if [ -f "''${NIX_ATTRS_SH_FILE-}" ]; then
source "$NIX_ATTRS_SH_FILE"
source /tmp/xchg/saved-env
if [ -f /tmp/xchg/.attrs.sh ]; then
source /tmp/xchg/.attrs.sh
export NIX_ATTRS_JSON_FILE=/tmp/xchg/.attrs.json
export NIX_ATTRS_SH_FILE=/tmp/xchg/.attrs.sh
fi
export NIX_STORE=${storeDir}
Expand All @@ -177,6 +179,7 @@ rec {
cd "$NIX_BUILD_TOP"
source $stdenv/setup
if ! test -e /bin/sh; then
${coreutils}/bin/mkdir -p /bin
${coreutils}/bin/ln -s ${bash}/bin/sh /bin/sh
Expand All @@ -201,7 +204,7 @@ rec {
declare -a argsArray=()
concatTo argsArray origArgs
"$origBuilder" "''${argsArray[@]}"
echo $? > /build/xchg/in-vm-exit
echo $? > /tmp/xchg/in-vm-exit
${busybox}/bin/mount -o remount,ro dummy /
Expand All @@ -220,7 +223,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=xchg,security_model=none,mount_tag=xchg \
''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
-kernel ${kernel}/${img} \
-initrd ${initrd}/initrd \
Expand All @@ -235,6 +238,7 @@ rec {
PATH=${coreutils}/bin
if [ -f "''${NIX_ATTRS_SH_FILE-}" ]; then
cp $NIX_ATTRS_JSON_FILE $NIX_ATTRS_SH_FILE xchg
source "$NIX_ATTRS_SH_FILE"
fi
source $stdenv/setup
Expand Down

0 comments on commit d2593f0

Please sign in to comment.