Compare commits
4 Commits
0ed97a5232
...
e9f04931fa
Author | SHA1 | Date | |
---|---|---|---|
e9f04931fa | |||
2d7bb6b2fa | |||
f030efbd49 | |||
7f280b5d6a |
@ -114,7 +114,12 @@ Assuming you have nixpkgs checked out in a peer directory of this one,
|
|||||||
|
|
||||||
NIX_PATH=nixpkgs=../nixpkgs:$NIX_PATH ./run-tests.sh
|
NIX_PATH=nixpkgs=../nixpkgs:$NIX_PATH ./run-tests.sh
|
||||||
|
|
||||||
## Diagnosing unexpectedly large images
|
Some of the tests require the emulated upstream connection to be running.
|
||||||
|
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Diagnosing unexpectedly large images
|
||||||
|
|
||||||
Sometimes you can add a package and it causes the image size to balloon
|
Sometimes you can add a package and it causes the image size to balloon
|
||||||
because it has dependencies on other things you didn't know about. Build the
|
because it has dependencies on other things you didn't know about. Build the
|
||||||
|
@ -10,10 +10,11 @@ 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 -e "#!$shell\n$run" > $out/${name}/run)
|
test -n "$run" && (echo -e "$run" > $out/${name}/run)
|
||||||
test -n "${notificationFd}" && (echo ${notificationFd} > $out/${name}/notification-fd)
|
test -n "${notificationFd}" && (echo ${notificationFd} > $out/${name}/notification-fd)
|
||||||
test -n "$up" && (echo -e "#!$shell\n$up" > $out/${name}/up)
|
test -n "$up" && (echo -e "$up" > $out/${name}/up)
|
||||||
test -n "$down" && (echo -e "#!$shell\n$down" > $out/${name}/down)
|
test -n "$down" && (echo -e "$down" > $out/${name}/down)
|
||||||
|
( cd $out && ln -s /run/service-state/${name} ./.outputs )
|
||||||
for i in $out/${name}/{down,up,run} ; do test -f $i && chmod +x $i; done
|
for i in $out/${name}/{down,up,run} ; do test -f $i && chmod +x $i; done
|
||||||
true
|
true
|
||||||
# (echo $out/${name} && cd $out/${name} && find . -ls)
|
# (echo $out/${name} && cd $out/${name} && find . -ls)
|
||||||
|
@ -4,27 +4,47 @@
|
|||||||
, lib
|
, lib
|
||||||
, busybox
|
, busybox
|
||||||
, callPackage
|
, callPackage
|
||||||
, writeAshScript
|
, writeScript
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (builtins) concatStringsSep;
|
inherit (builtins) concatStringsSep;
|
||||||
output = service: name: "/run/service-state/${service.name}/${name}";
|
output = service: name: "/run/service-state/${service.name}/${name}";
|
||||||
|
serviceScript = commands : ''
|
||||||
|
#!${busybox}/bin/sh
|
||||||
|
output() { cat $1/.outputs/$2; }
|
||||||
|
${commands}
|
||||||
|
'';
|
||||||
|
service = {
|
||||||
|
name
|
||||||
|
, serviceType
|
||||||
|
, run ? null
|
||||||
|
, up ? null
|
||||||
|
, down ? null
|
||||||
|
, outputs ? []
|
||||||
|
, notification-fd ? null
|
||||||
|
, dependencies ? []
|
||||||
|
, contents ? []
|
||||||
|
} @ args: stdenvNoCC.mkDerivation {
|
||||||
|
# we use stdenvNoCC to avoid generating derivations with names
|
||||||
|
# like foo.service-mips-linux-musl
|
||||||
|
inherit name serviceType up down run;
|
||||||
|
buildInputs = dependencies ++ contents;
|
||||||
|
dependencies = builtins.map (d: d.name) dependencies;
|
||||||
|
contents = builtins.map (d: d.name) contents;
|
||||||
|
notificationFd = notification-fd;
|
||||||
|
builder = ./builder.sh;
|
||||||
|
};
|
||||||
|
|
||||||
longrun = {
|
longrun = {
|
||||||
name
|
name
|
||||||
, run
|
, run
|
||||||
, outputs ? []
|
, outputs ? []
|
||||||
, notification-fd ? null
|
, notification-fd ? null
|
||||||
, dependencies ? []
|
, dependencies ? []
|
||||||
} @ args: stdenvNoCC.mkDerivation {
|
} @ args: service (args //{
|
||||||
inherit name;
|
|
||||||
serviceType = "longrun";
|
serviceType = "longrun";
|
||||||
buildInputs = dependencies;
|
run = serviceScript run;
|
||||||
dependencies = builtins.map (d: d.name) dependencies;
|
});
|
||||||
shell = "${busybox}/bin/sh";
|
|
||||||
inherit run;
|
|
||||||
notificationFd = notification-fd;
|
|
||||||
builder = ./builder.sh;
|
|
||||||
};
|
|
||||||
oneshot = {
|
oneshot = {
|
||||||
name
|
name
|
||||||
, up
|
, up
|
||||||
@ -32,37 +52,21 @@ let
|
|||||||
, outputs ? []
|
, outputs ? []
|
||||||
, dependencies ? []
|
, dependencies ? []
|
||||||
, ...
|
, ...
|
||||||
} @ args: stdenvNoCC.mkDerivation {
|
} @ args : service (args // {
|
||||||
# stdenvNoCC is to avoid generating derivations with names
|
|
||||||
# like foo.service-mips-linux-musl
|
|
||||||
inherit name;
|
|
||||||
serviceType = "oneshot";
|
serviceType = "oneshot";
|
||||||
# does this suffice to make sure dependencies are included
|
up = writeScript "${name}-up" (serviceScript up);
|
||||||
# even though the built output has no references to their
|
down= writeScript "${name}-down" (serviceScript down);
|
||||||
# store directories?
|
});
|
||||||
buildInputs = dependencies;
|
bundle = {
|
||||||
shell = "${busybox}/bin/sh";
|
|
||||||
# up and down for oneshots are pathnames not scripts
|
|
||||||
up = writeAshScript "${name}-up" {} up;
|
|
||||||
down = writeAshScript "${name}-down" {} down;
|
|
||||||
dependencies = builtins.map (d: d.name) dependencies;
|
|
||||||
builder = ./builder.sh;
|
|
||||||
};
|
|
||||||
target = {
|
|
||||||
name
|
name
|
||||||
, contents ? []
|
, contents ? []
|
||||||
, dependencies ? []
|
, dependencies ? []
|
||||||
, ...
|
, ...
|
||||||
}: stdenvNoCC.mkDerivation {
|
} @ args: service (args // {
|
||||||
inherit name;
|
|
||||||
serviceType = "bundle";
|
serviceType = "bundle";
|
||||||
contents = builtins.map (d: d.name) contents;
|
inherit contents dependencies;
|
||||||
buildInputs = dependencies ++ contents;
|
});
|
||||||
dependencies = builtins.map (d: d.name) dependencies;
|
target = bundle;
|
||||||
shell = "${busybox}/bin/sh";
|
|
||||||
builder = ./builder.sh;
|
|
||||||
};
|
|
||||||
bundle = { name, ... } @args : target (args // { inherit name;});
|
|
||||||
in {
|
in {
|
||||||
inherit target bundle oneshot longrun output;
|
inherit target bundle oneshot longrun output;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
INIT=${INIT-/bin/init}
|
INIT=${INIT-/bin/init}
|
||||||
|
echo $QEMU_OPTIONS
|
||||||
qemu-system-mips \
|
qemu-system-mips \
|
||||||
-M malta -m 256 \
|
-M malta -m 256 \
|
||||||
-echr 16 \
|
-echr 16 \
|
||||||
@ -22,4 +22,4 @@ qemu-system-mips \
|
|||||||
-device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:21:02 \
|
-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 \
|
-netdev socket,id=lan,mcast=230.0.0.1:1235 \
|
||||||
-device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=lan,mac=ba:ad:1d:ea:21:01 \
|
-device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=lan,mac=ba:ad:1d:ea:21:01 \
|
||||||
-kernel $1 -display none $flags
|
-kernel $1 -display none $flags ${QEMU_OPTIONS}
|
||||||
|
@ -41,7 +41,7 @@ in rec {
|
|||||||
|
|
||||||
services.defaultroute4 = route {
|
services.defaultroute4 = route {
|
||||||
name = "defautlrote";
|
name = "defautlrote";
|
||||||
via = "$(cat ${output services.pppoe "address"})";
|
via = "$(output ${services.pppoe} address)";
|
||||||
target = "default";
|
target = "default";
|
||||||
dependencies = [ services.pppoe ];
|
dependencies = [ services.pppoe ];
|
||||||
};
|
};
|
||||||
@ -49,7 +49,7 @@ in rec {
|
|||||||
services.packet_forwarding =
|
services.packet_forwarding =
|
||||||
let
|
let
|
||||||
iface = services.pppoe;
|
iface = services.pppoe;
|
||||||
filename = "/proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"})/forwarding";
|
filename = "/proc/sys/net/ipv4/conf/$(output ${iface} ifname)/forwarding";
|
||||||
in oneshot {
|
in oneshot {
|
||||||
name = "let-the-ip-flow";
|
name = "let-the-ip-flow";
|
||||||
up = "echo 1 > ${filename}";
|
up = "echo 1 > ${filename}";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{ config, pkgs, ... } :
|
{ config, pkgs, ... } :
|
||||||
let
|
let
|
||||||
inherit (pkgs.liminix.networking) interface address udhcpc odhcpc route;
|
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;
|
||||||
in rec {
|
in rec {
|
||||||
services.loopback =
|
services.loopback =
|
||||||
let iface = interface { type = "loopback"; device = "lo";};
|
let iface = interface { type = "loopback"; device = "lo";};
|
||||||
@ -21,11 +21,9 @@ in rec {
|
|||||||
in odhcpc iface { uid = "e7"; };
|
in odhcpc iface { uid = "e7"; };
|
||||||
|
|
||||||
services.ntp = longrun {
|
services.ntp = longrun {
|
||||||
# the simplest approach at the consumer end is to require the
|
|
||||||
# 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/ntpd $(cat ${output dhcpv4 "ntp_servers"}) $(cat ${output dhcpv6 "NTP_IP"})";
|
in "${pkgs.ntp}/bin/ntpd $(output ${dhcpv4} ntp_servers) $(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
|
||||||
@ -42,7 +40,7 @@ in rec {
|
|||||||
|
|
||||||
services.defaultroute4 = route {
|
services.defaultroute4 = route {
|
||||||
name = "defautlrote";
|
name = "defautlrote";
|
||||||
via = "$(cat ${output services.dhcpv4 "address"})";
|
via = "$(output ${services.dhcpv4} address)";
|
||||||
target = "default";
|
target = "default";
|
||||||
dependencies = [ services.dhcpv4 ];
|
dependencies = [ services.dhcpv4 ];
|
||||||
};
|
};
|
||||||
@ -50,7 +48,7 @@ in rec {
|
|||||||
services.packet_forwarding =
|
services.packet_forwarding =
|
||||||
let
|
let
|
||||||
iface = services.dhcpv4;
|
iface = services.dhcpv4;
|
||||||
filename = "/proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"})/forwarding";
|
filename = "/proc/sys/net/ipv4/conf/$(output ${iface} ifname)/forwarding";
|
||||||
in oneshot {
|
in oneshot {
|
||||||
name = "let-the-ip-flow";
|
name = "let-the-ip-flow";
|
||||||
up = "echo 1 > ${filename}";
|
up = "echo 1 > ${filename}";
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
To test a router, we need an upstream connection. In this directory,
|
To test a router, we need an upstream connection. In this directory,
|
||||||
find
|
find
|
||||||
|
|
||||||
* run.sh, a script that will start a RouterOS image in qemu.
|
* chr.sh, a script that will start a RouterOS image in qemu.
|
||||||
Login when prompted, username is "admin", blank password
|
Login when prompted, username is "admin", blank password
|
||||||
* routeros.config, a set of commands you can feed into routeros
|
* routeros.config, a set of commands you can feed into routeros
|
||||||
to set up PPPoE
|
to set up PPPoE
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{ config, pkgs, lib, ... } :
|
{ config, pkgs, lib, ... } :
|
||||||
let
|
let
|
||||||
inherit (pkgs.liminix.networking) interface address hostapd route dnsmasq;
|
inherit (pkgs.liminix.networking) interface address hostapd route dnsmasq;
|
||||||
inherit (pkgs.liminix.services) oneshot longrun bundle target output;
|
inherit (pkgs.liminix.services) oneshot longrun bundle target;
|
||||||
in rec {
|
in rec {
|
||||||
services.loopback =
|
services.loopback =
|
||||||
let iface = interface { type = "loopback"; device = "lo";};
|
let iface = interface { type = "loopback"; device = "lo";};
|
||||||
|
Loading…
Reference in New Issue
Block a user