Browse Source

nixos-module: ISO support

remotes/praha/master
Emery Hemingway 1 year ago
parent
commit
576c1ca41a
  1. 36
      flake.nix
  2. 106
      nixos-modules/default.nix
  3. 3
      nixos-modules/dhall/root.dhall
  4. 240
      nixos-modules/dhall/vbox-guest.dhall

36
flake.nix

@ -120,7 +120,7 @@
nixosModule = {
type = "app";
program =
"${self.checks.${localSystem}.nixosModule}/bin/run-nixos-vm";
"${self.checks.${localSystem}.nixosGuest}/bin/run-nixos-vm";
};
});
in apps' // { x86_64-linux = apps'.x86_64-linux-x86_64-genode; };
@ -196,17 +196,33 @@
];
};
};
genode.guests.flakeCheck = {
config = { config, lib, pkgs, ... }: {
networking.firewall.allowedTCPPorts = [ 80 ];
services.mingetty.autologinUser = lib.mkDefault "root";
services.nginx.enable = true;
services.openssh.permitRootLogin = lib.mkDefault "yes";
services.sshd.enable = true;
users.users.root.password = "nixos";
virtualbox.memorySize = 128;
genode.guests = {
flakeCheck = {
config = { config, lib, pkgs, ... }: {
networking.firewall.allowedTCPPorts = [ 80 ];
services.mingetty.autologinUser =
lib.mkDefault "root";
services.nginx.enable = true;
services.openssh.permitRootLogin =
lib.mkDefault "yes";
services.sshd.enable = true;
users.users.root.password = "nixos";
virtualbox.memorySize = 128;
};
};
azimuth = {
bootFormat = "vdi";
config = { config, lib, pkgs, ... }: {
services.cage = {
enable = true;
program = "${pkgs.azimuth}/bin/tor-azimuth";
};
users.users.demo.isNormalUser = true;
virtualbox.memorySize = 1024;
};
};
};
})
];
};

106
nixos-modules/default.nix

@ -9,17 +9,7 @@
modulesPath' = "${self.inputs.nixpkgs}/nixos/modules";
cfg = config.genode;
toVdi = config:
import "${modulesPath'}/../lib/make-disk-image.nix" {
inherit config lib pkgs;
diskSize = config.virtualbox.baseImageSize;
partitionTableType = "legacy";
fsType = "ext4";
name = "nixos-${pkgs.stdenv.hostPlatform.system}.vdi";
format = "vdi";
};
genodeConfig = config.genode;
console = lib'.runDhallCommand "vbox.dhall" { } ''
dhall > $out <<< '${
@ -37,17 +27,48 @@
'' + builtins.concatStringsSep "," (lib.mapAttrsToList (vmName: cfg:
let
inherit (cfg) config;
vdiRoot = toVdi config;
boot = {
iso = rec {
filename = "nixos.iso";
drv = pkgs.callPackage
"${modulesPath'}/../lib/make-iso9660-image.nix"
# call the ISO utility from our nixpkgs with the package set of the guest
{
isoName = filename;
inherit (config.isoImage) volumeID contents;
};
format = "< ISO | VDI >.ISO";
storeRoot = "${baseNameOf drv}/iso";
uuid = "81763434-9a51-49e8-9444-528a5a28c4bc";
};
vdi = rec {
filename = "nixos.vdi";
drv = import "${modulesPath'}/../lib/make-disk-image.nix" {
inherit config lib pkgs;
diskSize = config.virtualbox.baseImageSize;
partitionTableType = "legacy";
name = "nixos-${pkgs.stdenv.hostPlatform.system}.vdi";
format = "vdi";
};
format = "< ISO | VDI >.VDI";
storeRoot = baseNameOf drv;
uuid = ''
$(${pkgs.virtualbox}/bin/VBoxManage showmediuminfo "${boot.drv}/${boot.filename}" | awk '/^UUID:/ {print $2}')'';
};
}.${cfg.bootFormat};
in lib'.runDhallCommand "vbox.dhall" { } ''
vdiUuid=$(${pkgs.virtualbox}/bin/VBoxManage showmediuminfo "${vdiRoot}/nixos.vdi" | awk '/^UUID:/ {print $2}')
bootUuid=${boot.uuid}
dhall > $out << END
{ mapKey = "vbox-${vmName}"
, mapValue =
${./dhall/vbox-guest.dhall}
{ vdiFilename = "nixos.vdi"
, vdiPkg = "${baseNameOf vdiRoot}"
, vdiUuid = "$vdiUuid"
, memorySize = ${toString config.virtualbox.memorySize}
{ bootFilename = "${boot.filename}"
, bootFormat = ${boot.format}
, bootPkg = "${boot.storeRoot}"
, bootUuid = "$bootUuid"
, memorySize = ${toString cfg.memorySize}
, vmName = "${vmName}"
}
}
@ -58,16 +79,14 @@
'');
initConfig = let
fbDriverConfig = if cfg.fbDriver == "intel" then
./dhall/intel_fb_drv.dhall
else if cfg.fbDriver == "vesa" then
./dhall/vesa_fb_drv.dhall
else
throw ''No driver configuration found for "${cfg.fbDriver}"'';
fbDriverConfig = {
intel = ./dhall/intel_fb_drv.dhall;
vesa = ./dhall/vesa_fb_drv.dhall;
}.${genodeConfig.fbDriver};
in ''
${
./dhall/root.dhall
} { fbDriver = ${fbDriverConfig}, guests = toMap { console = ${console} } # ${guestChildren}, inputFilterChargens = ${cfg.inputFilter.extraChargen}, partitionType = ${
} { fbDriver = ${fbDriverConfig}, guests = toMap { console = ${console} } # ${guestChildren}, inputFilterChargens = ${genodeConfig.inputFilter.extraChargen}, partitionType = ${
./dhall/partition-type
}, wm = ${./dhall/wm.dhall}
}'';
@ -111,9 +130,9 @@
"vfs_ttf"
"window_layouter"
"wm"
] ++ lib.optional (cfg.guests != { }) "vbox5"
++ lib.optional (cfg.fbDriver == "vesa") "vesa_drv"
++ lib.optional (cfg.fbDriver == "intel") "intel_fb_drv")
] ++ lib.optional (genodeConfig.guests != { }) "vbox5"
++ lib.optional (genodeConfig.fbDriver == "vesa") "vesa_drv"
++ lib.optional (genodeConfig.fbDriver == "intel") "intel_fb_drv")
++ (with pkgs'; [ base-nova block_router ]);
extraBinaries = [
"ld.lib.so"
@ -129,7 +148,7 @@
"libvfs_pipe.so"
"libvfs_rump.so"
"libvfs_ttf.so"
] ++ lib.optionals (cfg.guests != { }) [
] ++ lib.optionals (genodeConfig.guests != { }) [
"libc_pipe.so"
"libiconv.so"
"libqemu-usb.so"
@ -162,6 +181,19 @@
({ config, options, name, ... }: {
options = {
bootFormat = mkOption {
default = "vdi";
type = types.enum [ "iso" "vdi" ];
description = "Set boot media format.";
};
memorySize = mkOption {
type = types.int;
default = 1536;
description = ''
The amount of RAM in MiB allocated to the VirtualBox guest.
'';
};
config = mkOption {
description = ''
A specification of the desired configuration of this
@ -172,9 +204,21 @@
merge = loc: defs:
(import "${modulesPath}/../lib/eval-config.nix" {
inherit (config'.nixpkgs) system;
modules = [
"${modulesPath}/virtualisation/virtualbox-image.nix"
] ++ (map (x: x.value) defs);
modules = {
iso = [
"${modulesPath}/installer/cd-dvd/iso-image.nix"
];
vdi = [
"${modulesPath}/virtualisation/virtualbox-image.nix"
{
virtualbox.memorySize =
genodeConfig.guests.${name}.memorySize;
}
];
}.${genodeConfig.guests.${name}.bootFormat}
++ [{ system.nixos.tags = [ name ]; }]
++ (map (x: x.value) defs);
prefix = [ "guests" name ];
}).config;
};

3
nixos-modules/dhall/root.dhall

@ -409,8 +409,7 @@ let rootInit =
Child.Attributes::{
, binary = "nit_fb"
, config = Init.Config::{
, attributes = toMap
{ xpos = "600", width = "600", height = "768" }
, attributes = toMap { initial_width = "600" }
}
, provides = [ "Framebuffer", "Input" ]
, resources = Resources::{ ram = Genode.units.MiB 8 }

240
nixos-modules/dhall/vbox-guest.dhall

@ -23,69 +23,124 @@ let Vfs/inline =
, content = [ XML.text body ]
}
let BootFormat = < ISO | VDI >
let Params
: Type
= { bootFilename : Text
, bootPkg : Text
, bootUuid : Text
, bootFormat : BootFormat
, memorySize : Natural
, vmName : Text
}
let toVbox =
λ ( params
: { vdiFilename : Text
, vdiPkg : Text
, vdiUuid : Text
, memorySize : Natural
, vmName : Text
}
)
λ(params : Params)
→ let vboxConfig =
''
<VirtualBox xmlns="http://www.virtualbox.org/" version="1.14-freebsd">
<Machine uuid="{37ab43a5-38d8-4491-93f5-5b0b077f5c32}" name="ubuntu_16_04_64" OSType="Ubuntu_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="2">
<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>
<Controllers/>
</USB>
<Network>
<Adapter slot="0" enabled="true" MACAddress="0800271D7901" cable="true" type="82540EM">
<BridgedInterface/>
</Adapter>
</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>
''
let hardDisks =
merge
{ ISO = XML.text ""
, VDI =
XML.leaf
{ name = "HardDisk"
, attributes = toMap
{ uuid = "{${params.bootUuid}}"
, location = "${params.bootFilename}"
, format = "VDI"
, type = "Normal"
}
}
}
params.bootFormat
let dvdImages =
merge
{ ISO =
XML.leaf
{ name = "Image"
, attributes = toMap
{ uuid = "{${params.bootUuid}}"
, location = "${params.bootFilename}"
}
}
, VDI = XML.text ""
}
params.bootFormat
let attachedDevices =
XML.element
{ name = "AttachedDevice"
, attributes =
merge
{ ISO = toMap
{ passthrough = "false"
, type = "DVD"
, port = "3"
, device = "0"
}
, VDI = toMap
{ type = "HardDisk", port = "0", device = "0" }
}
params.bootFormat
, content =
[ XML.leaf
{ name = "Image"
, attributes = toMap
{ uuid = "{${params.bootUuid}}" }
}
]
}
in ''
<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>${XML.render hardDisks}</HardDisks>
<DVDImages>${XML.render dvdImages}</DVDImages>
</MediaRegistry>
<Hardware>
<CPU count="2">
<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>
<Controllers/>
</USB>
<Network>
<Adapter slot="0" enabled="true" MACAddress="0800271D7901" cable="true" type="82540EM">
<BridgedInterface/>
</Adapter>
</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">
${XML.render attachedDevices}
</StorageController>
</StorageControllers>
</Machine>
</VirtualBox>
''
in Child.flat
Child.Attributes::{
@ -113,30 +168,47 @@ let toVbox =
, attributes = XML.emptyAttributes
}
in [ Vfs/inline "machine.vbox" vboxConfig
, XML.element
{ name = "dir"
, attributes = toMap { name = "dev" }
, content = [ tag "log", tag "rtc" ]
}
, XML.leaf
{ name = "fs"
, attributes = toMap { writeable = "yes" }
}
, XML.element
{ name = "import"
, attributes = toMap { overwrite = "no" }
, content =
[ XML.leaf
{ name = "fs"
, attributes = toMap
{ label = "nix/store"
, root = "${params.vdiPkg}"
let mutableVfs =
let fsNode =
[ XML.leaf
{ name = "ram"
, attributes = XML.emptyAttributes
}
, XML.leaf
{ name = "fs"
, attributes = toMap
{ label = "nix/store"
, root = "${params.bootPkg}"
}
}
]
in merge
{ ISO = fsNode
, VDI =
[ XML.leaf
{ name = "fs"
, attributes = toMap
{ writeable = "yes" }
}
}
]
}
]
, XML.element
{ name = "import"
, attributes = toMap
{ overwrite = "no" }
, content = fsNode
}
]
}
params.bootFormat
in [ Vfs/inline "machine.vbox" vboxConfig
, XML.element
{ name = "dir"
, attributes = toMap { name = "dev" }
, content = [ tag "log", tag "rtc" ]
}
]
# mutableVfs
}
]
}

Loading…
Cancel
Save