liminix-fork/modules/initramfs.nix
Daniel Barlow 5dd0c6e3c0 rewrite preinit as very small C program
By using the kernel "nolibc" header to avoid requiring a C library, we
can bring the initramfs size to around 4k

This does involve a tiny bit of inline mips assembly which I'm not
sure about. gcc seems unwilling to generate the code to load $gp at
function entry of main(), so we do it by hand - but I'd rather find
out why gcc doesn't.
2023-04-15 18:27:39 +01:00

42 lines
1 KiB
Nix

{
config
, pkgs
, lib
, ...
}:
let
inherit (lib) mkEnableOption mkIf;
inherit (pkgs) runCommand callPackage writeText;
in
{
options = {
boot.initramfs = {
enable = mkEnableOption "enable initramfs";
default = false;
};
};
config = mkIf config.boot.initramfs.enable {
kernel.config = {
BLK_DEV_INITRD = "y";
INITRAMFS_SOURCE = builtins.toJSON "${config.outputs.initramfs}";
# INITRAMFS_COMPRESSION_LZO = "y";
};
outputs = {
initramfs =
let inherit (pkgs.pkgsBuildBuild) gen_init_cpio;
in runCommand "initramfs.cpio" {} ''
cat << SPECIALS | ${gen_init_cpio}/bin/gen_init_cpio /dev/stdin > $out
dir /proc 0755 0 0
dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
nod /dev/mtdblock0 0600 0 0 b 31 0
dir /target 0755 0 0
dir /target/persist 0755 0 0
dir /target/nix 0755 0 0
file /init ${pkgs.preinit}/bin/preinit 0755 0 0
SPECIALS
'';
};
};
}