1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-11-28 12:56:54 +03:00
mobile-nixos/initrd.nix

83 lines
1.4 KiB
Nix
Raw Normal View History

{
device_config,
stage-1 ? {},
stdenv,
makeInitrd,
runCommand,
writeScript,
runCommandCC,
busybox,
glibc,
2018-06-11 03:00:03 +03:00
lib,
mkExtraUtils,
}:
let
2018-06-13 04:47:00 +03:00
inherit (lib) optionalString optionals optional;
device_name = device_config.name;
2018-06-13 04:47:00 +03:00
extraUtils = mkExtraUtils {
name = device_name;
packages = [
busybox
2018-06-13 04:47:00 +03:00
]
++ optionals (stage-1 ? extraUtils) stage-1.extraUtils
2018-06-13 04:47:00 +03:00
;
};
shell = "${extraUtils}/bin/ash";
stage1 = writeScript "stage1" ''
#!${shell}
export PATH=${extraUtils}/bin/
export LD_LIBRARY_PATH=${extraUtils}/lib
2018-06-13 04:47:00 +03:00
mkdir -p /bin
ln -sv ${shell} /bin/sh
mkdir -p /proc /sys /dev /etc/udev /tmp /run/ /lib/ /mnt/ /var/log
mount -t devtmpfs devtmpfs /dev/
mount -t proc proc /proc
mount -t sysfs sysfs /sys
2018-06-13 04:47:00 +03:00
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
touch /var/log/lastlog
2018-06-11 03:00:03 +03:00
# TODO
# Hack~ish
echo -e '#!/bin/sh\necho b > /proc/sysrq-trigger' > /bin/reboot
chmod +x /bin/reboot
2018-06-11 03:00:03 +03:00
${stage-1.init}
# TODO
loop_forever() {
2018-06-10 23:22:17 +03:00
while true; do
sleep 3600
done
}
2018-06-10 23:22:17 +03:00
loop_forever
'';
ramdisk = makeInitrd {
contents = [
{ object = stage1; symlink = "/init"; }
]
++ lib.flatten stage-1.contents
;
};
in
stdenv.mkDerivation {
name = "initrd-${device_name}";
src = builtins.filterSource (path: type: false) ./.;
unpackPhase = "true";
installPhase = ''
cp ${ramdisk}/initrd $out
'';
}