Unverified Commit d2593f01 authored by Wolfgang Walther's avatar Wolfgang Walther
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]: 97ed6b45
parent 58570e75
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -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

@@ -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}
@@ -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
@@ -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 /

@@ -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 \
@@ -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