nixos-config/pkgs/firecracker-vm/rootfs.nix

31 lines
667 B
Nix
Raw Permalink Normal View History

2024-11-08 03:59:57 +00:00
{
e2fsprogs,
pkgsStatic,
runCommand,
util-linux,
writeShellScript,
2023-12-18 03:39:23 +00:00
}:
let
init-sh = builtins.toFile "init.sh" ''
#!/bin/sh
mount none -t proc /proc
mount none -t sysfs /sys
mount none -t tmpfs /tmp
mount none -t tmpfs /run
exec sh
'';
mkroot = writeShellScript "mkroot" ''
mkdir -p rootfs/{dev,proc,run,sys,tmp}
install -Dm 755 ${init-sh} rootfs/sbin/init
install -Dm 755 ${pkgsStatic.busybox}/bin/busybox rootfs/bin/busybox
chroot rootfs /bin/busybox --install -s /bin
${e2fsprogs.bin}/bin/mkfs.ext4 -d rootfs $out 32M
'';
in
runCommand "rootfs.img" { } ''
${util-linux}/bin/unshare -r ${mkroot}
''