support jffs2, with initramfs
the jffs2 filesystem contains only /nix/store and a script which is run in early init (initramfs) and is responsible for recreating "traditional" directories (/bin /etc/**/* /var &c) based on the configuration. this is tested only in qemu so far and could use some cleanup
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
};
|
||||
};
|
||||
writeAshScript = callPackage ./write-ash-script {};
|
||||
systemconfig = callPackage ./systemconfig {};
|
||||
s6-init-bin = callPackage ./s6-init-bin {};
|
||||
s6-rc-database = callPackage ./s6-rc-database {};
|
||||
mips-vm = callPackage ./mips-vm {};
|
||||
|
@@ -1,7 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cleanup(){
|
||||
test -n "$rootfs" && test -f $rootfs && rm $rootfs
|
||||
}
|
||||
trap 'exit 1' INT HUP QUIT TERM ALRM USR1
|
||||
trap 'cleanup' EXIT
|
||||
|
||||
usage(){
|
||||
echo "usage: $(basename $0) [--background /path/to/state_directory] kernel rootimg"
|
||||
echo "usage: $(basename $0) [--background /path/to/state_directory] kernel rootimg [initramfs]"
|
||||
echo -e "\nWithout --background, use C-p c (not C-a c) to switch to the monitor"
|
||||
exit 1
|
||||
}
|
||||
@@ -23,14 +29,22 @@ fi
|
||||
|
||||
test -n "$2" || usage
|
||||
|
||||
rootfs=$(mktemp mips-vm-fs-XXXXXX)
|
||||
dd if=$2 of=$rootfs bs=65536 conv=sync
|
||||
|
||||
if test -n "$3"; then
|
||||
initramfs="-initrd $3"
|
||||
fi
|
||||
|
||||
|
||||
INIT=${INIT-/bin/init}
|
||||
echo $QEMU_OPTIONS
|
||||
qemu-system-mips \
|
||||
-M malta -m 256 \
|
||||
-echr 16 \
|
||||
-append "liminix default console=ttyS0,38400n8 panic=10 oops=panic init=$INIT loglevel=8 root=/dev/mtdblock0 block2mtd.block2mtd=/dev/vda,4096" \
|
||||
-drive file=$2,format=raw,readonly=on,if=virtio \
|
||||
-append "liminix default console=ttyS0,38400n8 panic=10 oops=panic init=$INIT loglevel=8 root=/dev/mtdblock0 block2mtd.block2mtd=/dev/vda,65536" \
|
||||
-drive file=$rootfs,format=raw,readonly=on,if=virtio \
|
||||
${initramfs} \
|
||||
-netdev socket,id=access,mcast=230.0.0.1:1234,localaddr=127.0.0.1 \
|
||||
-device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:21:02 \
|
||||
-netdev socket,id=lan,mcast=230.0.0.1:1235,localaddr=127.0.0.1 \
|
||||
|
60
pkgs/systemconfig/default.nix
Normal file
60
pkgs/systemconfig/default.nix
Normal file
@@ -0,0 +1,60 @@
|
||||
# The ideal is that a Liminix system can boot with only the files in
|
||||
# /nix/store. This package generates a script that is run at early
|
||||
# boot (from the initramfs) to populate directories such as /etc,
|
||||
# /bin, /home according to whatever the configuration says
|
||||
# they should contain
|
||||
|
||||
{
|
||||
writeText
|
||||
, runCommand
|
||||
, lib
|
||||
}:
|
||||
let
|
||||
inherit (lib.attrsets) mapAttrsToList;
|
||||
escaped = msg : builtins.replaceStrings
|
||||
["\n" "=" "\"" "$" ]
|
||||
["\\x0a" "\\x3d" "\\x22" "\\x24"]
|
||||
msg;
|
||||
|
||||
visit = prefix: attrset:
|
||||
let makeFile = prefix : filename: {
|
||||
type ? "f"
|
||||
, mode ? null
|
||||
, target ? null
|
||||
, contents ? null
|
||||
, file ? null
|
||||
, major ? null
|
||||
, minor ? null
|
||||
}:
|
||||
let
|
||||
pathname = "${prefix}/${filename}";
|
||||
chmod =
|
||||
let m = if mode != null then mode else
|
||||
(if type == "d" then "0755" else "0644");
|
||||
in (if type == "s"
|
||||
then ""
|
||||
else "\nchmod ${m} ${pathname}");
|
||||
cmds = {
|
||||
"f" = "printf \"${escaped file}\" > ${pathname}";
|
||||
"d" = "mkdir ${pathname}\n" +
|
||||
(builtins.concatStringsSep "\n"
|
||||
(visit pathname contents));
|
||||
"c" = "mknod ${pathname} c ${major} ${minor}";
|
||||
"b" = "mknod ${pathname} b ${major} ${minor}";
|
||||
"s" = "ln -s ${target} ${pathname}";
|
||||
"l" = "ln ${target} ${pathname}";
|
||||
"i" = "mknod ${pathname} p";
|
||||
};
|
||||
cmd = cmds.${type};
|
||||
in "${cmd}${chmod}";
|
||||
in mapAttrsToList (makeFile prefix) attrset;
|
||||
activateScript = attrset: writeText "systemConfig" ''
|
||||
#!/bin/sh
|
||||
t=$1
|
||||
${(builtins.concatStringsSep "\n" (visit "$t" attrset))}
|
||||
'';
|
||||
in attrset:
|
||||
runCommand "make-stuff" {} ''
|
||||
mkdir -p $out
|
||||
ln -s ${activateScript attrset} $out/activate
|
||||
''
|
Reference in New Issue
Block a user