aboutsummaryrefslogtreecommitdiff
path: root/nix/rootfs.nix
blob: 34f1b4e65afa4d0ff80dc4c46a7b170075e3d5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ stdenv, fetchgit, busybox, squashfsTools, linuxHeaders, musl }:

stdenv.mkDerivation {
	name = "rootfs-yerba";
	src = ./.;
	buildInputs = [ squashfsTools ];
	nativeBuildInputs = [ squashfsTools linuxHeaders ];
	buildPhase = ''
		# Basic setup start
		mkdir -p rootfs 
		mkdir -p rootfs/{bin,sbin,etc,proc,sys,dev,home,var,usr,root,mnt,tmp,lib}
		mkdir -p rootfs/usr/{lib,bin}
		chmod -R u+w rootfs
		# Basic setup end

		# Musl start
		cp -a ${musl}/lib/* rootfs/usr/lib/
		chmod -R u+w rootfs
		ln -sf /usr/lib/ld-musl-x86_64.so.1 rootfs/lib/ld-musl-x86_64.so.1
		chmod -R u+w rootfs
		ln -sf /usr/lib/libc.so rootfs/lib/libc.so
		# Musl end

		# Busybox start
		cp -a ${busybox}/_install/. rootfs/	
		chmod -R u+w rootfs
		ln -sf /bin/busybox rootfs/init
		# Busybox end

		# Programs start
		# Programs end

		# Basic files setup start
		echo "proc /proc proc defaults 0 0" > rootfs/etc/fstab
		echo "sysfs /sys sysfs defaults 0 0" >> rootfs/etc/fstab
		echo "devtmpfs /dev devtmpfs defaults 0 0" >> rootfs/etc/fstab
		echo "::sysinit:/bin/mount -a" > rootfs/etc/inittab
		echo "tty0::askfirst:/bin/sh" >> rootfs/etc/inittab 
		echo "ttyS0::askfirst:/bin/sh" >> rootfs/etc/inittab 
		echo "::ctrlaltdel:/sbin/reboot" >> rootfs/etc/inittab
		echo "yerba-live" > rootfs/etc/hostname
		# Basic files setup end

		# Squashfs start
		mksquashfs rootfs $out -comp zstd -noappend
		# Squashfs end
	'';
	installPhase = ''
		echo "rootfs built"
	'';
}