2023-04-05 00:35:49 +02:00
|
|
|
{
|
|
|
|
config
|
|
|
|
, pkgs
|
2023-04-10 20:59:09 +02:00
|
|
|
, lib
|
2023-04-05 00:35:49 +02:00
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
2023-04-07 10:39:47 +02:00
|
|
|
inherit (pkgs) closureInfo;
|
2023-04-10 20:59:09 +02:00
|
|
|
inherit (lib) mkIf;
|
2023-04-05 00:35:49 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
./initramfs.nix
|
|
|
|
];
|
2023-04-10 20:59:09 +02:00
|
|
|
config = mkIf (config.rootfsType == "jffs2") {
|
2023-04-15 18:23:58 +02:00
|
|
|
kernel.config = {
|
|
|
|
JFFS2_FS = "y";
|
|
|
|
JFFS2_LZO = "y";
|
|
|
|
JFFS2_RTIME = "y";
|
|
|
|
JFFS2_COMPRESSION_OPTIONS = "y";
|
|
|
|
JFFS2_ZLIB = "y";
|
|
|
|
JFFS2_CMODE_SIZE = "y";
|
|
|
|
};
|
2023-04-10 20:07:27 +02:00
|
|
|
boot.initramfs.enable = true;
|
2023-04-05 00:35:49 +02:00
|
|
|
outputs = rec {
|
|
|
|
systemConfiguration =
|
2023-04-15 18:15:44 +02:00
|
|
|
pkgs.systemconfig config.filesystem.contents;
|
2023-04-10 20:59:09 +02:00
|
|
|
rootfs =
|
2023-04-05 00:35:49 +02:00
|
|
|
let
|
2023-04-07 10:39:47 +02:00
|
|
|
inherit (pkgs.pkgsBuildBuild) runCommand mtdutils;
|
|
|
|
endian = if pkgs.stdenv.isBigEndian
|
|
|
|
then "--big-endian" else "--little-endian";
|
2023-04-05 00:35:49 +02:00
|
|
|
in runCommand "make-jffs2" {
|
|
|
|
depsBuildBuild = [ mtdutils ];
|
|
|
|
} ''
|
|
|
|
mkdir -p $TMPDIR/empty/nix/store/
|
2023-04-15 18:15:44 +02:00
|
|
|
cp ${systemConfiguration}/bin/activate $TMPDIR/empty/activate
|
|
|
|
ln -s ${pkgs.s6-init-bin}/bin/init $TMPDIR/empty/init
|
2023-04-07 10:39:47 +02:00
|
|
|
pkgClosure=${closureInfo {
|
|
|
|
rootPaths = [ systemConfiguration ];
|
|
|
|
}}
|
2023-04-05 00:35:49 +02:00
|
|
|
cp $pkgClosure/registration nix-path-registration
|
|
|
|
grafts=$(sed < $pkgClosure/store-paths 's/^\(.*\)$/--graft \1:\1/g')
|
2023-04-15 18:23:58 +02:00
|
|
|
mkfs.jffs2 --compression-mode=size ${endian} -e ${config.hardware.flash.eraseBlockSize} --enable-compressor=lzo --pad --root $TMPDIR/empty --output $out $grafts --squash --faketime
|
2023-04-05 00:35:49 +02:00
|
|
|
'';
|
|
|
|
jffs2boot =
|
|
|
|
let o = config.outputs; in
|
|
|
|
pkgs.runCommand "jffs2boot" {} ''
|
|
|
|
mkdir $out
|
|
|
|
cd $out
|
2023-04-10 20:59:09 +02:00
|
|
|
ln -s ${o.rootfs} rootfs
|
2023-04-05 00:35:49 +02:00
|
|
|
ln -s ${o.kernel} vmlinux
|
|
|
|
ln -s ${o.manifest} manifest
|
|
|
|
ln -s ${o.initramfs} initramfs
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|