From 42725f56f9653f3998a684775e08d348b212556c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 10 Apr 2023 19:59:09 +0100 Subject: [PATCH] make jffs2 module provide o.rootfs, conditionally it's enabled if config.rootfsType == "jffs2" --- modules/base.nix | 7 ++++++- modules/jffs2.nix | 8 +++++--- modules/outputs.nix | 6 ++++-- modules/squashfs.nix | 17 +++++++++++++++++ tests/jffs2/configuration.nix | 1 + 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 modules/squashfs.nix diff --git a/modules/base.nix b/modules/base.nix index 7015b0f..bd249f6 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -25,6 +25,10 @@ in { type = types.attrsOf type_service; }; filesystem = mkOption { type = types.anything; }; + rootfsType = mkOption { + default = "squashfs"; + type = types.str; + }; kernel = { src = mkOption { type = types.package; } ; extraPatchPhase = mkOption { @@ -107,7 +111,8 @@ in { }; }; boot.commandLine = [ - "console=ttyS0,115200 panic=10 oops=panic init=/bin/init loglevel=8 rootfstype=squashfs" + "console=ttyS0,115200 panic=10 oops=panic init=/bin/init loglevel=8" + "rootfstype=${config.rootfsType}" "fw_devlink=off" ]; users.root = { diff --git a/modules/jffs2.nix b/modules/jffs2.nix index 69d6a82..deca6fd 100644 --- a/modules/jffs2.nix +++ b/modules/jffs2.nix @@ -1,22 +1,24 @@ { config , pkgs +, lib , ... }: let inherit (pkgs) closureInfo; + inherit (lib) mkIf; in { imports = [ ./initramfs.nix ]; - config = { + config = mkIf (config.rootfsType == "jffs2") { kernel.config.JFFS2_FS = "y"; boot.initramfs.enable = true; outputs = rec { systemConfiguration = pkgs.pkgsBuildBuild.systemconfig config.filesystem.contents; - jffs2fs = + rootfs = let inherit (pkgs.pkgsBuildBuild) runCommand mtdutils; endian = if pkgs.stdenv.isBigEndian @@ -38,7 +40,7 @@ in pkgs.runCommand "jffs2boot" {} '' mkdir $out cd $out - ln -s ${o.jffs2fs} rootfs + ln -s ${o.rootfs} rootfs ln -s ${o.kernel} vmlinux ln -s ${o.manifest} manifest ln -s ${o.initramfs} initramfs diff --git a/modules/outputs.nix b/modules/outputs.nix index 2326f38..dbb4a33 100644 --- a/modules/outputs.nix +++ b/modules/outputs.nix @@ -9,6 +9,9 @@ let inherit (pkgs) liminix callPackage writeText; in { + imports = [ + ./squashfs.nix + ]; options = { outputs = mkOption { type = types.attrsOf types.package; @@ -17,7 +20,6 @@ in }; config = { outputs = rec { - rootfs = liminix.builders.squashfs config.filesystem.contents; tftpd = pkgs.buildPackages.tufted; kernel = liminix.builders.kernel.override { inherit (config.kernel) config src extraPatchPhase; @@ -38,7 +40,7 @@ in vmroot = pkgs.runCommand "qemu" {} '' mkdir $out cd $out - ln -s ${rootfs} rootfs + ln -s ${config.outputs.rootfs} rootfs ln -s ${kernel} vmlinux ln -s ${manifest} manifest ln -s ${kernel.headers} build diff --git a/modules/squashfs.nix b/modules/squashfs.nix new file mode 100644 index 0000000..a543d33 --- /dev/null +++ b/modules/squashfs.nix @@ -0,0 +1,17 @@ +{ + config +, pkgs +, lib +, ... +}: +let + inherit (pkgs) liminix; + inherit (lib) mkIf; +in +{ + config = mkIf (config.rootfsType == "squashfs") { + outputs = rec { + rootfs = liminix.builders.squashfs config.filesystem.contents; + }; + }; +} diff --git a/tests/jffs2/configuration.nix b/tests/jffs2/configuration.nix index b5b739c..1404579 100644 --- a/tests/jffs2/configuration.nix +++ b/tests/jffs2/configuration.nix @@ -4,4 +4,5 @@ ../../vanilla-configuration.nix ../../modules/jffs2.nix ]; + config.rootfsType = "jffs2"; }