liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4389fa15f712eb592309c226f3d3f4c74dcb58a1
parent 4f29bdd3ed9be1b16627522d8b247b9baf185566
Author: Daniel Barlow <dan@telent.net>
Date:   Wed, 20 Sep 2023 18:33:08 +0100

rename mips-vm as run-liminix-vm

Diffstat:
Mdefault.nix | 2+-
Mdevices/qemu/default.nix | 2+-
Mdoc/development.rst | 6+++---
Mdoc/tutorial.rst | 2+-
Mmodules/outputs.nix | 2+-
Mpkgs/default.nix | 2+-
Dpkgs/mips-vm/default.nix | 19-------------------
Dpkgs/mips-vm/mips-vm.sh | 55-------------------------------------------------------
Apkgs/run-liminix-vm/default.nix | 19+++++++++++++++++++
Apkgs/run-liminix-vm/mips-vm.sh | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/jffs2/test.nix | 6+++---
Mtests/min-copy-closure/test.nix | 6+++---
Mtests/pppoe/test.nix | 6+++---
Mtests/wlan/test.nix | 6+++---
14 files changed, 94 insertions(+), 94 deletions(-)

diff --git a/default.nix b/default.nix @@ -54,7 +54,7 @@ in { tufted routeros.routeros routeros.ros-exec-script - mips-vm + run-liminix-vm borderVm.build.vm go-l2tp min-copy-closure diff --git a/devices/qemu/default.nix b/devices/qemu/default.nix @@ -50,7 +50,7 @@ }; in { defaultOutput = "vmroot"; - flash.eraseBlockSize = "65536"; # c.f. pkgs/mips-vm/mips-vm.sh + flash.eraseBlockSize = "65536"; # c.f. pkgs/run-liminix-vm/run-liminix-vm.sh networkInterfaces = let inherit (config.system.service.network) link; in { diff --git a/doc/development.rst b/doc/development.rst @@ -27,13 +27,13 @@ To build it, nix-build -I liminix-config=path/to/your/configuration.nix --arg device "import ./devices/qemu" -A outputs.default -In a ``buildEnv`` nix-shell, you can use the :command:`mips-vm` command +In a ``buildEnv`` nix-shell, you can use the :command:`run-liminix-vm` command to run Qemu with appropriate options. It connects the Liminix serial console and the `QEMU monitor <https://www.qemu.org/docs/master/system/monitor.html>`_ to stdin/stdout. Use ^P (not ^A) to switch to the monitor. .. code-block:: console - nix-shell --run "mips-vm result/vmlinux result/squashfs" + nix-shell --run "run-liminix-vm result/vmlinux result/squashfs" If you run with ``--background /path/to/some/directory`` as the first parameter, it will fork into the background and open Unix sockets in @@ -53,7 +53,7 @@ the right way: * multicast 230.0.0.1:1235 : lan * multicast 230.0.0.1:1236 : world (the internet) -A VM started with :command:`mips-vm` is connected to "lan" and "access", and +A VM started with :command:`run-liminix-vm` is connected to "lan" and "access", and the emulated border network gateway (see below) runs PPPoE and is connected to "access" and "world". diff --git a/doc/tutorial.rst b/doc/tutorial.rst @@ -60,7 +60,7 @@ Now you can try it: .. code-block:: console - nix-shell --run "mips-vm ./result/vmlinux ./result/rootfs" + nix-shell --run "run-liminix-vm ./result/vmlinux ./result/rootfs" This starts the Qemu emulator with a bunch of useful options, to run the Liminix configuration you just built. It connects the emulated diff --git a/modules/outputs.nix b/modules/outputs.nix @@ -36,7 +36,7 @@ in type = types.package; description = '' Directory containing separate kernel and rootfs image for - use with qemu (see mips-vm) + use with qemu (see run-liminix-vm) ''; }; manifest = mkOption { diff --git a/pkgs/default.nix b/pkgs/default.nix @@ -59,7 +59,7 @@ in { systemconfig = callPackage ./systemconfig {}; s6-init-bin = callPackage ./s6-init-bin {}; s6-rc-database = callPackage ./s6-rc-database {}; - mips-vm = callPackage ./mips-vm {}; + run-liminix-vm = callPackage ./run-liminix-vm {}; ppp = callPackage ./ppp {}; pppoe = callPackage ./pppoe {}; diff --git a/pkgs/mips-vm/default.nix b/pkgs/mips-vm/default.nix @@ -1,19 +0,0 @@ -{ - qemu -, socat -, writeShellScriptBin -, symlinkJoin -, lib -}: let - mips-vm = writeShellScriptBin "mips-vm" '' - export PATH="${lib.makeBinPath [qemu]}:$PATH" - ${builtins.readFile ./mips-vm.sh} - ''; - connect = writeShellScriptBin "connect-vm" '' - export PATH="${lib.makeBinPath [socat]}:$PATH" - socat -,raw,echo=0,icanon=0,isig=0,icrnl=0,escape=0x0f unix-connect:$1 - ''; -in symlinkJoin { - name = "mips-vm"; - paths = [ mips-vm connect ]; -} diff --git a/pkgs/mips-vm/mips-vm.sh b/pkgs/mips-vm/mips-vm.sh @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -cleanup(){ - test -n "$rootfs" && test -f $rootfs && rm $rootfs -} -trap 'exit 1' INT HUP QUIT TERM ALRM USR1 -trap 'cleanup' EXIT - -usage(){ - echo "usage: $(basename $0) [--background /path/to/state_directory] kernel rootimg [initramfs]" - echo -e "\nWithout --background, use C-p c (not C-a c) to switch to the monitor" - exit 1 -} - -if test "$1" = "--background" ; then - statedir=$2 - if test -z "$statedir" || ! test -d $statedir ; then - usage - fi - pid="${statedir}/pid" - socket="${statedir}/console" - monitor="${statedir}/monitor" - echo "running in background, socket is $socket, pid $pid" - flags="--daemonize --pidfile $pid -serial unix:$socket,server,nowait -monitor unix:$monitor,server,nowait" - shift;shift -else - flags="-serial mon:stdio" -fi - -test -n "$2" || usage - -lan=${LAN-"socket,mcast=230.0.0.1:1235,localaddr=127.0.0.1"} - -rootfs=$(mktemp mips-vm-fs-XXXXXX) -dd if=/dev/zero of=$rootfs bs=1M count=16 conv=sync -dd if=$2 of=$rootfs bs=65536 conv=sync,nocreat,notrunc - -if test -n "$3"; then - initramfs="-initrd $3" -fi - - -INIT=${INIT-/bin/init} -echo $QEMU_OPTIONS -qemu-system-mips \ - -M malta -m 256 \ - -echr 16 \ - -append "liminix default console=ttyS0,38400n8 panic=10 oops=panic init=$INIT loglevel=8 root=/dev/mtdblock0 block2mtd.block2mtd=/dev/vda,65536" \ - -drive file=$rootfs,format=raw,readonly=off,if=virtio,index=0 \ - ${initramfs} \ - -netdev socket,id=access,mcast=230.0.0.1:1234,localaddr=127.0.0.1 \ - -device virtio-net,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:21:02 \ - -netdev ${lan},id=lan \ - -device virtio-net,disable-legacy=on,disable-modern=off,netdev=lan,mac=ba:ad:1d:ea:21:01 \ - -kernel $1 -display none $flags ${QEMU_OPTIONS} diff --git a/pkgs/run-liminix-vm/default.nix b/pkgs/run-liminix-vm/default.nix @@ -0,0 +1,19 @@ +{ + qemu +, socat +, writeShellScriptBin +, symlinkJoin +, lib +}: let + run-liminix-vm = writeShellScriptBin "run-liminix-vm" '' + export PATH="${lib.makeBinPath [qemu]}:$PATH" + ${builtins.readFile ./run-liminix-vm.sh} + ''; + connect = writeShellScriptBin "connect-vm" '' + export PATH="${lib.makeBinPath [socat]}:$PATH" + socat -,raw,echo=0,icanon=0,isig=0,icrnl=0,escape=0x0f unix-connect:$1 + ''; +in symlinkJoin { + name = "run-liminix-vm"; + paths = [ run-liminix-vm connect ]; +} diff --git a/pkgs/run-liminix-vm/mips-vm.sh b/pkgs/run-liminix-vm/mips-vm.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +cleanup(){ + test -n "$rootfs" && test -f $rootfs && rm $rootfs +} +trap 'exit 1' INT HUP QUIT TERM ALRM USR1 +trap 'cleanup' EXIT + +usage(){ + echo "usage: $(basename $0) [--background /path/to/state_directory] kernel rootimg [initramfs]" + echo -e "\nWithout --background, use C-p c (not C-a c) to switch to the monitor" + exit 1 +} + +if test "$1" = "--background" ; then + statedir=$2 + if test -z "$statedir" || ! test -d $statedir ; then + usage + fi + pid="${statedir}/pid" + socket="${statedir}/console" + monitor="${statedir}/monitor" + echo "running in background, socket is $socket, pid $pid" + flags="--daemonize --pidfile $pid -serial unix:$socket,server,nowait -monitor unix:$monitor,server,nowait" + shift;shift +else + flags="-serial mon:stdio" +fi + +test -n "$2" || usage + +lan=${LAN-"socket,mcast=230.0.0.1:1235,localaddr=127.0.0.1"} + +rootfs=$(mktemp run-liminix-vm-fs-XXXXXX) +dd if=/dev/zero of=$rootfs bs=1M count=16 conv=sync +dd if=$2 of=$rootfs bs=65536 conv=sync,nocreat,notrunc + +if test -n "$3"; then + initramfs="-initrd $3" +fi + + +INIT=${INIT-/bin/init} +echo $QEMU_OPTIONS +qemu-system-mips \ + -M malta -m 256 \ + -echr 16 \ + -append "liminix default console=ttyS0,38400n8 panic=10 oops=panic init=$INIT loglevel=8 root=/dev/mtdblock0 block2mtd.block2mtd=/dev/vda,65536" \ + -drive file=$rootfs,format=raw,readonly=off,if=virtio,index=0 \ + ${initramfs} \ + -netdev socket,id=access,mcast=230.0.0.1:1234,localaddr=127.0.0.1 \ + -device virtio-net,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:21:02 \ + -netdev ${lan},id=lan \ + -device virtio-net,disable-legacy=on,disable-modern=off,netdev=lan,mac=ba:ad:1d:ea:21:01 \ + -kernel $1 -display none $flags ${QEMU_OPTIONS} diff --git a/tests/jffs2/test.nix b/tests/jffs2/test.nix @@ -7,15 +7,15 @@ let img = (import liminix { liminix-config = ./configuration.nix; }).outputs.vmroot; pkgs = import <nixpkgs> { overlays = [(import ../../overlay.nix)]; }; - inherit (pkgs.pkgsBuildBuild) routeros mips-vm; + inherit (pkgs.pkgsBuildBuild) routeros run-liminix-vm; in pkgs.runCommand "check" { nativeBuildInputs = with pkgs; [ - mips-vm + run-liminix-vm expect socat ] ; } '' mkdir vm -mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs +run-liminix-vm --background ./vm ${img}/vmlinux ${img}/rootfs expect ${./script.expect} >$out '' diff --git a/tests/min-copy-closure/test.nix b/tests/min-copy-closure/test.nix @@ -9,11 +9,11 @@ let lmx = (import liminix { rogue = lmx.pkgs.rogue; img = lmx.outputs.vmroot; pkgs = import <nixpkgs> { overlays = [(import ../../overlay.nix)]; }; - inherit (pkgs.pkgsBuildBuild) mips-vm; + inherit (pkgs.pkgsBuildBuild) run-liminix-vm; in pkgs.runCommand "check" { nativeBuildInputs = with pkgs; [ expect - mips-vm + run-liminix-vm socat min-copy-closure rogue @@ -22,7 +22,7 @@ in pkgs.runCommand "check" { . ${../test-helpers.sh} mkdir vm -LAN=user,hostfwd=tcp::2022-:22 mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs +LAN=user,hostfwd=tcp::2022-:22 run-liminix-vm --background ./vm ${img}/vmlinux ${img}/rootfs expect ${./wait-until-ready.expect} export SSH_COMMAND="ssh -o StrictHostKeyChecking=no -p 2022 -i ${./id}" $SSH_COMMAND root@localhost echo ready diff --git a/tests/pppoe/test.nix b/tests/pppoe/test.nix @@ -7,7 +7,7 @@ let img = (import liminix { liminix-config = ./configuration.nix; }).outputs.default; pkgs = import <nixpkgs> { overlays = [(import ../../overlay.nix)]; }; - inherit (pkgs.pkgsBuildBuild) routeros mips-vm; + inherit (pkgs.pkgsBuildBuild) routeros run-liminix-vm; in pkgs.runCommand "check" { nativeBuildInputs = with pkgs; [ python3Packages.scapy @@ -15,7 +15,7 @@ in pkgs.runCommand "check" { jq socat routeros.routeros - mips-vm + run-liminix-vm ] ; } '' serverstatedir=$(mktemp -d -t routeros-XXXXXX) @@ -27,7 +27,7 @@ export MPLCONFIGDIR=$(mktemp -d -t routeros-XXXXXX) routeros $serverstatedir mkdir vm -mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs +run-liminix-vm --background ./vm ${img}/vmlinux ${img}/rootfs expect ${./getaddress.expect} set -o pipefail diff --git a/tests/wlan/test.nix b/tests/wlan/test.nix @@ -7,17 +7,17 @@ let img = (import liminix { liminix-config = ./configuration.nix; }).outputs.default; pkgs = import <nixpkgs> { overlays = [(import ../../overlay.nix)]; }; - inherit (pkgs.pkgsBuildBuild) mips-vm; + inherit (pkgs.pkgsBuildBuild) run-liminix-vm; in pkgs.runCommand "check" { nativeBuildInputs = with pkgs; [ expect - mips-vm + run-liminix-vm socat ] ; } '' . ${../test-helpers.sh} mkdir vm -mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs +run-liminix-vm --background ./vm ${img}/vmlinux ${img}/rootfs expect ${./wait-for-wlan.expect} |tee output && mv output $out ''