commit a9d847e2c0a76ff01cb9eb026237cc227e2d8618
parent 6bbff2f5b34967b7202c56658791f5e59df5c055
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 6 Nov 2023 21:52:31 +0000
add ext4 as rootfsType
Diffstat:
6 files changed, 103 insertions(+), 2 deletions(-)
diff --git a/modules/base.nix b/modules/base.nix
@@ -39,7 +39,12 @@ in {
};
rootfsType = mkOption {
default = "squashfs";
- type = types.enum ["squashfs" "jffs2" "ubifs"];
+ type = types.enum [
+ "ext4"
+ "jffs2"
+ "squashfs"
+ "ubifs"
+ ];
};
boot = {
commandLine = mkOption {
diff --git a/modules/ext4fs.nix b/modules/ext4fs.nix
@@ -0,0 +1,45 @@
+{
+ config
+, pkgs
+, lib
+, ...
+}:
+let
+ inherit (lib) mkIf mkOption types;
+in
+{
+ imports = [
+ ./initramfs.nix
+ ];
+ config = mkIf (config.rootfsType == "ext4") {
+ kernel.config = {
+ EXT4_FS = "y";
+ EXT4_USE_FOR_EXT2 = "y";
+ FS_ENCRYPTION = "y";
+ };
+ boot.initramfs.enable = true;
+ system.outputs = rec {
+ systemConfiguration =
+ pkgs.systemconfig config.filesystem.contents;
+ rootfs =
+ let
+ inherit (pkgs.pkgsBuildBuild) runCommand e2fsprogs;
+ in runCommand "mkfs.ext4" {
+ depsBuildBuild = [ e2fsprogs ];
+ } ''
+ mkdir -p $TMPDIR/empty/nix/store/ $TMPDIR/empty/secrets
+ cp ${systemConfiguration}/bin/activate $TMPDIR/empty/activate
+ ln -s ${pkgs.s6-init-bin}/bin/init $TMPDIR/empty/init
+ mkdir -p $TMPDIR/empty/nix/store
+ for path in $(cat ${systemConfiguration}/etc/nix-store-paths) ; do
+ (cd $TMPDIR/empty && cp -a $path .$path)
+ done
+ size=$(du -s --apparent-size --block-size 1024 $TMPDIR/empty |cut -f1)
+ # add 25% for filesystem overhead
+ size=$(( 5 * $size / 4))
+ dd if=/dev/zero of=$out bs=1024 count=$size
+ mke2fs -t ext4 -j -d $TMPDIR/empty $out
+ '';
+ };
+ };
+}
diff --git a/tests/ci.nix b/tests/ci.nix
@@ -3,7 +3,8 @@
pseudofiles = import ./pseudofiles/test.nix;
wlan = import ./wlan/test.nix;
pppoe = import ./pppoe/test.nix;
- jffs2 = import ./jffs2/test.nix;
+ jffs2 = import ./jffs2/test.nix;
+ ext4 = import ./ext4/test.nix;
min-copy-closure = import ./min-copy-closure/test.nix;
fennel = import ./fennel/test.nix;
}
diff --git a/tests/ext4/configuration.nix b/tests/ext4/configuration.nix
@@ -0,0 +1,19 @@
+{ config, pkgs, lib, ... } :
+let
+ inherit (pkgs.pseudofile) dir symlink;
+in {
+ imports = [
+ ../../vanilla-configuration.nix
+ ../../modules/squashfs.nix
+ ../../modules/ext4fs.nix
+ ];
+ config.rootfsType = "ext4";
+ config.filesystem = dir {
+ hello = {
+ type = "f";
+ uid = 7;
+ gid = 24;
+ file = "hello world";
+ };
+ };
+}
diff --git a/tests/ext4/script.expect b/tests/ext4/script.expect
@@ -0,0 +1,11 @@
+set timeout 10
+
+spawn socat unix-connect:vm/console -
+send "\r\n"
+expect "login:" { send "root\r\n" }
+expect "#"
+send "echo HELLO WORLD > /hello\r\n"
+expect "#"
+send "cat /hello\r\n"
+expect 'HELLO WORLD'
+close
+\ No newline at end of file
diff --git a/tests/ext4/test.nix b/tests/ext4/test.nix
@@ -0,0 +1,19 @@
+{
+ liminix
+, nixpkgs
+}:
+let img = (import liminix {
+ device = import "${liminix}/devices/qemu/";
+ liminix-config = ./configuration.nix;
+ }).outputs.vmroot;
+ pkgs = import <nixpkgs> { overlays = [(import ../../overlay.nix)]; };
+in pkgs.runCommand "check" {
+ nativeBuildInputs = with pkgs; [
+ expect
+ socat
+ ] ;
+} ''
+mkdir vm
+${img}/run.sh --background ./vm
+expect ${./script.expect} >$out
+''