summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-05-28 09:54:29 +0000
committerAlyssa Ross <hi@alyssa.is>2023-05-31 10:27:22 +0000
commit997d39121cdb61bf2ba0852839e65f8adf633209 (patch)
tree419f3d1ef25d107a5218d252f5f422a19008a06e
parentce93e1cd22a40e4f0e678808c53031a889c4677b (diff)
downloadspectrum-997d39121cdb61bf2ba0852839e65f8adf633209.tar
spectrum-997d39121cdb61bf2ba0852839e65f8adf633209.tar.gz
spectrum-997d39121cdb61bf2ba0852839e65f8adf633209.tar.bz2
spectrum-997d39121cdb61bf2ba0852839e65f8adf633209.tar.lz
spectrum-997d39121cdb61bf2ba0852839e65f8adf633209.tar.xz
spectrum-997d39121cdb61bf2ba0852839e65f8adf633209.tar.zst
spectrum-997d39121cdb61bf2ba0852839e65f8adf633209.zip
vm-lib/make-vm.nix: switch to EROFS
Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rw-r--r--img/app/etc/fstab2
-rwxr-xr-ximg/app/etc/s6-linux-init/scripts/rc.init7
-rwxr-xr-xscripts/make-erofs.sh59
-rw-r--r--vm-lib/make-vm.nix13
4 files changed, 71 insertions, 10 deletions
diff --git a/img/app/etc/fstab b/img/app/etc/fstab
index 95bfe2b..c3afaba 100644
--- a/img/app/etc/fstab
+++ b/img/app/etc/fstab
@@ -4,5 +4,5 @@ proc		/proc		proc	defaults					0	0
 devpts		/dev/pts	devpts	defaults,gid=4,mode=620				0	0
 tmpfs		/dev/shm	tmpfs	defaults					0	0
 sysfs		/sys		sysfs	defaults					0	0
-LABEL=ext	/run/ext	ext4	ro						0	0
+LABEL=ext	/run/ext	erofs	ro						0	0
 store		/nix/store	overlay	ro,lowerdir=/nix/store:/run/ext/nix/store	0	0
diff --git a/img/app/etc/s6-linux-init/scripts/rc.init b/img/app/etc/s6-linux-init/scripts/rc.init
index b46afb7..8e9741c 100755
--- a/img/app/etc/s6-linux-init/scripts/rc.init
+++ b/img/app/etc/s6-linux-init/scripts/rc.init
@@ -1,11 +1,14 @@
 #!/bin/execlineb -P
 # SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2020-2022 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2020-2023 Alyssa Ross <hi@alyssa.is>
 
 if { s6-rc-init -c /etc/s6-rc /run/service }
 
 if { mkdir -p /dev/pts /dev/shm }
-if { modprobe overlay }
+if {
+  forx -pE module { erofs overlay }
+  modprobe $module
+}
 if { mount -a }
 
 s6-rc change ok-all
diff --git a/scripts/make-erofs.sh b/scripts/make-erofs.sh
new file mode 100755
index 0000000..d671bbe
--- /dev/null
+++ b/scripts/make-erofs.sh
@@ -0,0 +1,59 @@
+#!/bin/sh -eu
+#
+# SPDX-FileCopyrightText: 2023 Alyssa Ross <hi@alyssa.is>
+# SPDX-License-Identifier: EUPL-1.2+
+#
+# FIXME: It would be nice to replace this script with a program that
+#        didn't have to redundantly copy everything so it's all in a
+#        single directory structure, and could generate an EROFS image
+#        based on source:dest mappings directly.
+
+ex_usage() {
+	echo "Usage: make-erofs.sh [options]... -- img [source dest]..." >&2
+	exit 1
+}
+
+opt_count=0
+while [ $# -gt $opt_count ]; do
+	arg1="$1"
+	shift
+
+        if [ -z "${img-}" ]; then
+		set -- "$@" "$arg1"
+		opt_count=$((opt_count + 1))
+
+		if [ "$arg1" = -- ]; then
+			img="$1"
+			shift
+
+			if [ $(($# % 2)) -eq 0 ]; then
+				ex_usage
+			fi
+
+			root="$(mktemp -d -- "$img.tmp.XXXXXXXXXX")"
+			trap 'chmod -R +w -- "$root" && rm -rf -- "$root"' EXIT
+		fi
+
+		continue
+	fi
+
+	arg2="$1"
+	shift
+
+	printf "%s" "$arg1"
+	if [ "${arg1#/}" != "${arg2#/}" ]; then
+		printf " -> %s" "$arg2"
+	fi
+	echo
+
+	parent="$root/$(dirname "$arg2")"
+	chmod -R +w -- "$root"
+	mkdir -p -- "$parent"
+	cp -RT -- "$arg1" "$root/$arg2"
+done
+
+if [ -z "${img-}" ]; then
+	ex_usage
+fi
+
+mkfs.erofs "$@" "$img" "$root"
diff --git a/vm-lib/make-vm.nix b/vm-lib/make-vm.nix
index 61e0b2d..45ff78d 100644
--- a/vm-lib/make-vm.nix
+++ b/vm-lib/make-vm.nix
@@ -11,7 +11,7 @@
 
 pkgs.pkgsStatic.callPackage (
 
-{ lib, runCommand, writeReferencesToFile, e2fsprogs, tar2ext4 }:
+{ lib, runCommand, writeReferencesToFile, erofs-utils }:
 
 { run, providers ? {}, sharedDirs ? {} }:
 
@@ -24,7 +24,7 @@ in
 assert !(any (hasInfix "\n") (concatLists (attrValues providers)));
 
 runCommand "spectrum-vm" {
-  nativeBuildInputs = [ e2fsprogs tar2ext4 ];
+  nativeBuildInputs = [ erofs-utils ];
 
   providerDirs = concatStrings (concatLists
     (mapAttrsToList (kind: map (vm: "${kind}/${vm}\n")) providers));
@@ -35,11 +35,10 @@ runCommand "spectrum-vm" {
   mkdir root
   cd root
   ln -s ${run} run
-  comm -23 <(sort ${writeReferencesToFile run}) \
-      <(sort ${writeReferencesToFile basePaths}) |
-      tar -cf ../run.tar --verbatim-files-from -T - run
-  tar2ext4 -i ../run.tar -o "$out/blk/run.img"
-  e2label "$out/blk/run.img" ext
+
+  ${../scripts/make-erofs.sh} -L ext -- "$out/blk/run.img" run run \
+      $(comm -23 <(sort ${writeReferencesToFile run}) \
+          <(sort ${writeReferencesToFile basePaths}) | sed p)
 
   pushd "$out"