summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-05-27 22:33:31 +0000
committerAlyssa Ross <hi@alyssa.is>2023-05-31 10:27:32 +0000
commit75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc (patch)
treeed4888ea0aa2470ea99e5d9df2db85322a309285
parent997d39121cdb61bf2ba0852839e65f8adf633209 (diff)
downloadspectrum-75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc.tar
spectrum-75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc.tar.gz
spectrum-75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc.tar.bz2
spectrum-75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc.tar.lz
spectrum-75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc.tar.xz
spectrum-75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc.tar.zst
spectrum-75a1ac3d62bf8c641e7145f46ebd6e9d01e6d3dc.zip
vm: switch to EROFS
-rw-r--r--img/app/Makefile17
-rw-r--r--img/app/default.nix22
-rwxr-xr-ximg/app/etc/s6-linux-init/scripts/rc.init7
-rw-r--r--vm/sys/net/Makefile17
-rw-r--r--vm/sys/net/default.nix22
5 files changed, 40 insertions, 45 deletions
diff --git a/img/app/Makefile b/img/app/Makefile
index 2414c45..3e2c0ce 100644
--- a/img/app/Makefile
+++ b/img/app/Makefile
@@ -19,10 +19,10 @@ $(imgdir)/appvm/vmlinux: $(KERNEL)
 	mkdir -p $$(dirname $@)
 	cp $(KERNEL) $@
 
-$(imgdir)/appvm/blk/root.img: ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/rootfs.ext4
+$(imgdir)/appvm/blk/root.img: ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/rootfs.erofs
 	mkdir -p $$(dirname $@)
 	../../scripts/make-gpt.sh $@.tmp \
-	    build/rootfs.ext4:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:5460386f-2203-4911-8694-91400125c604:root
+	    build/rootfs.erofs:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:5460386f-2203-4911-8694-91400125c604:root
 	mv $@.tmp $@
 
 VM_FILES = \
@@ -50,14 +50,11 @@ VM_BUILD_FILES = build/etc/s6-rc
 build/empty:
 	mkdir -p $@
 
-build/rootfs.tar: build/empty $(PACKAGES_TAR) $(VM_FILES) $(VM_BUILD_FILES)
-	cp --no-preserve=mode -f $(PACKAGES_TAR) $@
-	tar $(TARFLAGS) --append -f $@ $(VM_FILES) $(VM_LINKS)
-	echo $(VM_BUILD_FILES) | cut -d/ -f2 | \
-	    tar $(TARFLAGS) --append -f $@ -C build -T -
-	for m in $(VM_DIRS); do \
-	    tar $(TARFLAGS) --append -hf $@ --xform="s,.*,$$m," build/empty ; \
-	done
+build/rootfs.erofs: ../../scripts/make-erofs.sh $(VM_FILES) $(VM_BUILD_FILES) build/empty
+	../../scripts/make-erofs.sh -- $@ $(PACKAGES) \
+	    $$(for file in $(VM_FILES) $(VM_LINKS); do printf '%s %s ' $$file $$file; done) \
+	    $$(for file in $(VM_BUILD_FILES); do printf '%s %s ' $$file $${file#build/}; done) \
+	    $$(printf 'build/empty %s ' $(VM_DIRS))
 
 VM_S6_RC_FILES = \
 	etc/s6-rc/app/run \
diff --git a/img/app/default.nix b/img/app/default.nix
index 7bcb2dd..ab87eda 100644
--- a/img/app/default.nix
+++ b/img/app/default.nix
@@ -12,7 +12,7 @@ import ../../lib/eval-config.nix (
 config.pkgs.pkgsStatic.callPackage (
 
 { lib, stdenvNoCC, runCommand, writeReferencesToFile, buildPackages
-, jq, s6-rc, tar2ext4, util-linux
+, erofs-utils, jq, s6-rc, util-linux
 , busybox, cacert, execline, kmod, mdevd, s6, s6-linux-init
 }:
 
@@ -45,12 +45,6 @@ let
     ln -s ${cacert}/etc/ssl $out/usr/share
   '';
 
-  packagesTar = runCommand "packages.tar" {} ''
-    cd ${packagesSysroot}
-    tar -cf $out --verbatim-files-from \
-        -T ${writeReferencesToFile packagesSysroot} .
-  '';
-
   kernelTarget =
     if stdenvNoCC.hostPlatform.isx86 then
       # vmlinux.bin is the stripped version of vmlinux.
@@ -69,7 +63,7 @@ let
       VIRTIO_PCI = yes;
       VIRTIO_BLK = yes;
       VIRTIO_CONSOLE = yes;
-      EXT4_FS = yes;
+      EROFS_FS = yes;
       EXPERT = yes;
       FONTS = lib.mkForce unset;
       FONT_8x8 = lib.mkForce unset;
@@ -92,11 +86,19 @@ stdenvNoCC.mkDerivation {
   inherit src;
   sourceRoot = "source/img/app";
 
-  nativeBuildInputs = [ jq lseek s6-rc tar2ext4 util-linux ];
+  nativeBuildInputs = [ erofs-utils jq lseek s6-rc util-linux ];
 
-  PACKAGES_TAR = packagesTar;
+  PACKAGES = [ packagesSysroot "/" ];
   KERNEL = "${kernel}/${baseNameOf kernelTarget}";
 
+  shellHook = ''
+    PACKAGES+=" $(sed p ${writeReferencesToFile packagesSysroot} | tr '\n' ' ')"
+  '';
+
+  preBuild = ''
+    runHook shellHook
+  '';
+
   makeFlags = [ "prefix=$(out)" ];
 
   dontInstall = true;
diff --git a/img/app/etc/s6-linux-init/scripts/rc.init b/img/app/etc/s6-linux-init/scripts/rc.init
index 8e9741c..b46afb7 100755
--- a/img/app/etc/s6-linux-init/scripts/rc.init
+++ b/img/app/etc/s6-linux-init/scripts/rc.init
@@ -1,14 +1,11 @@
 #!/bin/execlineb -P
 # SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2020-2023 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2020-2022 Alyssa Ross <hi@alyssa.is>
 
 if { s6-rc-init -c /etc/s6-rc /run/service }
 
 if { mkdir -p /dev/pts /dev/shm }
-if {
-  forx -pE module { erofs overlay }
-  modprobe $module
-}
+if { modprobe overlay }
 if { mount -a }
 
 s6-rc change ok-all
diff --git a/vm/sys/net/Makefile b/vm/sys/net/Makefile
index 45d19d1..50c7b29 100644
--- a/vm/sys/net/Makefile
+++ b/vm/sys/net/Makefile
@@ -28,10 +28,10 @@ build/host/data/netvm/vmlinux: $(KERNEL)
 	mkdir -p $$(dirname $@)
 	cp $(KERNEL) $@
 
-build/host/data/netvm/blk/root.img: ../../../scripts/make-gpt.sh ../../../scripts/sfdisk-field.awk build/rootfs.ext4
+build/host/data/netvm/blk/root.img: ../../../scripts/make-gpt.sh ../../../scripts/sfdisk-field.awk build/rootfs.erofs
 	mkdir -p $$(dirname $@)
 	../../../scripts/make-gpt.sh $@.tmp \
-	    build/rootfs.ext4:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:ea21da27-0391-48da-9235-9d2ab2ca7844:root
+	    build/rootfs.erofs:4f68bce3-e8cd-4db1-96e7-fbcaf984b709:ea21da27-0391-48da-9235-9d2ab2ca7844:root
 	mv $@.tmp $@
 
 VM_FILES = \
@@ -56,14 +56,11 @@ VM_BUILD_FILES = build/etc/s6-rc
 build/empty:
 	mkdir -p $@
 
-build/rootfs.tar: build/empty $(PACKAGES_TAR) $(VM_FILES) $(VM_BUILD_FILES)
-	cp --no-preserve=mode -f $(PACKAGES_TAR) $@
-	tar $(TARFLAGS) --append -f $@ $(VM_FILES) $(VM_LINKS)
-	echo $(VM_BUILD_FILES) | cut -d/ -f2 | \
-	    tar $(TARFLAGS) --append -f $@ -C build -T -
-	for m in $(VM_DIRS); do \
-	    tar $(TARFLAGS) --append -hf $@ --xform="s,.*,$$m," build/empty ; \
-	done
+build/rootfs.erofs: ../../../scripts/make-erofs.sh $(VM_FILES) $(VM_BUILD_FILES) build/empty
+	../../../scripts/make-erofs.sh -- $@ $(PACKAGES) \
+	    $$(for file in $(VM_FILES) $(VM_LINKS); do printf '%s %s ' $$file $$file; done) \
+	    $$(for file in $(VM_BUILD_FILES); do printf '%s %s ' $$file $${file#build/}; done) \
+	    $$(printf 'build/empty %s ' $(VM_DIRS))
 
 VM_S6_RC_FILES = \
 	etc/s6-rc/connman/dependencies \
diff --git a/vm/sys/net/default.nix b/vm/sys/net/default.nix
index c43f347..98749d1 100644
--- a/vm/sys/net/default.nix
+++ b/vm/sys/net/default.nix
@@ -12,7 +12,7 @@ import ../../../lib/eval-config.nix (
 config.pkgs.pkgsStatic.callPackage (
 
 { lib, stdenvNoCC, runCommand, writeReferencesToFile, buildPackages
-, jq, s6-rc, tar2ext4, util-linux, xorg
+, erofs-utils, jq, s6-rc, util-linux, xorg
 , busybox, connmanMinimal, dbus, execline, kmod, mdevd, nftables, s6
 , s6-linux-init
 }:
@@ -54,12 +54,6 @@ let
     done
   '';
 
-  packagesTar = runCommand "packages.tar" {} ''
-    cd ${packagesSysroot}
-    tar -cf $out --verbatim-files-from \
-        -T ${writeReferencesToFile packagesSysroot} .
-  '';
-
   kernelTarget =
     if stdenvNoCC.hostPlatform.isx86 then
       # vmlinux.bin is the stripped version of vmlinux.
@@ -78,7 +72,7 @@ let
       VIRTIO_PCI = yes;
       VIRTIO_BLK = yes;
       VIRTIO_CONSOLE = yes;
-      EXT4_FS = yes;
+      EROFS_FS = yes;
       EXPERT = yes;
       FONTS = lib.mkForce unset;
       FONT_8x8 = lib.mkForce unset;
@@ -101,11 +95,19 @@ stdenvNoCC.mkDerivation {
   inherit src;
   sourceRoot = "source/vm/sys/net";
 
-  nativeBuildInputs = [ jq lseek s6-rc tar2ext4 util-linux ];
+  nativeBuildInputs = [ erofs-utils jq lseek s6-rc util-linux ];
 
-  PACKAGES_TAR = packagesTar;
+  PACKAGES = [ packagesSysroot "/" ];
   KERNEL = "${kernel}/${baseNameOf kernelTarget}";
 
+  shellHook = ''
+    PACKAGES+=" $(sed p ${writeReferencesToFile packagesSysroot} | tr '\n' ' ')"
+  '';
+
+  preBuild = ''
+    runHook shellHook
+  '';
+
   makeFlags = [ "prefix=$(out)" ];
 
   dontInstall = true;