summary refs log tree commit diff
path: root/pkgs/os-specific/linux/spectrum/vm/app/default.nix
blob: 9ffed7e5b13592f0803bd295ec31557e574bf45f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ runCommand, writeScript, writeText, makeRootfs
, busybox, execline, linux_vm, jq, iproute
}:

runCommand "vm-app" rec {
  linux = linux_vm;

  login = writeScript "login" ''
    #! ${execline}/bin/execlineb -s0
    unexport !
    ${busybox}/bin/login -p -f root $@
  '';

  rootfs = makeRootfs {
    rcServices.ok-all = {
      type = writeText "ok-all-type" ''
        bundle
      '';
      contents = writeText "ok-all-contents" ''
        net
      '';
    };

    rcServices.net = {
      type = writeText "net-type" ''
        oneshot
      '';
      up = writeText "net-up" ''
        backtick -E LOCAL_IP {
          pipeline { ip -j link show eth0 }
          pipeline { jq -r ".[0].address | split(\":\") | .[4:6] | \"0x\" + .[]" }
          xargs printf "100.64.%d.%d"
        }

        if { ip address add ''${LOCAL_IP}/32 dev eth0 }
        if { ip link set eth0 up }
        if { ip route add 169.254.0.1 dev eth0 }
        ip route add default via 169.254.0.1 dev eth0
      '';
    };

    services.getty.run = writeScript "getty-run" ''
      #! ${execline}/bin/execlineb -P
      ${busybox}/bin/getty -i -n -l ${login} 38400 ttyS0
    '';

    path = [ iproute jq ];
  };

  inherit (rootfs) squashfs;
  vmID = 0;
} ''
  mkdir $out
  echo "$vmID" > $out/vm-id
  ln -s $linux/bzImage $out/kernel
  ln -s $squashfs $out/squashfs
''