liminix

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

default.nix (1832B)


      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 = [
     28       qemu
     29       ros-exec-script
     30     ];
     31     text = ''
     32       RUNTIME_DIRECTORY=$1
     33       test -d "$RUNTIME_DIRECTORY" || exit 1
     34       ${qemu}/bin/qemu-system-x86_64 \
     35         -M q35  \
     36         -m 1024 \
     37         -accel kvm \
     38         -display none \
     39         -daemonize \
     40         -pidfile "$RUNTIME_DIRECTORY/pid" \
     41         -serial "unix:$RUNTIME_DIRECTORY/console,server,nowait"\
     42         -monitor "unix:$RUNTIME_DIRECTORY/monitor,server,nowait" \
     43         -snapshot -drive file=${chr-image}/chr-7.7.img,format=raw,if=virtio \
     44         -chardev "socket,path=$RUNTIME_DIRECTORY/qmp,server=on,wait=off,id=qga0" \
     45         -device virtio-serial \
     46         -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
     47         -netdev socket,id=access,mcast=230.0.0.1:1234,localaddr=127.0.0.1 \
     48         -device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:11:02 \
     49         -netdev socket,id=world,mcast=230.0.0.1:1236,localaddr=127.0.0.1 \
     50         -device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=world,mac=ba:ad:1d:ea:11:01
     51       ros-exec-script "$RUNTIME_DIRECTORY/qmp" ${./routeros.config}
     52     '';
     53   };
     54 in
     55 {
     56   inherit routeros ros-exec-script;
     57 }