2024-03-17 21:00:44 +01:00
|
|
|
{ depot, pkgs, lib, ... }:
|
2023-09-25 12:59:25 +02:00
|
|
|
|
2024-03-11 23:07:46 +01:00
|
|
|
let
|
2023-09-25 12:59:25 +02:00
|
|
|
# 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.
|
2024-03-17 21:00:44 +01:00
|
|
|
mkBootTest =
|
|
|
|
{ blobServiceAddr ? "memory://"
|
|
|
|
, directoryServiceAddr ? "memory://"
|
|
|
|
, pathInfoServiceAddr ? "memory://"
|
2024-03-18 10:41:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
# The path to import.
|
|
|
|
, path
|
|
|
|
|
|
|
|
# Whether the path should be imported as a closure.
|
|
|
|
# If false, importPathName must be specified.
|
|
|
|
, isClosure ? false
|
|
|
|
, importPathName ? null
|
|
|
|
|
2024-03-18 11:08:47 +01:00
|
|
|
# The cmdline to pass to the VM.
|
|
|
|
# Defaults to tvix.find, which lists all files in the store.
|
|
|
|
, vmCmdline ? "tvix.find"
|
|
|
|
# The string we expect to find in the VM output.
|
|
|
|
# Defaults the value of `path` (the store path we upload).
|
|
|
|
, assertVMOutput ? path
|
2024-03-17 21:00:44 +01:00
|
|
|
}:
|
2024-03-18 10:41:29 +01:00
|
|
|
|
|
|
|
assert isClosure -> importPathName == null;
|
|
|
|
assert (!isClosure) -> importPathName != null;
|
|
|
|
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "run-vm";
|
|
|
|
|
2024-04-12 19:27:15 +02:00
|
|
|
__structuredAttrs = true;
|
|
|
|
exportReferencesGraph.closure = [ path ];
|
|
|
|
|
2024-03-18 10:41:29 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
depot.tvix.store
|
|
|
|
depot.tvix.boot.runVM
|
|
|
|
];
|
|
|
|
buildCommand = ''
|
|
|
|
touch $out
|
|
|
|
|
|
|
|
# Start the tvix daemon, listening on a unix socket.
|
|
|
|
BLOB_SERVICE_ADDR=${blobServiceAddr} \
|
|
|
|
DIRECTORY_SERVICE_ADDR=${directoryServiceAddr} \
|
|
|
|
PATH_INFO_SERVICE_ADDR=${pathInfoServiceAddr} \
|
2024-03-18 11:07:56 +01:00
|
|
|
tvix-store \
|
|
|
|
--otlp=false \
|
|
|
|
daemon -l $PWD/tvix-store.sock &
|
2024-03-18 10:41:29 +01:00
|
|
|
|
|
|
|
# Wait for the socket to be created.
|
|
|
|
while [ ! -e $PWD/tvix-store.sock ]; do sleep 1; done
|
|
|
|
|
|
|
|
# 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.sock
|
|
|
|
export DIRECTORY_SERVICE_ADDR=grpc+unix://$PWD/tvix-store.sock
|
|
|
|
export PATH_INFO_SERVICE_ADDR=grpc+unix://$PWD/tvix-store.sock
|
|
|
|
'' + lib.optionalString (!isClosure) ''
|
|
|
|
echo "Importing ${path} into tvix-store with name ${importPathName}…"
|
|
|
|
cp -R ${path} ${importPathName}
|
|
|
|
outpath=$(tvix-store import ${importPathName})
|
|
|
|
|
|
|
|
echo "imported to $outpath"
|
|
|
|
'' + lib.optionalString (isClosure) ''
|
2024-04-12 19:27:15 +02:00
|
|
|
echo "Copying closure ${path}…"
|
|
|
|
# This picks up the `closure` key in `$NIX_ATTRS_JSON_FILE` automatically.
|
|
|
|
tvix-store --otlp=false copy
|
2024-03-18 10:41:29 +01:00
|
|
|
'' + ''
|
|
|
|
# Invoke a VM using tvix as the backing store, ensure the outpath appears in its listing.
|
2024-03-18 11:09:49 +01:00
|
|
|
echo "Starting VM…"
|
2024-03-18 10:41:29 +01:00
|
|
|
|
2024-03-18 11:08:47 +01:00
|
|
|
CH_CMDLINE="${vmCmdline}" run-tvix-vm 2>&1 | tee output.txt
|
|
|
|
grep "${assertVMOutput}" output.txt
|
2024-03-18 10:41:29 +01:00
|
|
|
'';
|
|
|
|
requiredSystemFeatures = [ "kvm" ];
|
|
|
|
};
|
2024-03-18 11:09:49 +01:00
|
|
|
|
|
|
|
systemFor = sys: (depot.ops.nixos.nixosFor sys).system;
|
|
|
|
|
|
|
|
testSystem = systemFor ({ modulesPath, pkgs, ... }: {
|
|
|
|
# Set some options necessary to evaluate.
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
# TODO: figure out how to disable this without causing eval to fail
|
|
|
|
fileSystems."/" = {
|
|
|
|
device = "/dev/root";
|
|
|
|
fsType = "tmpfs";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.getty.helpLine = "Onwards and upwards.";
|
|
|
|
systemd.services.do-shutdown = {
|
|
|
|
after = [ "getty.target" ];
|
|
|
|
description = "Shut down again";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = "/run/current-system/sw/bin/systemctl poweroff --when=+10s";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Don't warn about stateVersion.
|
|
|
|
system.stateVersion = "24.05";
|
|
|
|
});
|
|
|
|
|
2024-03-11 23:07:46 +01:00
|
|
|
in
|
2024-03-18 10:41:29 +01:00
|
|
|
depot.nix.readTree.drvTargets
|
|
|
|
{
|
|
|
|
docs-memory = (mkBootTest {
|
|
|
|
path = ../../docs;
|
|
|
|
importPathName = "docs";
|
|
|
|
});
|
2024-03-17 21:00:44 +01:00
|
|
|
docs-sled = (mkBootTest {
|
|
|
|
blobServiceAddr = "sled://$PWD/blobs.sled";
|
|
|
|
directoryServiceAddr = "sled://$PWD/directories.sled";
|
|
|
|
pathInfoServiceAddr = "sled://$PWD/pathinfo.sled";
|
2024-03-18 10:41:29 +01:00
|
|
|
path = ../../docs;
|
|
|
|
importPathName = "docs";
|
2024-03-17 21:00:44 +01:00
|
|
|
});
|
|
|
|
docs-objectstore-local = (mkBootTest {
|
|
|
|
blobServiceAddr = "objectstore+file://$PWD/blobs";
|
2024-03-18 10:41:29 +01:00
|
|
|
path = ../../docs;
|
|
|
|
importPathName = "docs";
|
|
|
|
});
|
|
|
|
|
|
|
|
closure-tvix = (mkBootTest {
|
|
|
|
blobServiceAddr = "objectstore+file://$PWD/blobs";
|
|
|
|
path = depot.tvix.store;
|
|
|
|
isClosure = true;
|
2024-03-17 21:00:44 +01:00
|
|
|
});
|
2024-03-18 11:09:49 +01:00
|
|
|
|
|
|
|
closure-nixos = (mkBootTest {
|
|
|
|
blobServiceAddr = "objectstore+file://$PWD/blobs";
|
|
|
|
path = testSystem;
|
|
|
|
isClosure = true;
|
|
|
|
vmCmdline = "init=${testSystem}/init panic=-1"; # reboot immediately on panic
|
|
|
|
assertVMOutput = "Onwards and upwards.";
|
|
|
|
});
|
2023-09-25 12:59:25 +02:00
|
|
|
}
|