add default service target, get some stuff running

module-based-network
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"; };
init = {
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";
@ -45,8 +45,8 @@ let
file = ''
#!${execline}/bin/execlineb -P
${execline}/bin/fdmove -c 2 1
${execline}/bin/bin/fdmove 1 3
${s6}/s6-ipcserver -1 -a 0700 -c 1 -- s
${execline}/bin/fdmove 1 3
${s6}/bin/s6-ipcserver -1 -a 0700 -c 1 -- s
${s6}/bin/s6-sudod -dt30000 -- "/etc/s6-linux-init/current"/scripts/runlevel
'';
mode = "0755";
@ -98,7 +98,7 @@ let
quit = message: ''
#!${execline}/bin/execlineb -P
${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} }
${s6-linux-init}/bin/s6-linux-init-hpr -fr
'';

View File

@ -3,6 +3,6 @@
qemu-system-mips \
-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 \
-kernel $1 -nographic -display none -serial mon:stdio

View File

@ -1,7 +1,7 @@
{ config, tools, pkgs } :
let
inherit (tools.networking) interface address udhcpc odhcpc;
inherit (tools.services) oneshot longrun bundle output;
inherit (tools.services) oneshot longrun bundle target output;
in rec {
services.loopback =
let iface = interface { type = "loopback"; device = "lo";};
@ -25,7 +25,7 @@ in rec {
# producer to create a file per output variable.
name = "ntp";
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
# generally, as different services have different outputs, but it
@ -53,5 +53,11 @@ in rec {
echo "0" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"})
'';
};
services.default = target {
name = "default";
contents = with services; [ loopback ntp defaultroute4 ];
};
systemPackages = [ pkgs.hello ] ;
}

View File

@ -3,14 +3,16 @@ mkdir -p $out/${name}
echo $type > $out/${name}/type
mkdir -p $out/${name}/dependencies.d
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
done
test -n "$contents" && for d in "$contents"; do
test -n "$contents" && for d in $contents; do
mkdir -p $out/${name}/contents.d
touch $out/${name}/contents.d/$d
done
test -n "$run" && (echo "$run" > $out/${name}/run)
test -n "$up" && (echo "$up" > $out/${name}/up)
test -n "$down" && (echo "$down" > $out/${name}/down)
(echo $out/${name} && cd $out/${name} && find . -ls)
test -n "$run" && (echo -e "#!$shell\n$run" > $out/${name}/run)
test -n "$up" && (echo -e "#!$shell\n$up" > $out/${name}/up)
test -n "$down" && (echo -e "#!$shell\n$down" > $out/${name}/down)
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
, s6-rc
, lib
, busybox
} :let
inherit (builtins) concatStringsSep;
longrun = {
@ -13,6 +15,7 @@
type = "longrun";
buildInputs = dependencies;
dependencies = builtins.map (d: d.name) dependencies;
shell = "${busybox}/bin/sh";
inherit run;
builder = ./builder.sh;
};
@ -32,23 +35,27 @@
# even though the built output has no references to their
# store directories?
buildInputs = dependencies;
shell = "${busybox}/bin/sh";
inherit up down;
dependencies = builtins.map (d: d.name) dependencies;
builder = ./builder.sh;
};
bundle = {
target = {
name
, contents ? []
, dependencies ? []
, ...
}: stdenvNoCC.mkDerivation {
name = "${name}.bundle";
inherit name;
type = "bundle";
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;
shell = "${busybox}/bin/sh";
builder = ./builder.sh;
};
bundle = { name, ... } @args : target (args // { name = "${name}.bundle";});
in {
networking = {
interface = { type, device } @ args: oneshot {
@ -66,7 +73,7 @@ in {
};
udhcpc = interface: { ... } @ args: longrun {
name = "${interface.device}.udhcp";
run = "udhchpcd ${interface.device}";
run = "${busybox}/bin/udhcpc -f -i ${interface.device}";
};
odhcpc = interface: { ... } @ args: longrun {
name = "${interface.device}.odhcp";
@ -74,7 +81,7 @@ in {
};
};
services = {
inherit longrun oneshot bundle;
inherit longrun oneshot bundle target;
output = service: name: "/run/services/outputs/${service.name}/${name}";
};
}