anchor.diff:  
           trap cleanup SIGTERM SIGKILL EXIT
   
  -        uuid="$(uuidgen -r)"
  +        # Variables that are substituted within the libvirt XML files
  +        testid="$(basename "$out")"
  +        testid="''${testid%%-*}"
           pwd="$(pwd)"
  -
  -        ${optionalString (cfg.backend == "lxc") ''
  -          mkdir root-{${concatMapStringsSep "," (n: ''"${n}"'') (attrNames cfg.instances)}}
  -          uid="$(id -u)"
  -          gid="$(id -g)"
  -        ''}
  -
  -        echo "Test UUID: $uuid"
  -
  -        mkdir -p out/logs out/libvirt
  -        touch out/logs/{${concatMapStringsSep "," (n: ''"${n}"'')
  -          (attrNames cfg.instances)}}.{console,journal}
  +        uid="$(id -u)"
  +        gid="$(id -g)"
  +
  +        # Setup directories and libvirt XML files
  +        mkdir -p out/libvirt out/hosts/{${instList}}
  +        touch out/hosts/{${instList}}/{console,journal}.log
           cp -t out/libvirt "$src"/*
  -
           for f in out/libvirt/{dom,net}-*.xml; do substituteAllInPlace "$f"; done
  +        ${optionalString (cfg.backend == "lxc") "mkdir root-{${instList}}"}
   
           # Let libvirt access paths inside the build directory and write to out dir
           chmod a+x .
  -        chmod a+w out
  -
  -        tail -Fq out/stdout.log out/stderr.log \
  -          ${concatMapStringsSep " " (n: "out/logs/${n}.journal")
  -            (attrNames cfg.instances)
  -          } 2>/dev/null &
  -
  -        # Start libvirt machines
  -        virsh -c "${cfg.connectionURI}" "${virshCmds}" >/dev/null || true
  -
  -        test -a out/done || echo >&2 "Possible test timeout!"
  -        test -a out/passed || exit 1
  -
  -        chmod go-w out
  -        mv out $out
  +        chmod a+w out/hosts/*
  +
  +        tail -Fq out/hosts/test-driver/script.std{out,err} \
  +          out/hosts/{${instList}}/{console,journal}.log 2>/dev/null &
  +
  +        ${pkgs.libvirt}/bin/virsh -c "${cfg.connectionURI}" \
  +          "${virshCmds}" >/dev/null || true
  +
  +        cleanup
         '';
  +
  +      installPhase = "mv out $out";
       };
   
     };
  
positive.code:     };
    };
  
    virshCmds = concatStringsSep ";" (flatten [
      "net-create out/libvirt/net-test.xml"
      (map (name: "create out/libvirt/dom-${name}.xml --autodestroy") (attrNames cfg.instances))
      "event --timeout ${toString cfg.timeout} --domain $uuid --event lifecycle"
      "net-destroy net-$uuid"
    ]);
  
    # A temporary, isolated network for our test machines
    libvirtNetwork = writeText "network.xml" ''
      <network>
        <name>net-@uuid@</name>
      </network>
    '';
  
  
negative.code:       instances = mkOption {
          default = {};
          type = with types; attrsOf (submodule instanceOpts);
        };
  
        verification-script = mkOption {
          type = types.lines;
          description = ''
            A script that will be inlined in the build phase of the
            result builder. The environment variable <code>output</output>
            will point to the directory containing the build output.
            By default, the output is checked for the existence of a
            successful exit code file from the test script.
            You can also use this script to do post-processing of the
            test output, by writing to the <code>out</code> path like
            any Nix build.
          '';
          default = ''
            test -a hosts/test-driver/script.exit && \
            test "$(cat hosts/test-driver/script.exit)" = "0" || \
            exit 1
          '';
        };
  
        test-driver = {
  