jffs2.nix (1576B)
1 { 2 config 3 , pkgs 4 , lib 5 , ... 6 }: 7 let 8 inherit (lib) mkIf mkOption types; 9 in 10 { 11 imports = [ 12 ./initramfs.nix 13 ]; 14 options.system.outputs = { 15 systemConfiguration = mkOption { 16 type = types.package; 17 description = '' 18 pkgs.systemconfig for the configured filesystem, 19 contains 'activate' and 'init' commands 20 ''; 21 internal = true; 22 }; 23 }; 24 25 config = mkIf (config.rootfsType == "jffs2") { 26 kernel.config = { 27 JFFS2_FS = "y"; 28 JFFS2_LZO = "y"; 29 JFFS2_RTIME = "y"; 30 JFFS2_COMPRESSION_OPTIONS = "y"; 31 JFFS2_ZLIB = "y"; 32 JFFS2_CMODE_SIZE = "y"; 33 }; 34 boot.initramfs.enable = true; 35 system.outputs = rec { 36 systemConfiguration = 37 pkgs.systemconfig config.filesystem.contents; 38 rootfs = 39 let 40 inherit (pkgs.pkgsBuildBuild) runCommand mtdutils; 41 endian = if pkgs.stdenv.isBigEndian 42 then "--big-endian" else "--little-endian"; 43 in runCommand "make-jffs2" { 44 depsBuildBuild = [ mtdutils ]; 45 } '' 46 mkdir -p $TMPDIR/empty/nix/store/ $TMPDIR/empty/secrets 47 cp ${systemConfiguration}/bin/activate $TMPDIR/empty/activate 48 ln -s ${pkgs.s6-init-bin}/bin/init $TMPDIR/empty/init 49 grafts=$(sed < ${systemConfiguration}/etc/nix-store-paths 's/^\(.*\)$/--graft \1:\1/g') 50 mkfs.jffs2 --compression-mode=size ${endian} -e ${config.hardware.flash.eraseBlockSize} --enable-compressor=lzo --pad --root $TMPDIR/empty --output $out $grafts --squash --faketime 51 ''; 52 }; 53 }; 54 }