2
0
genodepkgs/nixos-modules/dhall/vbox-host.dhall

518 lines
23 KiB
Plaintext

-- SPDX-License-Identifier: CC0-1.0
let Genode = env:DHALL_GENODE
let Prelude = Genode.Prelude
let XML = Prelude.XML
let Init = Genode.Init
let Child = Init.Child
let Resources = Init.Resources
let ServiceRoute = Init.ServiceRoute
let label =
λ(label : Text)
→ { local = label, route = label } : Child.Attributes.Label
let Vfs/inline =
λ(name : Text)
→ λ(body : Text)
→ XML.element
{ name = "inline"
, attributes = XML.emptyAttributes
, content = [ XML.text body ]
}
let rootInit =
λ ( params
: { vdiFilename : Text
, vdiUuid : Text
, memorySize : Natural
, vmName : Text
}
)
→ let vboxConfig =
''
<?xml version="1.0"?>
<VirtualBox xmlns="http://www.virtualbox.org/" version="1.14-freebsd">
<Machine uuid="{37ab43a5-38d8-4491-93f5-5b0b077f5c32}" name="${params.vmName}" OSType="Linux26_64" snapshotFolder="Snapshots" lastStateChange="2018-01-23T18:40:00Z">
<MediaRegistry>
<HardDisks>
<HardDisk uuid="{${params.vdiUuid}}" location="${params.vdiFilename}" format="VDI" type="Normal"/>
</HardDisks>
<DVDImages/>
</MediaRegistry>
<Hardware>
<CPU count="1">
<PAE enabled="true"/>
<LongMode enabled="true"/>
<HardwareVirtExLargePages enabled="false"/>
</CPU>
<Memory RAMSize="${Prelude.Natural.show
params.memorySize}"/>
<HID Pointing="USBTablet"/>
<Display VRAMSize="20"/>
<RemoteDisplay enabled="false"/>
<BIOS>
<IOAPIC enabled="true"/>
</BIOS>
<USB/>
<Network/>
<UART>
<Port slot="0" enabled="false" IOBase="0x3f8" IRQ="4" hostMode="Disconnected"/>
<Port slot="1" enabled="false" IOBase="0x2f8" IRQ="3" hostMode="Disconnected"/>
</UART>
<LPT>
<Port slot="0" enabled="false" IOBase="0x378" IRQ="7"/>
<Port slot="1" enabled="false" IOBase="0x378" IRQ="7"/>
</LPT>
<AudioAdapter controller="HDA" driver="OSS" enabled="false"/>
<RTC localOrUTC="UTC"/>
<SharedFolders/>
</Hardware>
<StorageControllers>
<StorageController name="SATA" type="AHCI" PortCount="4" useHostIOCache="true" Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3">
<AttachedDevice type="HardDisk" port="0" device="0">
<Image uuid="{${params.vdiUuid}}"/>
</AttachedDevice>
</StorageController>
</StorageControllers>
</Machine>
</VirtualBox>
''
in Init::{
, routes = [ ServiceRoute.child "Timer" "timer" ]
, children = toMap
{ timer =
Child.flat
Child.Attributes::{
, binary = "timer_drv"
, provides = [ "Timer" ]
}
, rtc =
Child.flat
Child.Attributes::{
, binary = "rtc_drv"
, provides = [ "Rtc" ]
, routes =
[ ServiceRoute.parent "IO_PORT"
, ServiceRoute.parent "IO_MEM"
]
}
, acpi_drv =
Child.flat
Child.Attributes::{
, binary = "acpi_drv"
, priority = 1
, resources = Resources::{
, caps = 350
, ram = Genode.units.MiB 4
}
, romReports = [ label "acpi", label "smbios_table" ]
, routes = [ ServiceRoute.parent "IO_MEM" ]
}
, platform_drv =
Child.flat
Child.Attributes::{
, binary = "platform_drv"
, resources = Resources::{
, caps = 400
, ram = Genode.units.MiB 4
, constrainPhys = True
}
, reportRoms = [ label "acpi" ]
, romReports = [ label "pci" ]
, provides = [ "Acpi", "Platform" ]
, routes =
[ ServiceRoute.parent "IRQ"
, ServiceRoute.parent "IO_MEM"
, ServiceRoute.parent "IO_PORT"
, ServiceRoute.parentLabel
"ROM"
(Some "system")
(Some "system")
]
, config = Init.Config::{
, attributes = toMap { system = "yes" }
, content =
[ XML.text
''
<report pci="yes"/>
<policy label_suffix="ps2_drv">
<device name="PS2"/>
</policy>
<policy label_suffix="vesa_fb_drv">
<pci class="VGA"/>
</policy>
<policy label_suffix="ahci_drv">
<pci class="AHCI"/>
</policy>
<policy label_suffix="nvme_drv">
<pci class="NVME"/>
</policy>
<policy label_suffix="usb_drv">
<pci class="USB"/>
</policy>
<policy label_suffix="intel_fb_drv">
<pci class="VGA"/>
<pci bus="0" device="0" function="0"/>
<pci class="ISABRIDGE"/>
</policy>
<policy label_suffix="-&gt; wifi">
<pci class="WIFI"/>
</policy>
<policy label_suffix="-&gt; nic">
<pci class="ETHERNET"/>
</policy>
<policy label_suffix="-&gt; audio">
<pci class="AUDIO"/>
<pci class="HDAUDIO"/>
</policy>
<policy label="acpica"/>
''
]
}
}
, framebuffer =
Child.flat
Child.Attributes::{
, binary = "vesa_fb_drv"
, provides = [ "Framebuffer" ]
, resources = Init.Resources::{
, caps = 256
, ram = Genode.units.MiB 16
}
, routes =
[ ServiceRoute.parent "IO_MEM"
, ServiceRoute.parent "IO_PORT"
, ServiceRoute.childLabel
"Platform"
"platform_drv"
(None Text)
(Some "vesa_fb_drv")
]
}
, input_filter =
Child.flat
Child.Attributes::{
, binary = "input_filter"
, config =
let key =
λ(name : Text)
→ XML.leaf
{ name = "key"
, attributes = toMap { name = name }
}
let remap =
λ(name : Text)
→ λ(to : Text)
→ XML.leaf
{ name = "key"
, attributes = toMap
{ name = name, to = to }
}
in Init.Config::{
, content =
[ XML.leaf
{ name = "input"
, attributes = toMap { label = "ps2" }
}
, XML.element
{ name = "output"
, attributes = XML.emptyAttributes
, content =
[ XML.element
{ name = "chargen"
, attributes = XML.emptyAttributes
, content =
[ XML.element
{ name = "remap"
, attributes =
XML.emptyAttributes
, content =
[ remap
"KEY_LEFTMETA"
"KEY_SCREEN"
, XML.leaf
{ name = "input"
, attributes = toMap
{ name = "ps2" }
}
]
}
, XML.element
{ name = "mod1"
, attributes =
XML.emptyAttributes
, content =
[ key "KEY_LEFTSHIFT"
, key "KEY_RIGHTSHIFT"
]
}
, XML.element
{ name = "mod2"
, attributes =
XML.emptyAttributes
, content =
[ key "KEY_LEFTCTRL"
, key "KEY_RIGHTCTRL"
]
}
, XML.element
{ name = "mod3"
, attributes =
XML.emptyAttributes
, content =
[ key "KEY_RIGHTALT" ]
}
]
}
]
}
]
}
, provides = [ "Input" ]
, routes =
[ ServiceRoute.parentLabel
"ROM"
(Some "config")
(Some "config -> input_filter.config")
, ServiceRoute.childLabel
"Input"
"ps2_drv"
(Some "ps2")
(None Text)
]
}
, ps2_drv =
Child.flat
Child.Attributes::{
, binary = "ps2_drv"
, provides = [ "Input" ]
, routes =
[ ServiceRoute.childLabel
"Platform"
"platform_drv"
(None Text)
(Some "ps2_drv")
]
}
, nitpicker =
Child.flat
Child.Attributes::{
, binary = "nitpicker"
, config = Init.Config::{
, content =
[ XML.text
''
<domain name="pointer" layer="1" content="client" label="no" origin="pointer" />
<domain name="default" layer="2" content="client" label="yes" hover="always" focus="click"/>
<policy label_prefix="pointer" domain="pointer"/>
<default-policy domain="default"/>
''
]
}
, provides = [ "Nitpicker" ]
, routes =
[ ServiceRoute.child "Framebuffer" "framebuffer"
, ServiceRoute.child "Input" "input_filter"
]
}
, pointer =
Child.flat
Child.Attributes::{
, binary = "pointer"
, routes = [ ServiceRoute.child "Nitpicker" "nitpicker" ]
}
, block =
Child.flat
Child.Attributes::{
, binary = "ahci_drv"
, config = Init.Config::{
, content =
[ Genode.Prelude.XML.leaf
{ name = "default-policy"
, attributes = toMap
{ device = "0", writeable = "yes" }
}
]
}
, provides = [ "Block" ]
, resources = Init.Resources::{
, caps = 256
, ram = Genode.units.MiB 10
}
, routes =
[ ServiceRoute.childLabel
"Platform"
"platform_drv"
(None Text)
(Some "ahci_drv")
]
}
, block_partitions =
Child.flat
Child.Attributes::{
, binary = "part_block"
, config = Init.Config::{
, content =
Prelude.List.map
Natural
XML.Type
( λ(i : Natural)
→ XML.leaf
{ name = "policy"
, attributes =
let partition =
Prelude.Natural.show (i + 1)
in toMap
{ label_suffix = " ${partition}"
, partition = partition
, writeable = "yes"
}
}
)
(Prelude.Natural.enumerate 128)
# [ XML.leaf
{ name = "report"
, attributes = toMap { partitions = "yes" }
}
]
}
, resources = Resources::{
, caps = 256
, ram = Genode.units.MiB 8
}
, provides = [ "Block" ]
, routes =
[ ServiceRoute.child "Block" "block"
, ServiceRoute.child "Report" "block_router"
]
}
, block_router =
Child.flat
Child.Attributes::{
, binary = "block_router"
, config = Init.Config::{
, attributes = toMap { verbose = "yes" }
, content =
[ XML.element
{ name = "default-policy"
, attributes = XML.emptyAttributes
, content =
[ XML.leaf
{ name = "partition"
, attributes = toMap
{ type = ./partition-type
, writeable = "yes"
}
}
]
}
]
}
, resources = Resources::{
, caps = 256
, ram = Genode.units.MiB 8
}
, provides = [ "Block", "Report" ]
, routes =
[ ServiceRoute.child "Block" "block_partitions" ]
}
, file_system =
Child.flat
Child.Attributes::{
, binary = "vfs"
, config = Init.Config::{
, content =
[ XML.element
{ name = "vfs"
, attributes = XML.emptyAttributes
, content =
[ XML.leaf
{ name = "rump"
, attributes = toMap
{ fs = "ext2fs"
, writeable = "yes"
, ram = "8M"
}
}
]
}
, XML.leaf
{ name = "default-policy"
, attributes = toMap { root = "/" }
}
]
}
, provides = [ "File_system" ]
, resources = Init.Resources::{
, caps = 256
, ram = Genode.units.MiB 12
}
, routes = [ ServiceRoute.child "Block" "block_router" ]
}
, vbox =
Child.flat
Child.Attributes::{
, binary = "virtualbox5"
, config = Init.Config::{
, attributes = toMap
{ vbox_file = "nixos.vbox", vm_name = "nixos" }
, content =
[ XML.leaf
{ name = "libc"
, attributes = toMap
{ stdout = "/dev/log"
, stderr = "/dev/log"
, rtc = "/dev/rtc"
}
}
, XML.element
{ name = "vfs"
, attributes = XML.emptyAttributes
, content =
let tag =
λ(name : Text)
→ XML.leaf
{ name = name
, attributes = XML.emptyAttributes
}
in [ Vfs/inline "nixos.vbox" vboxConfig
, XML.element
{ name = "dir"
, attributes = toMap { name = "dev" }
, content = [ tag "log", tag "rtc" ]
}
, tag "fs"
]
}
]
}
, resources = Resources::{
, caps = 1024
, ram =
Genode.units.MiB 64
+ Genode.units.MiB params.memorySize
}
, routes =
[ ServiceRoute.parent "VM"
, ServiceRoute.child "Nitpicker" "nitpicker"
, ServiceRoute.child "File_system" "file_system"
, ServiceRoute.child "Rtc" "rtc"
]
}
}
}
in rootInit