[PATCH 21/22] host/initramfs/extfs.nix: add example Nix-built VM

Alyssa Ross
2022-10-10T23:32:49Z

This adds the Nix files that define a very simple VM that just runs
the "yes" command, which repeatedly prints 'y' to the console. Only
the Nix files that define the VM are added, and not the VM itself, so
it will only appear when vm-rebuild is run in appvm-nix.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
host/initramfs/extfs.nix | 11 ++++++++++-
vm/app/nix/example.nix | 13 +++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 vm/app/nix/example.nix

diff --git a/host/initramfs/extfs.nix b/host/initramfs/extfs.nix
index 9f00793..4319afb 100644
--- a/host/initramfs/extfs.nix
+++ b/host/initramfs/extfs.nix
@@ -4,6 +4,8 @@
{ config, runCommand, e2fsprogs, tar2ext4 }:

let
+ inherit (config.pkgs) lib;
+
netvm = import ../../vm/sys/net {
inherit config;
# inherit (foot) terminfo;
@@ -13,12 +15,16 @@ let
appvm-lynx = import ../../vm/app/lynx.nix { inherit config; };
appvm-mg = import ../../vm/app/mg.nix { inherit config; };
appvm-nix = import ../../vm/app/nix { inherit config; };
+
+ vmsNix = ../../vm/app/nix/example.nix;
+ spectrumNix =
+ builtins.filterSource (name: _type: lib.hasSuffix ".nix" name) ../../vm-lib;
in

runCommand "ext.ext4" {
nativeBuildInputs = [ e2fsprogs ];
} ''
- mkdir -p root/svc/data/appvm-{catgirl,lynx,mg,nix}
+ mkdir -p root/svc/data/appvm-{catgirl,lynx,mg,nix} root/vm-config
cd root

tar -C ${netvm} -c data | tar -C svc -x
@@ -29,6 +35,9 @@ runCommand "ext.ext4" {
tar -C ${appvm-mg} -c . | tar -C svc/data/appvm-mg -x
tar -C ${appvm-nix} -c . | tar -C svc/data/appvm-nix -x

+ cp ${vmsNix} vm-config/vms.nix
+ cp -R ${spectrumNix} vm-config/spectrum
+
mkfs.ext4 -d . $out 16T
resize2fs -M $out

diff --git a/vm/app/nix/example.nix b/vm/app/nix/example.nix
new file mode 100644
index 0000000..55068d1
--- /dev/null
+++ b/vm/app/nix/example.nix
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: MIT
+# SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+
+import <spectrum/make-vms.nix> {} ({ makeVm, pkgs }: {
+ appvm-yes = makeVm {
+ run = pkgs.pkgsStatic.callPackage (
+ { writeShellScript, coreutils }:
+ writeShellScript "appvm-yes-run" ''
+ ${coreutils}/bin/yes
+ ''
+ ) {};
+ };
+})
--
2.37.1