about summary refs log tree commit diff
path: root/tvix/boot/tests/default.nix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-03-17T20·00+0200
committerflokli <flokli@flokli.de>2024-03-18T16·10+0000
commitfca3926a62a7f6dda1b4f98acd036c61fe8211a5 (patch)
tree66bb3356d32a55c9de11b0daab6a118d9e0eb9a7 /tvix/boot/tests/default.nix
parent05bdb6852384f622071aefa070dd602ddb67ee45 (diff)
feat(tvix/boot/tests): make urls and paths configurable r/7725
Fork off a long-living tvix-store daemon in the background, and have
both the import, as well as the virtiofs invocation connect to that one,
rather than use the underlying storage directly.

This also opens up the potential to have other things seed the store
(like nar-bridge).

Change-Id: Ie13aedaf7ab31e5ebe78a7be42f144af3920fa9c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11186
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Diffstat (limited to 'tvix/boot/tests/default.nix')
-rw-r--r--tvix/boot/tests/default.nix55
1 files changed, 39 insertions, 16 deletions
diff --git a/tvix/boot/tests/default.nix b/tvix/boot/tests/default.nix
index 4a38b3f65083..378efaccc982 100644
--- a/tvix/boot/tests/default.nix
+++ b/tvix/boot/tests/default.nix
@@ -1,10 +1,17 @@
-{ depot, pkgs, ... }:
+{ depot, pkgs, lib, ... }:
 
 let
   # Seed a tvix-store with the tvix docs, then start a VM, ask it to list all
   # files in /nix/store, and ensure the store path is present, which acts as a
   # nice smoketest.
-  mkBootTest = blobServiceAddr:
+  mkBootTest =
+    { blobServiceAddr ? "memory://"
+    , directoryServiceAddr ? "memory://"
+    , pathInfoServiceAddr ? "memory://"
+      # The path to import (via tvix-store import).
+    , importPath ? ../../docs
+    , importPathName ? "docs"
+    }:
     pkgs.stdenv.mkDerivation {
       name = "run-vm";
       nativeBuildInputs = [
@@ -14,27 +21,43 @@ let
       buildCommand = ''
         touch $out
 
-        # Configure tvix to put data in the local working directory
-        export BLOB_SERVICE_ADDR=${blobServiceAddr}
-        export DIRECTORY_SERVICE_ADDR=sled://$PWD/directories.sled
-        export PATH_INFO_SERVICE_ADDR=sled://$PWD/pathinfo.sled
+        # Start the tvix daemon, listening on a unix socket.
+        BLOB_SERVICE_ADDR=${blobServiceAddr} \
+          DIRECTORY_SERVICE_ADDR=${directoryServiceAddr} \
+          PATH_INFO_SERVICE_ADDR=${pathInfoServiceAddr} \
+          tvix-store daemon -l $PWD/tvix-store.socket &
 
-        # Seed the tvix store with some data
-        # Create a `docs` directory with the contents from ../docs
-        # Make sure it still is called "docs" when calling import, so we can
-        # predict the store path.
-        cp -R ${../../docs} docs
-        outpath=$(tvix-store import docs)
+        # Wait for the socket to be created.
+        while [ ! -e $PWD/tvix-store.socket ]; do sleep 1; done
 
-        echo "Store contents imported to $outpath"
+        # Export env vars so that subsequent tvix-store commands will talk to
+        # our tvix-store daemon over the unix socket.
+        export BLOB_SERVICE_ADDR=grpc+unix://$PWD/tvix-store.socket
+        export DIRECTORY_SERVICE_ADDR=grpc+unix://$PWD/tvix-store.socket
+        export PATH_INFO_SERVICE_ADDR=grpc+unix://$PWD/tvix-store.socket
+      '' + lib.optionalString (importPath != null) ''
+        echo "Importing ${importPath} into tvix-store with name ${importPathName}…"
+        cp -R ${importPath} ${importPathName}
+        outpath=$(tvix-store import ${importPathName})
+
+        echo "imported to $outpath"
+
+        # Invoke a VM using tvix as the backing store, ensure the outpath appears in its listing.
 
         CH_CMDLINE="tvix.find" run-tvix-vm 2>&1 | tee output.txt
-        grep ${../../docs} output.txt
+        grep $outpath output.txt
       '';
       requiredSystemFeatures = [ "kvm" ];
     };
 in
 depot.nix.readTree.drvTargets {
-  docs-sled = (mkBootTest "sled://$PWD/blobs.sled");
-  docs-objectstore-local = (mkBootTest "objectstore+file://$PWD/blobs");
+  docs-memory = (mkBootTest { });
+  docs-sled = (mkBootTest {
+    blobServiceAddr = "sled://$PWD/blobs.sled";
+    directoryServiceAddr = "sled://$PWD/directories.sled";
+    pathInfoServiceAddr = "sled://$PWD/pathinfo.sled";
+  });
+  docs-objectstore-local = (mkBootTest {
+    blobServiceAddr = "objectstore+file://$PWD/blobs";
+  });
 }