2018-06-10 06:03:24 +03:00
|
|
|
{
|
2018-06-17 03:43:19 +03:00
|
|
|
device_config,
|
|
|
|
stage-1 ? {},
|
2018-06-10 06:03:24 +03:00
|
|
|
|
|
|
|
stdenv,
|
|
|
|
makeInitrd,
|
|
|
|
runCommand,
|
|
|
|
writeScript,
|
|
|
|
|
|
|
|
runCommandCC,
|
|
|
|
busybox,
|
|
|
|
glibc,
|
2018-06-10 21:22:09 +03:00
|
|
|
|
2018-06-11 03:00:03 +03:00
|
|
|
lib,
|
2018-06-13 03:07:36 +03:00
|
|
|
mkExtraUtils,
|
2018-06-10 06:03:24 +03:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2018-06-13 04:47:00 +03:00
|
|
|
inherit (lib) optionalString optionals optional;
|
|
|
|
|
2018-06-17 03:43:19 +03:00
|
|
|
device_name = device_config.name;
|
2018-06-13 04:47:00 +03:00
|
|
|
|
2018-06-13 03:07:36 +03:00
|
|
|
extraUtils = mkExtraUtils {
|
|
|
|
name = device_name;
|
|
|
|
packages = [
|
|
|
|
busybox
|
2018-06-13 04:47:00 +03:00
|
|
|
]
|
2018-06-17 03:43:19 +03:00
|
|
|
++ optionals (stage-1 ? extraUtils) stage-1.extraUtils
|
2018-06-13 04:47:00 +03:00
|
|
|
;
|
2018-06-13 03:07:36 +03:00
|
|
|
};
|
2018-06-10 06:03:24 +03:00
|
|
|
|
|
|
|
shell = "${extraUtils}/bin/ash";
|
|
|
|
|
|
|
|
stage1 = writeScript "stage1" ''
|
|
|
|
#!${shell}
|
|
|
|
export PATH=${extraUtils}/bin/
|
2018-06-11 03:09:06 +03:00
|
|
|
export LD_LIBRARY_PATH=${extraUtils}/lib
|
|
|
|
|
2018-06-13 04:47:00 +03:00
|
|
|
mkdir -p /bin
|
|
|
|
ln -sv ${shell} /bin/sh
|
|
|
|
|
2018-06-17 06:43:11 +03:00
|
|
|
mkdir -p /proc /sys /dev /etc/udev /tmp /run/ /lib/ /mnt/ /var/log
|
2018-06-10 06:03:24 +03:00
|
|
|
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
|
2018-06-17 06:43:11 +03:00
|
|
|
touch /var/log/lastlog
|
2018-06-11 03:00:03 +03:00
|
|
|
|
2018-06-17 06:43:11 +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
|
|
|
|
2018-06-17 06:43:11 +03:00
|
|
|
${stage-1.init}
|
2018-06-12 02:55:35 +03:00
|
|
|
|
2018-06-17 06:43:11 +03:00
|
|
|
# TODO
|
2018-06-10 06:03:24 +03:00
|
|
|
loop_forever() {
|
2018-06-10 23:22:17 +03:00
|
|
|
while true; do
|
|
|
|
sleep 3600
|
|
|
|
done
|
2018-06-10 06:03:24 +03:00
|
|
|
}
|
2018-06-10 23:22:17 +03:00
|
|
|
loop_forever
|
2018-06-10 06:03:24 +03:00
|
|
|
'';
|
2018-06-17 06:43:11 +03:00
|
|
|
|
2018-06-10 06:03:24 +03:00
|
|
|
ramdisk = makeInitrd {
|
|
|
|
contents = [
|
|
|
|
{ object = stage1; symlink = "/init"; }
|
2018-06-13 02:14:55 +03:00
|
|
|
]
|
2018-06-17 06:43:11 +03:00
|
|
|
++ lib.flatten stage-1.contents
|
2018-06-13 02:14:55 +03:00
|
|
|
;
|
2018-06-10 06:03:24 +03:00
|
|
|
};
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "initrd-${device_name}";
|
|
|
|
src = builtins.filterSource (path: type: false) ./.;
|
|
|
|
unpackPhase = "true";
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
cp ${ramdisk}/initrd $out
|
|
|
|
'';
|
|
|
|
}
|