Compare commits
6 Commits
1b1aa9de76
...
d5ccecf038
Author | SHA1 | Date | |
---|---|---|---|
d5ccecf038 | |||
2430e80ca1 | |||
7803eebfd4 | |||
676c94782b | |||
4bfba33170 | |||
f0024dcac5 |
@ -75,7 +75,7 @@ Sun Sep 25 20:56:28 BST 2022
|
|||||||
|
|
||||||
TODO - bugs, missing bits, other infelicities as they occur to me:
|
TODO - bugs, missing bits, other infelicities as they occur to me:
|
||||||
|
|
||||||
1) shutdown doesn't work as its using the busybox one not s6.
|
DONE 1) shutdown doesn't work as its using the busybox one not s6.
|
||||||
|
|
||||||
2) perhaps we shouldn't have process-based services like dhcp, ppp
|
2) perhaps we shouldn't have process-based services like dhcp, ppp
|
||||||
implement "address provider interface" - instead have a separate
|
implement "address provider interface" - instead have a separate
|
||||||
@ -102,7 +102,7 @@ look for obvious wastes of space
|
|||||||
8) some of configuration.nix (e.g. defining routes) should be moved into
|
8) some of configuration.nix (e.g. defining routes) should be moved into
|
||||||
tools
|
tools
|
||||||
|
|
||||||
9) split tools up instead of having it all one file
|
DONE 9) split tools up instead of having it all one file
|
||||||
|
|
||||||
10) is it OK to depend on squashfs pseudofiles if we might want to
|
10) is it OK to depend on squashfs pseudofiles if we might want to
|
||||||
switch to ubifs? will there always be a squashfs underneath? might
|
switch to ubifs? will there always be a squashfs underneath? might
|
||||||
@ -120,10 +120,12 @@ we want to change the pseudofiles in an overlay?
|
|||||||
is that specified or fluke?
|
is that specified or fluke?
|
||||||
|
|
||||||
16) tighten up the module specs. (DONE) services.foo should be a s6-rc
|
16) tighten up the module specs. (DONE) services.foo should be a s6-rc
|
||||||
service, kernel config should be checked in some way
|
service, (DONE) kernel config should be checked in some way
|
||||||
|
|
||||||
DONE 17) rename nixwrt references in kernel builder
|
DONE 17) rename nixwrt references in kernel builder
|
||||||
|
|
||||||
18) maybe stop suffixing all the service names with .service
|
18) maybe stop suffixing all the service names with .service
|
||||||
|
|
||||||
|
19) syslogd - use busybox or s6?
|
||||||
|
|
||||||
chat -s -S ogin:--ogin: root / "ip address show dev ppp0 | grep ppp0" 192.168.100.1 "/nix/store/*-s6-linux-init-*/bin/s6-linux-init-hpr -p"
|
chat -s -S ogin:--ogin: root / "ip address show dev ppp0 | grep ppp0" 192.168.100.1 "/nix/store/*-s6-linux-init-*/bin/s6-linux-init-hpr -p"
|
||||||
|
@ -39,7 +39,7 @@ let
|
|||||||
};
|
};
|
||||||
s6-pseudofiles = pkgs.s6-init-files;
|
s6-pseudofiles = pkgs.s6-init-files;
|
||||||
profile = writeScript ".profile" ''
|
profile = writeScript ".profile" ''
|
||||||
PATH=${lib.makeBinPath (with pkgs; [busybox execline s6-linux-init s6-rc])}
|
PATH=${lib.makeBinPath (with pkgs; [ s6-init-bin busybox execline s6-linux-init s6-rc])}
|
||||||
export PATH
|
export PATH
|
||||||
'';
|
'';
|
||||||
pseudofiles = writeText "pseudofiles" ''
|
pseudofiles = writeText "pseudofiles" ''
|
||||||
@ -60,7 +60,7 @@ let
|
|||||||
/sys d 0555 root root
|
/sys d 0555 root root
|
||||||
/dev/pts d 0755 0 0
|
/dev/pts d 0755 0 0
|
||||||
/etc/init.d d 0755 0 0
|
/etc/init.d d 0755 0 0
|
||||||
/bin/init s 0755 0 0 /etc/s6-linux-init/current/bin/init
|
/bin/init s 0755 0 0 ${pkgs.s6-init-bin}/bin/init
|
||||||
/bin/sh s 0755 0 0 ${pkgs.pkgsStatic.busybox}/bin/sh
|
/bin/sh s 0755 0 0 ${pkgs.pkgsStatic.busybox}/bin/sh
|
||||||
/bin/busybox s 0755 0 0 ${pkgs.busybox}/bin/busybox
|
/bin/busybox s 0755 0 0 ${pkgs.busybox}/bin/busybox
|
||||||
/etc/s6-rc d 0755 0 0
|
/etc/s6-rc d 0755 0 0
|
||||||
|
@ -15,8 +15,15 @@ in {
|
|||||||
services = mkOption {
|
services = mkOption {
|
||||||
type = types.attrsOf type_service;
|
type = types.attrsOf type_service;
|
||||||
};
|
};
|
||||||
kernel = mkOption {
|
kernel = {
|
||||||
type = types.anything;
|
config = mkOption {
|
||||||
|
# mostly the values are y n or m, but sometimes
|
||||||
|
# other strings are also used
|
||||||
|
type = types.attrsOf types.nonEmptyStr;
|
||||||
|
};
|
||||||
|
checkedConfig = mkOption {
|
||||||
|
type = types.attrsOf types.nonEmptyStr;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,14 @@ final: prev: {
|
|||||||
pseudofile = final.callPackage ./pkgs/pseudofile {};
|
pseudofile = final.callPackage ./pkgs/pseudofile {};
|
||||||
s6-init-files = final.callPackage ./pkgs/s6-init-files {};
|
s6-init-files = final.callPackage ./pkgs/s6-init-files {};
|
||||||
strace = prev.strace.override { libunwind = null; };
|
strace = prev.strace.override { libunwind = null; };
|
||||||
liminix = final.callPackage ./pkgs/liminix-tools {};
|
liminix = {
|
||||||
|
services = final.callPackage ./pkgs/liminix-tools/services {};
|
||||||
|
networking = final.callPackage ./pkgs/liminix-tools/networking {};
|
||||||
|
};
|
||||||
writeAshScript = final.callPackage ./pkgs/write-ash-script {};
|
writeAshScript = final.callPackage ./pkgs/write-ash-script {};
|
||||||
|
|
||||||
|
s6-init-bin = final.callPackage ./pkgs/s6-init-bin {};
|
||||||
|
|
||||||
pppoe = prev.rpPPPoE.overrideAttrs (o: {
|
pppoe = prev.rpPPPoE.overrideAttrs (o: {
|
||||||
# use newer rp-pppoe, it builds cleanly
|
# use newer rp-pppoe, it builds cleanly
|
||||||
src = final.fetchFromGitHub {
|
src = final.fetchFromGitHub {
|
||||||
|
39
pkgs/liminix-tools/networking/default.nix
Normal file
39
pkgs/liminix-tools/networking/default.nix
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
callPackage
|
||||||
|
, liminix
|
||||||
|
}:
|
||||||
|
let inherit (liminix.services) oneshot longrun;
|
||||||
|
in {
|
||||||
|
interface = { type, device } @ args: oneshot {
|
||||||
|
name = "${device}.link";
|
||||||
|
up = "ip link set up dev ${device}";
|
||||||
|
down = "ip link set down dev ${device}";
|
||||||
|
} // {
|
||||||
|
inherit device;
|
||||||
|
};
|
||||||
|
address = interface: { family, prefixLength, address } @ args:
|
||||||
|
let inherit (builtins) toString;
|
||||||
|
in oneshot {
|
||||||
|
dependencies = [ interface ];
|
||||||
|
name = "${interface.device}.addr.${address}";
|
||||||
|
up = "ip address add ${address}/${toString prefixLength} dev ${interface.device} ";
|
||||||
|
down = "ip address del ${address}/${toString prefixLength} dev ${interface.device} ";
|
||||||
|
};
|
||||||
|
udhcpc = callPackage ./udhcpc.nix {};
|
||||||
|
odhcpc = interface: { ... } @ args: longrun {
|
||||||
|
name = "${interface.device}.odhcp";
|
||||||
|
run = "odhcpcd ${interface.device}";
|
||||||
|
};
|
||||||
|
pppoe = callPackage ./pppoe.nix {};
|
||||||
|
route = { name, target, via, dependencies }:
|
||||||
|
oneshot {
|
||||||
|
inherit name;
|
||||||
|
up = ''
|
||||||
|
ip route add ${target} via ${via}
|
||||||
|
'';
|
||||||
|
down = ''
|
||||||
|
ip route del ${target} via ${via}
|
||||||
|
'';
|
||||||
|
inherit dependencies;
|
||||||
|
};
|
||||||
|
}
|
@ -5,8 +5,10 @@
|
|||||||
, busybox
|
, busybox
|
||||||
, callPackage
|
, callPackage
|
||||||
, writeAshScript
|
, writeAshScript
|
||||||
} :let
|
}:
|
||||||
|
let
|
||||||
inherit (builtins) concatStringsSep;
|
inherit (builtins) concatStringsSep;
|
||||||
|
output = service: name: "/run/service-state/${service.name}/${name}";
|
||||||
longrun = {
|
longrun = {
|
||||||
name
|
name
|
||||||
, run
|
, run
|
||||||
@ -61,33 +63,6 @@
|
|||||||
builder = ./builder.sh;
|
builder = ./builder.sh;
|
||||||
};
|
};
|
||||||
bundle = { name, ... } @args : target (args // { name = "${name}.bundle";});
|
bundle = { name, ... } @args : target (args // { name = "${name}.bundle";});
|
||||||
|
|
||||||
in {
|
in {
|
||||||
networking = {
|
inherit target bundle oneshot longrun output;
|
||||||
interface = { type, device } @ args: oneshot {
|
|
||||||
name = "${device}.link";
|
|
||||||
up = "ip link set up dev ${device}";
|
|
||||||
down = "ip link set down dev ${device}";
|
|
||||||
} // {
|
|
||||||
inherit device;
|
|
||||||
};
|
|
||||||
address = interface: { family, prefixLength, address } @ args:
|
|
||||||
let inherit (builtins) toString;
|
|
||||||
in oneshot {
|
|
||||||
dependencies = [ interface ];
|
|
||||||
name = "${interface.device}.addr.${address}";
|
|
||||||
up = "ip address add ${address}/${toString prefixLength} dev ${interface.device} ";
|
|
||||||
down = "ip address del ${address}/${toString prefixLength} dev ${interface.device} ";
|
|
||||||
};
|
|
||||||
udhcpc = callPackage ./networking/udhcpc.nix {};
|
|
||||||
odhcpc = interface: { ... } @ args: longrun {
|
|
||||||
name = "${interface.device}.odhcp";
|
|
||||||
run = "odhcpcd ${interface.device}";
|
|
||||||
};
|
|
||||||
pppoe = callPackage ./networking/pppoe.nix {};
|
|
||||||
};
|
|
||||||
services = {
|
|
||||||
inherit longrun oneshot bundle target;
|
|
||||||
output = service: name: "/run/service-state/${service.name}/${name}";
|
|
||||||
};
|
|
||||||
}
|
}
|
33
pkgs/s6-init-bin/default.nix
Normal file
33
pkgs/s6-init-bin/default.nix
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
s6-linux-init
|
||||||
|
, execline
|
||||||
|
, writeScript
|
||||||
|
, stdenvNoCC
|
||||||
|
, lib
|
||||||
|
, busybox
|
||||||
|
, s6-rc
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
hpr = name: arg: writeScript name ''
|
||||||
|
#!${execline}/bin/execlineb -S0
|
||||||
|
${s6-linux-init}/bin/s6-linux-init-hpr ${arg} \$@
|
||||||
|
'';
|
||||||
|
init = writeScript "init" ''
|
||||||
|
#!${execline}/bin/execlineb -S0
|
||||||
|
${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 -- "\$@"
|
||||||
|
'';
|
||||||
|
in stdenvNoCC.mkDerivation {
|
||||||
|
name = "s6-init-bin";
|
||||||
|
phases = ["installPhase"];
|
||||||
|
installPhase = ''
|
||||||
|
bin=$out/bin
|
||||||
|
mkdir -p $bin
|
||||||
|
cd $bin
|
||||||
|
ln -s ${s6-linux-init}/bin/s6-linux-init-shutdown shutdown
|
||||||
|
ln -s ${s6-linux-init}/bin/s6-linux-init-telinit telinit
|
||||||
|
ln -s ${hpr "reboot" "-r"} reboot
|
||||||
|
ln -s ${hpr "poweroff" "-p"} poweroff
|
||||||
|
ln -s ${hpr "halt" "-h"} halt
|
||||||
|
ln -s ${init} init
|
||||||
|
'';
|
||||||
|
}
|
@ -23,18 +23,6 @@ let
|
|||||||
};
|
};
|
||||||
dir = contents: { type = "d"; inherit contents; };
|
dir = contents: { type = "d"; inherit contents; };
|
||||||
symlink = target: { type = "s"; inherit target; };
|
symlink = target: { type = "s"; inherit target; };
|
||||||
hpr = arg: "#!${execline}/bin/execlineb -S0\n${s6-linux-init}/bin/s6-linux-init-hpr ${arg} \$@";
|
|
||||||
bin = dir {
|
|
||||||
shutdown = symlink "${s6-linux-init}/bin/s6-linux-init-shutdown";
|
|
||||||
telinit = symlink "${s6-linux-init}/bin/s6-linux-init-telinit";
|
|
||||||
reboot = { type="f"; file = hpr "-r"; mode="0755"; };
|
|
||||||
poweroff = { type="f"; file = hpr "-p"; mode="0755"; };
|
|
||||||
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 [busybox execline s6-linux-init s6-rc]}:/usr/bin:/bin -d /dev -- \"\\$@\"";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
scripts = symlink "${initscripts}/scripts";
|
scripts = symlink "${initscripts}/scripts";
|
||||||
env = dir {};
|
env = dir {};
|
||||||
run-image = dir {
|
run-image = dir {
|
||||||
@ -150,7 +138,7 @@ let
|
|||||||
uncaught-logs = (dir {}) // {mode = "2750";};
|
uncaught-logs = (dir {}) // {mode = "2750";};
|
||||||
};
|
};
|
||||||
structure = { etc = dir { s6-linux-init = dir { current = dir {
|
structure = { etc = dir { s6-linux-init = dir { current = dir {
|
||||||
inherit bin scripts env run-image;
|
inherit scripts env run-image;
|
||||||
};};};};
|
};};};};
|
||||||
|
|
||||||
in pseudofile "pseudo.s6-init" structure
|
in pseudofile "pseudo.s6-init" structure
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{ config, pkgs, ... } :
|
{ config, pkgs, ... } :
|
||||||
let
|
let
|
||||||
inherit (pkgs.liminix.networking) interface address pppoe;
|
inherit (pkgs.liminix.networking) interface address pppoe route;
|
||||||
inherit (pkgs.liminix.services) oneshot longrun bundle target output;
|
inherit (pkgs.liminix.services) oneshot longrun bundle target output;
|
||||||
in rec {
|
in rec {
|
||||||
services.loopback =
|
services.loopback =
|
||||||
@ -40,24 +40,32 @@ in rec {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.defaultroute4 =
|
services.defaultroute4 = route {
|
||||||
let iface = services.pppoe;
|
name = "defautlrote";
|
||||||
|
via = "$(cat ${output services.pppoe "address"})";
|
||||||
|
target = "default";
|
||||||
|
dependencies = [ services.pppoe ];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.packet_forwarding =
|
||||||
|
let
|
||||||
|
iface = services.pppoe;
|
||||||
|
filename = "/proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"})/forwarding";
|
||||||
in oneshot {
|
in oneshot {
|
||||||
name = "defaultroute4";
|
name = "let-the-ip-flow";
|
||||||
up = ''
|
up = "echo 1 > ${filename}";
|
||||||
ip route add default via $(cat ${output iface "address"})
|
down = "echo 0 > ${filename}";
|
||||||
echo "1" > /proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"}/forwarding)
|
|
||||||
'';
|
|
||||||
down = ''
|
|
||||||
ip route del default via $(cat ${output iface "address"})
|
|
||||||
echo "0" > /proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"}/forwarding)
|
|
||||||
'';
|
|
||||||
dependencies = [iface];
|
dependencies = [iface];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.default = target {
|
services.default = target {
|
||||||
name = "default";
|
name = "default";
|
||||||
contents = with services; [ loopback defaultroute4 syslogd ];
|
contents = with services; [
|
||||||
|
loopback
|
||||||
|
defaultroute4
|
||||||
|
packet_forwarding
|
||||||
|
syslogd
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
systemPackages = [ pkgs.hello ] ;
|
systemPackages = [ pkgs.hello ] ;
|
||||||
|
@ -12,6 +12,7 @@ while { $FINISHED < 5 } {
|
|||||||
expect {
|
expect {
|
||||||
"192.168.100.1" { set FINISHED 10; set EXIT 0; }
|
"192.168.100.1" { set FINISHED 10; set EXIT 0; }
|
||||||
"can't find device" { send_user "waiting ..." ; send "\r\n"; sleep 3 }
|
"can't find device" { send_user "waiting ..." ; send "\r\n"; sleep 3 }
|
||||||
|
"DOWN" { send_user "waiting ..." ; send "\r\n"; sleep 2 }
|
||||||
}
|
}
|
||||||
set FINISHED [ expr $FINISHED + 1 ]
|
set FINISHED [ expr $FINISHED + 1 ]
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{ config, pkgs, ... } :
|
{ config, pkgs, ... } :
|
||||||
let
|
let
|
||||||
inherit (pkgs.liminix.networking) interface address udhcpc odhcpc;
|
inherit (pkgs.liminix.networking) interface address udhcpc odhcpc route;
|
||||||
inherit (pkgs.liminix.services) oneshot longrun bundle target output;
|
inherit (pkgs.liminix.services) oneshot longrun bundle target output;
|
||||||
in rec {
|
in rec {
|
||||||
services.loopback =
|
services.loopback =
|
||||||
@ -40,18 +40,22 @@ in rec {
|
|||||||
dependencies = [services.dhcpv4];
|
dependencies = [services.dhcpv4];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.defaultroute4 =
|
services.defaultroute4 = route {
|
||||||
let inherit (services) dhcpv4;
|
name = "defautlrote";
|
||||||
|
via = "$(cat ${output services.dhcpv4 "address"})";
|
||||||
|
target = "default";
|
||||||
|
dependencies = [ services.dhcpv4 ];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.packet_forwarding =
|
||||||
|
let
|
||||||
|
iface = services.dhcpv4;
|
||||||
|
filename = "/proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"})/forwarding";
|
||||||
in oneshot {
|
in oneshot {
|
||||||
name = "defaultroute4";
|
name = "let-the-ip-flow";
|
||||||
up = ''
|
up = "echo 1 > ${filename}";
|
||||||
ip route add default gw $(cat ${output dhcpv4 "address"})
|
down = "echo 0 > ${filename}";
|
||||||
echo "1" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"})
|
dependencies = [iface];
|
||||||
'';
|
|
||||||
down = ''
|
|
||||||
ip route del default gw $(cat ${output dhcpv4 "address"})
|
|
||||||
echo "0" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"})
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
services.default = target {
|
services.default = target {
|
||||||
|
Loading…
Reference in New Issue
Block a user