Compare commits

..

No commits in common. "1b1aa9de76d9ea504a10931b15d24757ba6d2a72" and "617355773ec4429dcb4a8b6a6a8df446699d6547" have entirely different histories.

11 changed files with 45 additions and 138 deletions

View File

@ -19,7 +19,4 @@ expression or there is more than one reference to `up`, `down` etc.
* the parameters to a derivation are sorted alphabetically, except for * the parameters to a derivation are sorted alphabetically, except for
`lib`, `stdenv` and maybe other non-package "special cases" `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,57 +73,12 @@ Fri Sep 23 10:27:22 BST 2022
Sun Sep 25 20:56:28 BST 2022 Sun Sep 25 20:56:28 BST 2022
TODO - bugs, missing bits, other infelicities as they occur to me: 1) shutdown doesn't work as its using the busybox one not s6
1) shutdown doesn't work as its using the busybox one not s6. 2) think 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
service for interface address that depends on the service and uses its service for interface address that depends on the service and uses its
output output
* ppp is not like dhcp because dhcp finds addresses for an existing * ppp is not like dhcp because dhcp finds addresses for an existing
interface but ppp makes a new one 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,9 +16,7 @@ let
; ;
}; };
squashfs = (import ./make-image.nix) nixpkgs finalConfig; squashfs = (import ./make-image.nix) nixpkgs finalConfig;
kernel = nixpkgs.pkgs.callPackage ./kernel { kernel = (import ./make-kernel.nix) nixpkgs finalConfig.kernel.config;
inherit (finalConfig.kernel) config;
};
in { in {
outputs = { outputs = {
inherit squashfs kernel; inherit squashfs kernel;

View File

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

View File

@ -1,19 +1,12 @@
{ lib, ...}: { lib, ...}:
let let inherit (lib) mkEnableOption mkOption types;
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 { in {
options = { options = {
systemPackages = mkOption { systemPackages = mkOption {
type = types.listOf types.package; type = types.listOf types.package;
}; };
services = mkOption { services = mkOption {
type = types.attrsOf type_service; type = types.anything;
}; };
kernel = mkOption { kernel = mkOption {
type = types.anything; type = types.anything;

View File

@ -1,6 +1,6 @@
source $stdenv/setup source $stdenv/setup
mkdir -p $out/${name} mkdir -p $out/${name}
echo $serviceType > $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

View File

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

View File

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

View File

@ -1,19 +0,0 @@
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,25 +1,20 @@
#!/usr/bin/env sh #!/usr/bin/env sh
set -e
cleanup(){ cleanup(){
if test -e foo.pid && test -d /proc/`cat foo.pid` ; then echo "do cleanup";
echo "killing qemu"
kill `cat foo.pid`
fi
} }
trap cleanup EXIT trap cleanup EXIT
fatal(){ trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
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 $* 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" echo "need pppoe server running"
exit 1 exit 1
fi fi
../../scripts/run-qemu.sh --background foo.sock result/vmlinux result/squashfs ../../scripts/run-qemu.sh result/vmlinux result/squashfs
nix-shell -p expect --run "expect getaddress.expect"