summary refs log tree commit diff
path: root/pkgs/os-specific/linux/spectrum/spectrum-vm
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-04-21 19:28:29 +0000
committerAlyssa Ross <hi@alyssa.is>2020-04-22 16:42:10 +0000
commit817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff (patch)
tree8b42c11b35a68613f76c323e8d4af99fc08d9c05 /pkgs/os-specific/linux/spectrum/spectrum-vm
parent48c645aed80cf14cae8cad9053616ee9eb7a33cd (diff)
downloadnixpkgs-817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff.tar
nixpkgs-817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff.tar.gz
nixpkgs-817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff.tar.bz2
nixpkgs-817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff.tar.lz
nixpkgs-817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff.tar.xz
nixpkgs-817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff.tar.zst
nixpkgs-817a1a9b0de30d8bbc2ad2e80a802d87c56e96ff.zip
spectrumPackages: init
This is a modular version of what was previously start-vm.nix.  It
introduces a program, spectrum-vm, that allows for customising the
crosvm, kernel, and rootfs paths.  And, it can run a custom command
inside the VM!  I think this is going to be a big improvement over
start-vm.nix.
Diffstat (limited to 'pkgs/os-specific/linux/spectrum/spectrum-vm')
-rw-r--r--pkgs/os-specific/linux/spectrum/spectrum-vm/default.nix35
-rwxr-xr-xpkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in67
2 files changed, 102 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/spectrum/spectrum-vm/default.nix b/pkgs/os-specific/linux/spectrum/spectrum-vm/default.nix
new file mode 100644
index 00000000000..56f1eadea99
--- /dev/null
+++ b/pkgs/os-specific/linux/spectrum/spectrum-vm/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, lib, makeWrapper, utillinux, crosvm, linux, rootfs }:
+
+stdenv.mkDerivation {
+  name = "spectrum-vm";
+
+  src = ./spectrum-vm.in;
+
+  nativeBuildInputs = [ makeWrapper ];
+
+  unpackPhase = ''
+    cp $src spectrum-vm.in
+  '';
+
+  configurePhase = ''
+    substituteAll spectrum-vm.in spectrum-vm
+    chmod +x spectrum-vm
+  '';
+
+  getopt = "${lib.getBin utillinux}/bin/getopt";
+  crosvm = "${lib.getBin crosvm}/bin/crosvm";
+  kernel = "${linux}/bzImage";
+  rootfs = rootfs.squashfs;
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp spectrum-vm $out/bin
+  '';
+
+  meta = with lib; {
+    description = "Utility for testing Spectrum VM components";
+    maintainers = with maintainers; [ qyliss ];
+    license = licenses.gpl3Plus;
+    inherit (crosvm.meta) platforms;
+  };
+}
diff --git a/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in b/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in
new file mode 100755
index 00000000000..97cb5dbfa58
--- /dev/null
+++ b/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in
@@ -0,0 +1,67 @@
+#!@shell@
+set -ue
+
+ex_usage() {
+    cat <<EOF
+Usage: $(basename "$0") [OPTION]...
+
+  -c COMMAND         shell command to run inside VM
+  -C, --crosvm PATH  path to custom crosvm executable
+  -k, --kernel PATH  path to custom kernel image
+  -f, --rootfs PATH  path to custom root file system image
+EOF
+    exit "$1"
+}
+
+args="$(@getopt@ -s sh -l crosvm:,help,kernel:,rootfs: -o c:C:hk:f: -- "$@" || exit 1)"
+eval set -- "$args"
+
+command=
+crosvm=@crosvm@
+kernel=@kernel@
+rootfs=@rootfs@
+
+while :
+do
+    case "$1" in
+	-c)
+	    shift
+	    command="$1"
+	    shift
+	    ;;
+        -C|--crosvm)
+            shift
+            crosvm="$1"
+	    shift
+            ;;
+	-h|--help)
+	    ex_usage 0
+	    ;;
+        -k|--kernel)
+            shift
+            kernel="$1"
+	    shift
+            ;;
+        -f|--rootfs)
+            shift
+            rootfs="$1"
+	    shift
+            ;;
+        --)
+            shift
+            break
+            ;;
+    esac
+done
+
+if [ "$#" -ne 0 ]; then
+    ex_usage 1 >&2
+fi
+
+exec "$crosvm" run \
+    --wayland-sock "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" \
+    -s "$XDG_RUNTIME_DIR" \
+    -p init=/sbin/init \
+    -p "spectrumcmd=$(printf %s "$command" | base64)" \
+    --root "$rootfs" \
+    "$kernel"