liminix/modules/jffs2.nix
Daniel Barlow 42725f56f9 make jffs2 module provide o.rootfs, conditionally
it's enabled if config.rootfsType == "jffs2"
2023-04-10 20:01:58 +01:00

50 lines
1.4 KiB
Nix

{
config
, pkgs
, lib
, ...
}:
let
inherit (pkgs) closureInfo;
inherit (lib) mkIf;
in
{
imports = [
./initramfs.nix
];
config = mkIf (config.rootfsType == "jffs2") {
kernel.config.JFFS2_FS = "y";
boot.initramfs.enable = true;
outputs = rec {
systemConfiguration =
pkgs.pkgsBuildBuild.systemconfig config.filesystem.contents;
rootfs =
let
inherit (pkgs.pkgsBuildBuild) runCommand mtdutils;
endian = if pkgs.stdenv.isBigEndian
then "--big-endian" else "--little-endian";
in runCommand "make-jffs2" {
depsBuildBuild = [ mtdutils ];
} ''
mkdir -p $TMPDIR/empty/nix/store/
cp ${systemConfiguration}/activate $TMPDIR/empty/activate
pkgClosure=${closureInfo {
rootPaths = [ systemConfiguration ];
}}
cp $pkgClosure/registration nix-path-registration
grafts=$(sed < $pkgClosure/store-paths 's/^\(.*\)$/--graft \1:\1/g')
mkfs.jffs2 ${endian} --pad --root $TMPDIR/empty --output $out $grafts
'';
jffs2boot =
let o = config.outputs; in
pkgs.runCommand "jffs2boot" {} ''
mkdir $out
cd $out
ln -s ${o.rootfs} rootfs
ln -s ${o.kernel} vmlinux
ln -s ${o.manifest} manifest
ln -s ${o.initramfs} initramfs
'';
};
};
}