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-07-13 20:24:59 +02:00
|
|
|
inherit (lib) mkIf mkOption types;
|
2023-04-05 00:35:49 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
./initramfs.nix
|
|
|
|
];
|
2023-07-13 20:24:59 +02:00
|
|
|
options.system.outputs = {
|
|
|
|
systemConfiguration = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = ''
|
|
|
|
pkgs.systemconfig for the configured filesystem,
|
|
|
|
contains 'activate' and 'init' commands
|
|
|
|
'';
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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-07-13 20:24:59 +02:00
|
|
|
system.outputs = rec {
|
2023-04-05 00:35:49 +02:00
|
|
|
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 ];
|
|
|
|
} ''
|
2023-05-21 13:01:42 +02:00
|
|
|
mkdir -p $TMPDIR/empty/nix/store/ $TMPDIR/empty/secrets
|
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-05-20 00:53:29 +02:00
|
|
|
grafts=$(sed < ${systemConfiguration}/etc/nix-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
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|