Compare commits

...

6 Commits

11 changed files with 138 additions and 45 deletions

View File

@ -19,4 +19,7 @@ expression or there is more than one reference to `up`, `down` etc.
* the parameters to a derivation are sorted alphabetically, except for
`lib`, `stdenv` and maybe other non-package "special cases"
* indentation is whatever emacs nix-mode says it is
* indentation is whatever emacs nix-mode says it is.
* where a `let` form defines multiple names, put a newline after the
token `let`, and indent each name two characters

View File

@ -73,12 +73,57 @@ Fri Sep 23 10:27:22 BST 2022
Sun Sep 25 20:56:28 BST 2022
1) shutdown doesn't work as its using the busybox one not s6
TODO - bugs, missing bits, other infelicities as they occur to me:
2) think we shouldn't have process-based services like dhcp, ppp
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
implement "address provider interface" - instead have a separate
service for interface address that depends on the service and uses its
output
* ppp is not like dhcp because dhcp finds addresses for an existing
interface but ppp makes a new one
3) when I killed ppp it restarted, but I don't think it reran
defaultroute which is supposed to depend on it. (Might be important
e.g. if we'd been assigned a different IP address). Investigate
semantics of s6-rc service dependencies
DONE 4) make the pppoe test run unattended
5) write a test for udhcp
6) squashfs size is ~ 14MB for a configuration with not much in it,
look for obvious wastes of space
7) some of the pppoe config should be moved into a ppp service
8) some of configuration.nix (e.g. defining routes) should be moved into
tools
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
switch to ubifs? will there always be a squashfs underneath? might
we want to change the pseudofiles in an overlay?
11) haven't done (overlayfs) overlays at all
12) overlay.nix needs splitting up
13) upgrade ppp to something with an ipv6-up-script option
14) add ipv6 support generally
15) "ip address add" seems to magically recognise v4 vs v6 but
is that specified or fluke?
16) tighten up the module specs. (DONE) services.foo should be a s6-rc
service, kernel config should be checked in some way
DONE 17) rename nixwrt references in kernel builder
18) maybe stop suffixing all the service names with .service
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"

View File

@ -16,7 +16,9 @@ let
;
};
squashfs = (import ./make-image.nix) nixpkgs finalConfig;
kernel = (import ./make-kernel.nix) nixpkgs finalConfig.kernel.config;
kernel = nixpkgs.pkgs.callPackage ./kernel {
inherit (finalConfig.kernel) config;
};
in {
outputs = {
inherit squashfs kernel;

View File

@ -1,19 +1,32 @@
pkgs: config:
{
callPackage
, buildPackages
, stdenvNoCC
, fetchFromGitHub
, config
}:
let
inherit (pkgs) callPackage buildPackages stdenvNoCC fetchFromGitHub;
source = fetchFromGitHub {
owner = "torvalds";
repo = "linux";
rev = "3d7cb6b04c3f3115719235cc6866b10326de34cd"; # v5.19
hash = "sha256-OVsIRScAnrPleW1vbczRAj5L/SGGht2+GnvZJClMUu4=";
};
# The kernel is huge and takes a long time just to
# download and unpack. This derivation creates
# a source tree in a suitable shape to build from -
# today it just patches some scripts but as we add
# support for boards/SoCs we expect the scope of
# "pre-treatment" to grow
tree = stdenvNoCC.mkDerivation {
name = "spindled-kernel-tree";
src = source;
phases = [ "unpackPhase" "patchScripts" "installPhase" ];
patchScripts = ''
patchShebangs scripts/
# substituteInPlace Makefile --replace /bin/pwd ${buildPackages.pkgs.coreutils}/bin/pwd
'';
installPhase = ''
mkdir -p $out
@ -22,7 +35,7 @@ let
};
in
{
vmlinux = callPackage ./make-vmlinux.nix {
vmlinux = callPackage ./vmlinux.nix {
inherit tree;
inherit config;
};

View File

@ -15,7 +15,7 @@ let writeConfig = name : config: writeText name
(name: value: (if value == "n" then "# CONFIG_${name} is not set" else "CONFIG_${name}=${value}"))
config
));
kconfigFile = writeConfig "nixwrt_kconfig" config;
kconfigFile = writeConfig "kconfig" config;
checkedConfigFile = writeConfig "checked_kconfig" checkedConfig ;
inherit lib; in
stdenv.mkDerivation rec {
@ -26,38 +26,36 @@ stdenv.mkDerivation rec {
(with buildPackages.pkgs;
[rsync bc bison flex pkgconfig openssl ncurses.all perl]);
CC = "${stdenv.cc.bintools.targetPrefix}gcc";
HOSTCC = "gcc -I${buildPackages.pkgs.openssl}/include -I${buildPackages.pkgs.ncurses}/include";
HOST_EXTRACFLAGS = "-I${buildPackages.pkgs.openssl.dev}/include -L${buildPackages.pkgs.openssl.out}/lib -L${buildPackages.pkgs.ncurses.out}/lib " ;
HOSTCC = with buildPackages.pkgs;
"gcc -I${openssl}/include -I${ncurses}/include";
HOST_EXTRACFLAGS = with buildPackages.pkgs;
"-I${openssl.dev}/include -L${openssl.out}/lib -L${ncurses.out}/lib";
PKG_CONFIG_PATH = "./pkgconfig";
CROSS_COMPILE = stdenv.cc.bintools.targetPrefix;
ARCH = "mips"; # kernel uses "mips" here for both mips and mipsel
dontStrip = true;
dontPatchELF = true;
outputs = ["out" "modulesupport"];
phases = ["butcherPkgconfig"
# "patchScripts"
"configurePhase"
"checkConfigurationPhase"
"buildPhase"
"installPhase"
];
phases = [
"butcherPkgconfig"
"configurePhase"
"checkConfigurationPhase"
"buildPhase"
"installPhase"
];
# this is here to work around what I think is a bug in nixpkgs packaging
# of ncurses: it installs pkg-config data files which don't produce
# any -L options when queried with "pkg-config --lib ncurses". For a
# regular nixwrt compilation you'll never even notice, this only becomes
# an issue if you do a nix-shell in this derivation and expect "make nconfig"
# to work.
# this is here to work around what I think is a bug in nixpkgs
# packaging of ncurses: it installs pkg-config data files which
# don't produce any -L options when queried with "pkg-config --lib
# ncurses". For a regular build you'll never even notice, this only
# becomes an issue if you do a nix-shell in this derivation and
# expect "make nconfig" to work.
butcherPkgconfig = ''
cp -r ${buildPackages.pkgs.ncurses.dev}/lib/pkgconfig .
chmod +w pkgconfig pkgconfig/*.pc
for i in pkgconfig/*.pc; do test -f $i && sed -i 's/^Libs:/Libs: -L''${libdir} /' $i;done
'';
# patchScripts = ''
# patchShebangs --build scripts/
# '';
configurePhase = ''
export KBUILD_OUTPUT=`pwd`
cp ${kconfigFile} .config
@ -74,7 +72,7 @@ stdenv.mkDerivation rec {
echo "OK"
'';
KBUILD_BUILD_HOST = "nixwrt.builder";
KBUILD_BUILD_HOST = "liminix.builder";
buildPhase = ''
make -C ${tree} vmlinux
'';

View File

@ -1,12 +1,19 @@
{ lib, ...}:
let inherit (lib) mkEnableOption mkOption types;
let
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr ;
type_service = types.package // {
name = "service";
description = "s6-rc service";
check = x: isDerivation x && hasAttr "serviceType" x;
};
in {
options = {
systemPackages = mkOption {
type = types.listOf types.package;
};
services = mkOption {
type = types.anything;
type = types.attrsOf type_service;
};
kernel = mkOption {
type = types.anything;

View File

@ -1,6 +1,6 @@
source $stdenv/setup
mkdir -p $out/${name}
echo $type > $out/${name}/type
echo $serviceType > $out/${name}/type
mkdir -p $out/${name}/dependencies.d
echo $buildInputs > $out/buildInputs
test -n "$dependencies" && for d in $dependencies; do

View File

@ -15,7 +15,7 @@
, dependencies ? []
} @ args: stdenvNoCC.mkDerivation {
name = "${name}.service";
type = "longrun";
serviceType = "longrun";
buildInputs = dependencies;
dependencies = builtins.map (d: d.name) dependencies;
shell = "${busybox}/bin/sh";
@ -34,7 +34,7 @@
# stdenvNoCC is to avoid generating derivations with names
# like foo.service-mips-linux-musl
name = "${name}.service";
type = "oneshot";
serviceType = "oneshot";
# does this suffice to make sure dependencies are included
# even though the built output has no references to their
# store directories?
@ -53,7 +53,7 @@
, ...
}: stdenvNoCC.mkDerivation {
inherit name;
type = "bundle";
serviceType = "bundle";
contents = builtins.map (d: d.name) contents;
buildInputs = dependencies ++ contents;
dependencies = builtins.map (d: d.name) dependencies;

View File

@ -3,8 +3,9 @@
if test "$1" = "--background" ; then
socket=$2
echo "running in background, socket is $socket"
flags="--daemonize -chardev socket,id=sock,path=$2,server=on,wait=off,mux=on -mon chardev=sock,mode=readline -serial chardev:sock "
pid="`dirname $socket`/`basename $socket .sock`.pid"
echo "running in background, socket is $socket, pid $pid"
flags="--daemonize --pidfile $pid -chardev socket,id=sock,path=$2,server=on,wait=off,mux=on -mon chardev=sock,mode=readline -serial chardev:sock "
shift;shift
else
flags="-serial mon:stdio"

View File

@ -0,0 +1,19 @@
set timeout 60
spawn socat unix-connect:foo.sock -
send "\r\n"
expect "login:" { send "root\r\n" }
expect "/ #"
set FINISHED 0
set EXIT "1"
while { $FINISHED < 5 } {
send "ip address show dev ppp0 | grep ppp0\r\n"
expect {
"192.168.100.1" { set FINISHED 10; set EXIT 0; }
"can't find device" { send_user "waiting ..." ; send "\r\n"; sleep 3 }
}
set FINISHED [ expr $FINISHED + 1 ]
}
exit $EXIT

View File

@ -1,20 +1,25 @@
#!/usr/bin/env sh
set -e
cleanup(){
echo "do cleanup";
if test -e foo.pid && test -d /proc/`cat foo.pid` ; then
echo "killing qemu"
kill `cat foo.pid`
fi
}
trap cleanup EXIT
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
fatal(){
err=$?
echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err"
exit $err
}
trap fatal ERR
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/qemu.nix>" -A outputs.default $*
if ! ( echo "cont" | socat - unix-connect:../support/ppp-server/qemu-monitor); then
if ! ( echo "cont" | socat - unix-connect:../support/ppp-server/qemu-monitor); then
echo "need pppoe server running"
exit 1
fi
../../scripts/run-qemu.sh result/vmlinux result/squashfs
../../scripts/run-qemu.sh --background foo.sock result/vmlinux result/squashfs
nix-shell -p expect --run "expect getaddress.expect"