Created
April 13, 2019 20:21
-
-
Save lheckemann/532a40e9039d4c9ec6d45d264e6be85c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} }: with pkgs; | |
let linuxPackages = callPackage /etc/nixos/thirtythree/kernel.nix {}; in | |
rec { | |
linux = linuxPackages.kernel; | |
initrd = (makeInitrd { | |
contents = [ | |
{ object = init; symlink = "/sbin/init"; } | |
{ object = init; symlink = "/init"; } | |
{ object = "${modulesClosure}/lib"; symlink = "/lib"; } | |
]; | |
}).overrideAttrs (o: { | |
makeUInitrd = false; | |
}); | |
modulesClosure = makeModulesClosure { | |
kernel = aggregateModules [ linuxPackages.kernel linuxPackages.zfs linuxPackages.spl ]; | |
rootModules = ["zfs"]; | |
firmware = []; | |
}; | |
init = writeScript "init" '' | |
#!${busybox}/bin/ash -x | |
${busybox}/bin/mknod /dev/console c 5 1 | |
${busybox}/bin/mknod /dev/null c 1 3 | |
${busybox}/bin/mknod /dev/ttyFIQ0 c 254 0 | |
echo "Hello, world!" | |
echo "Hello, console!" > /dev/console | |
echo "Hello, tty!" > /dev/ttyFIQ0 | |
export PATH=${busybox}/bin:${pkgs.zfs}/bin | |
mkdir -p /proc | |
mount -t proc proc /proc | |
mkdir -p /sys | |
mount -t sysfs sys /sys | |
mkdir -p /etc | |
echo $'\x99\x33\x99\x33' > /etc/hostid | |
modprobe zfs | |
( | |
cd /sys | |
for dev in devices/virtual/misc/zfs block/* ; do | |
( . $dev/uevent | |
type=c | |
[[ $dev = *block* ]] && type=b | |
mknod /dev/$DEVNAME $type $MAJOR $MINOR | |
) & | |
done | |
wait | |
) | |
mkdir -p /mnt | |
zpool import -N thirtythree | |
mount.zfs -o zfsutil thirtythree/nixos/root /mnt | |
mount.zfs -o zfsutil thirtythree/nixos/nix /mnt/nix | |
exec ash | |
''; | |
nspawn = writeScript "nspawn" '' | |
#!${stdenv.shell} | |
exec unshare -m ${nspawnReal} "$@" | |
''; | |
nspawnReal = writeScript "nspawn-real" '' | |
#!${stdenv.shell} | |
mount -t tmpfs tmpfs /tmp | |
cd /tmp | |
gzip -d < ${initrd}/initrd | cpio -i | |
exec chroot . /sbin/init | |
''; | |
kexec = writeScript "kexec" '' | |
#!${stdenv.shell} | |
set -ex | |
kexec -l ${linux}/Image --initrd ${initrd}/initrd --append "console=ttyFIQ0 panic=10 loglevel=4" --dtb ${linux}/dtbs/rockchip/rk3399-nanopi4-rev01.dtb | |
sleep 5 | |
echo ---------------------------------------- > /dev/console | |
systemctl kexec | |
''; | |
# storagemedia=sd rw root=PARTUUID=614e0000-0000 rootfstype=ext4 rootwait root=/dev/mmcblk0p1 rw rootfstype=ext4 | |
# earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 | |
# uboot_logo=0x02000000@0xf5c00000 loader.timestamp=2019-03-16_17:26:35 SecureBootCheckOk=0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment