add default service target, get some stuff running

This commit is contained in:
Daniel Barlow 2022-09-22 00:10:55 +01:00
parent edb701b87d
commit fde7a269b7
5 changed files with 33 additions and 18 deletions

View file

@ -32,7 +32,7 @@ let
halt = { type="f"; file = hpr "-h"; mode="0755"; }; halt = { type="f"; file = hpr "-h"; mode="0755"; };
init = { init = {
type="f"; mode="0755"; type="f"; mode="0755";
file = "#!${execline}/bin/execlineb -S0\n${s6-linux-init}/bin/s6-linux-init -c /etc/s6-linux-init/current -m 0022 -p ${lib.makeBinPath [execline s6-linux-init s6-rc]}:/usr/bin:/bin -d /dev -- \"\\$@\""; file = "#!${execline}/bin/execlineb -S0\n${s6-linux-init}/bin/s6-linux-init -c /etc/s6-linux-init/current -m 0022 -p ${lib.makeBinPath [busybox execline s6-linux-init s6-rc]}:/usr/bin:/bin -d /dev -- \"\\$@\"";
}; };
}; };
scripts = symlink "${initscripts}/scripts"; scripts = symlink "${initscripts}/scripts";
@ -45,8 +45,8 @@ let
file = '' file = ''
#!${execline}/bin/execlineb -P #!${execline}/bin/execlineb -P
${execline}/bin/fdmove -c 2 1 ${execline}/bin/fdmove -c 2 1
${execline}/bin/bin/fdmove 1 3 ${execline}/bin/fdmove 1 3
${s6}/s6-ipcserver -1 -a 0700 -c 1 -- s ${s6}/bin/s6-ipcserver -1 -a 0700 -c 1 -- s
${s6}/bin/s6-sudod -dt30000 -- "/etc/s6-linux-init/current"/scripts/runlevel ${s6}/bin/s6-sudod -dt30000 -- "/etc/s6-linux-init/current"/scripts/runlevel
''; '';
mode = "0755"; mode = "0755";
@ -98,7 +98,7 @@ let
quit = message: '' quit = message: ''
#!${execline}/bin/execlineb -P #!${execline}/bin/execlineb -P
${execline}/bin/redirfd -w 2 /dev/console ${execline}/bin/redirfd -w 2 /dev/console
${execline}/bin/bin/fdmove -c 1 2 ${execline}/bin/fdmove -c 1 2
${execline}/bin/foreground { ${s6-linux-init}/bin/s6-linux-init-echo -- ${message} } ${execline}/bin/foreground { ${s6-linux-init}/bin/s6-linux-init-echo -- ${message} }
${s6-linux-init}/bin/s6-linux-init-hpr -fr ${s6-linux-init}/bin/s6-linux-init-hpr -fr
''; '';

View file

@ -3,6 +3,6 @@
qemu-system-mips \ qemu-system-mips \
-M malta -m 256 \ -M malta -m 256 \
-append "earlyprintk=serial,ttyS0 console=ttyS0,38400n8 panic=10 oops=panic init=/bin/init loglevel=8 root=/dev/vda" \ -append "default console=ttyS0,38400n8 panic=10 oops=panic init=/bin/init loglevel=8 root=/dev/vda" \
-drive file=$2,format=raw,readonly,if=virtio \ -drive file=$2,format=raw,readonly,if=virtio \
-kernel $1 -nographic -display none -serial mon:stdio -kernel $1 -nographic -display none -serial mon:stdio

View file

@ -1,7 +1,7 @@
{ config, tools, pkgs } : { config, tools, pkgs } :
let let
inherit (tools.networking) interface address udhcpc odhcpc; inherit (tools.networking) interface address udhcpc odhcpc;
inherit (tools.services) oneshot longrun bundle output; inherit (tools.services) oneshot longrun bundle target output;
in rec { in rec {
services.loopback = services.loopback =
let iface = interface { type = "loopback"; device = "lo";}; let iface = interface { type = "loopback"; device = "lo";};
@ -25,7 +25,7 @@ in rec {
# producer to create a file per output variable. # producer to create a file per output variable.
name = "ntp"; name = "ntp";
run = let inherit (services) dhcpv4 dhcpv6; run = let inherit (services) dhcpv4 dhcpv6;
in "${pkgs.ntp}/bin/ntp $(cat ${output dhcpv4 "ntp_servers"}) $(cat ${output dhcpv6 "NTP_IP"})"; in "${pkgs.ntp}/bin/ntpd $(cat ${output dhcpv4 "ntp_servers"}) $(cat ${output dhcpv6 "NTP_IP"})";
# I don't think it's possible to standardise the file names # I don't think it's possible to standardise the file names
# generally, as different services have different outputs, but it # generally, as different services have different outputs, but it
@ -53,5 +53,11 @@ in rec {
echo "0" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"}) echo "0" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"})
''; '';
}; };
services.default = target {
name = "default";
contents = with services; [ loopback ntp defaultroute4 ];
};
systemPackages = [ pkgs.hello ] ; systemPackages = [ pkgs.hello ] ;
} }

View file

@ -3,14 +3,16 @@ mkdir -p $out/${name}
echo $type > $out/${name}/type echo $type > $out/${name}/type
mkdir -p $out/${name}/dependencies.d mkdir -p $out/${name}/dependencies.d
echo $buildInputs > $out/buildInputs echo $buildInputs > $out/buildInputs
test -n "$dependencies" && for d in "$dependencies"; do test -n "$dependencies" && for d in $dependencies; do
touch $out/${name}/dependencies.d/$d touch $out/${name}/dependencies.d/$d
done done
test -n "$contents" && for d in "$contents"; do test -n "$contents" && for d in $contents; do
mkdir -p $out/${name}/contents.d mkdir -p $out/${name}/contents.d
touch $out/${name}/contents.d/$d touch $out/${name}/contents.d/$d
done done
test -n "$run" && (echo "$run" > $out/${name}/run) test -n "$run" && (echo -e "#!$shell\n$run" > $out/${name}/run)
test -n "$up" && (echo "$up" > $out/${name}/up) test -n "$up" && (echo -e "#!$shell\n$up" > $out/${name}/up)
test -n "$down" && (echo "$down" > $out/${name}/down) test -n "$down" && (echo -e "#!$shell\n$down" > $out/${name}/down)
(echo $out/${name} && cd $out/${name} && find . -ls) for i in $out/${name}/{down,up,run} ; do test -f $i && chmod +x $i; done
true
# (echo $out/${name} && cd $out/${name} && find . -ls)

View file

@ -1,6 +1,8 @@
{ {
stdenvNoCC stdenvNoCC
, s6-rc , s6-rc
, lib
, busybox
} :let } :let
inherit (builtins) concatStringsSep; inherit (builtins) concatStringsSep;
longrun = { longrun = {
@ -13,6 +15,7 @@
type = "longrun"; type = "longrun";
buildInputs = dependencies; buildInputs = dependencies;
dependencies = builtins.map (d: d.name) dependencies; dependencies = builtins.map (d: d.name) dependencies;
shell = "${busybox}/bin/sh";
inherit run; inherit run;
builder = ./builder.sh; builder = ./builder.sh;
}; };
@ -32,23 +35,27 @@
# even though the built output has no references to their # even though the built output has no references to their
# store directories? # store directories?
buildInputs = dependencies; buildInputs = dependencies;
shell = "${busybox}/bin/sh";
inherit up down; inherit up down;
dependencies = builtins.map (d: d.name) dependencies; dependencies = builtins.map (d: d.name) dependencies;
builder = ./builder.sh; builder = ./builder.sh;
}; };
bundle = { target = {
name name
, contents ? [] , contents ? []
, dependencies ? [] , dependencies ? []
, ... , ...
}: stdenvNoCC.mkDerivation { }: stdenvNoCC.mkDerivation {
name = "${name}.bundle"; inherit name;
type = "bundle"; type = "bundle";
contents = builtins.map (d: d.name) contents; contents = builtins.map (d: d.name) contents;
buildInputs = dependencies ++ contents; buildInputs = dependencies ++ (lib.debug.traceSeqN 2 contents contents);
dependencies = builtins.map (d: d.name) dependencies; dependencies = builtins.map (d: d.name) dependencies;
shell = "${busybox}/bin/sh";
builder = ./builder.sh; builder = ./builder.sh;
}; };
bundle = { name, ... } @args : target (args // { name = "${name}.bundle";});
in { in {
networking = { networking = {
interface = { type, device } @ args: oneshot { interface = { type, device } @ args: oneshot {
@ -66,7 +73,7 @@ in {
}; };
udhcpc = interface: { ... } @ args: longrun { udhcpc = interface: { ... } @ args: longrun {
name = "${interface.device}.udhcp"; name = "${interface.device}.udhcp";
run = "udhchpcd ${interface.device}"; run = "${busybox}/bin/udhcpc -f -i ${interface.device}";
}; };
odhcpc = interface: { ... } @ args: longrun { odhcpc = interface: { ... } @ args: longrun {
name = "${interface.device}.odhcp"; name = "${interface.device}.odhcp";
@ -74,7 +81,7 @@ in {
}; };
}; };
services = { services = {
inherit longrun oneshot bundle; inherit longrun oneshot bundle target;
output = service: name: "/run/services/outputs/${service.name}/${name}"; output = service: name: "/run/services/outputs/${service.name}/${name}";
}; };
} }