liminix

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

default.nix (1769B)


      1 {
      2   stdenv
      3 , python3
      4 , qemu
      5 , fetchzip
      6 , writeShellApplication
      7 }:
      8 let
      9   chr-image = fetchzip {
     10     url = "https://download.mikrotik.com/routeros/7.7/chr-7.7.img.zip";
     11     hash = "sha256-utBQMUgNvl/UTG+GjnQShlGgVtHmRKtnhSTWW/JyeiY=";
     12     curlOpts = "-L";
     13   };
     14   ros-exec-script = stdenv.mkDerivation {
     15     name = "ros-exec-script";
     16     src = ./.;
     17     buildInputs = [python3];
     18     buildPhase = ":";
     19     installPhase = ''
     20       mkdir -p $out/bin
     21       cp ros-exec-script.py $out/bin/ros-exec-script
     22       chmod +x $out/bin/ros-exec-script
     23     '';
     24   };
     25   routeros = writeShellApplication {
     26     name = "routeros";
     27     runtimeInputs = [ qemu ros-exec-script ];
     28     text = ''
     29     RUNTIME_DIRECTORY=$1
     30     test -d "$RUNTIME_DIRECTORY" || exit 1
     31     ${qemu}/bin/qemu-system-x86_64 \
     32       -M q35  \
     33       -m 1024 \
     34       -accel kvm \
     35       -display none \
     36       -daemonize \
     37       -pidfile "$RUNTIME_DIRECTORY/pid" \
     38       -serial "unix:$RUNTIME_DIRECTORY/console,server,nowait"\
     39       -monitor "unix:$RUNTIME_DIRECTORY/monitor,server,nowait" \
     40       -snapshot -drive file=${chr-image}/chr-7.7.img,format=raw,if=virtio \
     41       -chardev "socket,path=$RUNTIME_DIRECTORY/qmp,server=on,wait=off,id=qga0" \
     42       -device virtio-serial \
     43       -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
     44       -netdev socket,id=access,mcast=230.0.0.1:1234,localaddr=127.0.0.1 \
     45       -device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:11:02 \
     46       -netdev socket,id=world,mcast=230.0.0.1:1236,localaddr=127.0.0.1 \
     47       -device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=world,mac=ba:ad:1d:ea:11:01
     48     ros-exec-script "$RUNTIME_DIRECTORY/qmp" ${./routeros.config}
     49     '';
     50   };
     51 in {
     52   inherit routeros ros-exec-script;
     53 }