vmroot.nix (2613B)
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 54 then "${pkgs.stdenv.cc.targetPrefix}objcopy -O binary -R .comment -S ${kernel} $out" 55 else "cp ${kernel} $out"); 56 phram_address = lib.toHexString (config.hardware.ram.startAddress + 256 * 1024 * 1024); 57 in pkgs.runCommand "vmroot" {} '' 58 mkdir $out 59 cd $out 60 ln -s ${rootfs} rootfs 61 ln -s ${kernel} vmlinux 62 ln -s ${manifest} manifest 63 ln -s ${kernel.headers} build 64 echo ${cmdline} > commandline 65 cat > run.sh << EOF 66 #!${pkgs.runtimeShell} 67 ${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} 68 EOF 69 chmod +x run.sh 70 ''; 71 }; 72 }; 73 }