vmroot.nix (2653B)
1 { 2 config, 3 pkgs, 4 lib, 5 ... 6 }: 7 let 8 inherit (lib) mkOption types concatStringsSep; 9 in 10 { 11 options = { 12 system.outputs = { 13 vmroot = mkOption { 14 type = types.package; 15 description = '' 16 vmroot 17 ****** 18 19 This target is for use with the qemu, qemu-aarch64, qemu-armv7l 20 devices. It generates an executable :file:`run.sh` which 21 invokes QEMU. It connects the Liminix 22 serial console and the `QEMU monitor <https://www.qemu.org/docs/master/system/monitor.html>`_ 23 to stdin/stdout. Use ^P (not ^A) to switch between monitor and 24 stdio. 25 26 If you call :command:`run.sh` with ``--background 27 /path/to/some/directory`` as the first parameter, it will 28 fork into the background and open Unix sockets in that 29 directory for console and monitor. Use :command:`nix-shell 30 --run connect-vm` to connect to either of these sockets, and 31 ^O to disconnect. 32 33 Liminix VMs are networked using QEMU socket networking. The 34 default behaviour is to connect 35 36 * multicast 230.0.0.1:1234 ("access") to eth0 37 * multicast 230.0.0.1:1235 ("lan") to eth1 38 39 Refer to :ref:`border-network-gateway` for details of how to 40 start an emulated upstream on the "access" network that 41 your Liminix device can talk to. 42 ''; 43 }; 44 }; 45 }; 46 config = { 47 system.outputs = rec { 48 vmroot = 49 let 50 inherit (config.system.outputs) rootfs kernel manifest; 51 cmdline = builtins.toJSON (concatStringsSep " " config.boot.commandLine); 52 makeBootableImage = pkgs.runCommandCC "objcopy" { } ( 53 if pkgs.stdenv.hostPlatform.isAarch then 54 "${pkgs.stdenv.cc.targetPrefix}objcopy -O binary -R .comment -S ${kernel} $out" 55 else 56 "cp ${kernel} $out" 57 ); 58 phram_address = lib.toHexString (config.hardware.ram.startAddress + 256 * 1024 * 1024); 59 in 60 pkgs.runCommand "vmroot" { } '' 61 mkdir $out 62 cd $out 63 ln -s ${rootfs} rootfs 64 ln -s ${kernel} vmlinux 65 ln -s ${manifest} manifest 66 ln -s ${kernel.headers} build 67 echo ${cmdline} > commandline 68 cat > run.sh << EOF 69 #!${pkgs.runtimeShell} 70 ${pkgs.pkgsBuildBuild.run-liminix-vm}/bin/run-liminix-vm --command-line ${cmdline} --arch ${pkgs.stdenv.hostPlatform.qemuArch} --phram-address 0x${phram_address} \$* ${makeBootableImage} ${config.system.outputs.rootfs} 71 EOF 72 chmod +x run.sh 73 ''; 74 }; 75 }; 76 }