2
0
Fork 0

nixos-module: ISO support

This commit is contained in:
Ehmry - 2020-06-09 11:55:55 +05:30
parent 75c24ca27b
commit 576c1ca41a
4 changed files with 258 additions and 127 deletions

View File

@ -120,7 +120,7 @@
nixosModule = { nixosModule = {
type = "app"; type = "app";
program = 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; }; in apps' // { x86_64-linux = apps'.x86_64-linux-x86_64-genode; };
@ -196,17 +196,33 @@
]; ];
}; };
}; };
genode.guests.flakeCheck = { genode.guests = {
config = { config, lib, pkgs, ... }: { flakeCheck = {
networking.firewall.allowedTCPPorts = [ 80 ]; config = { config, lib, pkgs, ... }: {
services.mingetty.autologinUser = lib.mkDefault "root"; networking.firewall.allowedTCPPorts = [ 80 ];
services.nginx.enable = true; services.mingetty.autologinUser =
services.openssh.permitRootLogin = lib.mkDefault "yes"; lib.mkDefault "root";
services.sshd.enable = true; services.nginx.enable = true;
users.users.root.password = "nixos"; services.openssh.permitRootLogin =
virtualbox.memorySize = 128; 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;
};
}; };
}; };
}) })
]; ];
}; };

View File

@ -9,17 +9,7 @@
modulesPath' = "${self.inputs.nixpkgs}/nixos/modules"; modulesPath' = "${self.inputs.nixpkgs}/nixos/modules";
cfg = config.genode; genodeConfig = 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";
};
console = lib'.runDhallCommand "vbox.dhall" { } '' console = lib'.runDhallCommand "vbox.dhall" { } ''
dhall > $out <<< '${ dhall > $out <<< '${
@ -37,17 +27,48 @@
'' + builtins.concatStringsSep "," (lib.mapAttrsToList (vmName: cfg: '' + builtins.concatStringsSep "," (lib.mapAttrsToList (vmName: cfg:
let let
inherit (cfg) config; 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" { } '' in lib'.runDhallCommand "vbox.dhall" { } ''
vdiUuid=$(${pkgs.virtualbox}/bin/VBoxManage showmediuminfo "${vdiRoot}/nixos.vdi" | awk '/^UUID:/ {print $2}') bootUuid=${boot.uuid}
dhall > $out << END dhall > $out << END
{ mapKey = "vbox-${vmName}" { mapKey = "vbox-${vmName}"
, mapValue = , mapValue =
${./dhall/vbox-guest.dhall} ${./dhall/vbox-guest.dhall}
{ vdiFilename = "nixos.vdi" { bootFilename = "${boot.filename}"
, vdiPkg = "${baseNameOf vdiRoot}" , bootFormat = ${boot.format}
, vdiUuid = "$vdiUuid" , bootPkg = "${boot.storeRoot}"
, memorySize = ${toString config.virtualbox.memorySize} , bootUuid = "$bootUuid"
, memorySize = ${toString cfg.memorySize}
, vmName = "${vmName}" , vmName = "${vmName}"
} }
} }
@ -58,16 +79,14 @@
''); '');
initConfig = let initConfig = let
fbDriverConfig = if cfg.fbDriver == "intel" then fbDriverConfig = {
./dhall/intel_fb_drv.dhall intel = ./dhall/intel_fb_drv.dhall;
else if cfg.fbDriver == "vesa" then vesa = ./dhall/vesa_fb_drv.dhall;
./dhall/vesa_fb_drv.dhall }.${genodeConfig.fbDriver};
else
throw ''No driver configuration found for "${cfg.fbDriver}"'';
in '' in ''
${ ${
./dhall/root.dhall ./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 ./dhall/partition-type
}, wm = ${./dhall/wm.dhall} }, wm = ${./dhall/wm.dhall}
}''; }'';
@ -111,9 +130,9 @@
"vfs_ttf" "vfs_ttf"
"window_layouter" "window_layouter"
"wm" "wm"
] ++ lib.optional (cfg.guests != { }) "vbox5" ] ++ lib.optional (genodeConfig.guests != { }) "vbox5"
++ lib.optional (cfg.fbDriver == "vesa") "vesa_drv" ++ lib.optional (genodeConfig.fbDriver == "vesa") "vesa_drv"
++ lib.optional (cfg.fbDriver == "intel") "intel_fb_drv") ++ lib.optional (genodeConfig.fbDriver == "intel") "intel_fb_drv")
++ (with pkgs'; [ base-nova block_router ]); ++ (with pkgs'; [ base-nova block_router ]);
extraBinaries = [ extraBinaries = [
"ld.lib.so" "ld.lib.so"
@ -129,7 +148,7 @@
"libvfs_pipe.so" "libvfs_pipe.so"
"libvfs_rump.so" "libvfs_rump.so"
"libvfs_ttf.so" "libvfs_ttf.so"
] ++ lib.optionals (cfg.guests != { }) [ ] ++ lib.optionals (genodeConfig.guests != { }) [
"libc_pipe.so" "libc_pipe.so"
"libiconv.so" "libiconv.so"
"libqemu-usb.so" "libqemu-usb.so"
@ -162,6 +181,19 @@
({ config, options, name, ... }: { ({ config, options, name, ... }: {
options = { 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 { config = mkOption {
description = '' description = ''
A specification of the desired configuration of this A specification of the desired configuration of this
@ -172,9 +204,21 @@
merge = loc: defs: merge = loc: defs:
(import "${modulesPath}/../lib/eval-config.nix" { (import "${modulesPath}/../lib/eval-config.nix" {
inherit (config'.nixpkgs) system; inherit (config'.nixpkgs) system;
modules = [ modules = {
"${modulesPath}/virtualisation/virtualbox-image.nix" iso = [
] ++ (map (x: x.value) defs); "${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 ]; prefix = [ "guests" name ];
}).config; }).config;
}; };

View File

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

View File

@ -23,69 +23,124 @@ let Vfs/inline =
, content = [ XML.text body ] , 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 = let toVbox =
λ ( params λ(params : Params)
: { vdiFilename : Text
, vdiPkg : Text
, vdiUuid : Text
, memorySize : Natural
, vmName : Text
}
)
→ let vboxConfig = → let vboxConfig =
'' let hardDisks =
<VirtualBox xmlns="http://www.virtualbox.org/" version="1.14-freebsd"> merge
<Machine uuid="{37ab43a5-38d8-4491-93f5-5b0b077f5c32}" name="ubuntu_16_04_64" OSType="Ubuntu_64" snapshotFolder="Snapshots" lastStateChange="2018-01-23T18:40:00Z"> { ISO = XML.text ""
<MediaRegistry> , VDI =
<HardDisks> XML.leaf
<HardDisk uuid="{${params.vdiUuid}}" location="${params.vdiFilename}" format="VDI" type="Normal"/> { name = "HardDisk"
</HardDisks> , attributes = toMap
<DVDImages/> { uuid = "{${params.bootUuid}}"
</MediaRegistry> , location = "${params.bootFilename}"
<Hardware> , format = "VDI"
<CPU count="2"> , type = "Normal"
<PAE enabled="true"/> }
<LongMode enabled="true"/> }
<HardwareVirtExLargePages enabled="false"/> }
</CPU> params.bootFormat
<Memory RAMSize="${Prelude.Natural.show
params.memorySize}"/> let dvdImages =
<HID Pointing="USBTablet"/> merge
<Display VRAMSize="20"/> { ISO =
<RemoteDisplay enabled="false"/> XML.leaf
<BIOS> { name = "Image"
<IOAPIC enabled="true"/> , attributes = toMap
</BIOS> { uuid = "{${params.bootUuid}}"
<USB> , location = "${params.bootFilename}"
<Controllers/> }
</USB> }
<Network> , VDI = XML.text ""
<Adapter slot="0" enabled="true" MACAddress="0800271D7901" cable="true" type="82540EM"> }
<BridgedInterface/> params.bootFormat
</Adapter>
</Network> let attachedDevices =
<UART> XML.element
<Port slot="0" enabled="false" IOBase="0x3f8" IRQ="4" hostMode="Disconnected"/> { name = "AttachedDevice"
<Port slot="1" enabled="false" IOBase="0x2f8" IRQ="3" hostMode="Disconnected"/> , attributes =
</UART> merge
<LPT> { ISO = toMap
<Port slot="0" enabled="false" IOBase="0x378" IRQ="7"/> { passthrough = "false"
<Port slot="1" enabled="false" IOBase="0x378" IRQ="7"/> , type = "DVD"
</LPT> , port = "3"
<AudioAdapter controller="HDA" driver="OSS" enabled="false"/> , device = "0"
<RTC localOrUTC="UTC"/> }
<SharedFolders/> , VDI = toMap
</Hardware> { type = "HardDisk", port = "0", device = "0" }
<StorageControllers> }
<StorageController name="SATA" type="AHCI" PortCount="4" useHostIOCache="true" Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3"> params.bootFormat
<AttachedDevice type="HardDisk" port="0" device="0"> , content =
<Image uuid="{${params.vdiUuid}}"/> [ XML.leaf
</AttachedDevice> { name = "Image"
</StorageController> , attributes = toMap
</StorageControllers> { uuid = "{${params.bootUuid}}" }
</Machine> }
</VirtualBox> ]
'' }
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 in Child.flat
Child.Attributes::{ Child.Attributes::{
@ -113,30 +168,47 @@ let toVbox =
, attributes = XML.emptyAttributes , attributes = XML.emptyAttributes
} }
in [ Vfs/inline "machine.vbox" vboxConfig let mutableVfs =
, XML.element let fsNode =
{ name = "dir" [ XML.leaf
, attributes = toMap { name = "dev" } { name = "ram"
, content = [ tag "log", tag "rtc" ] , attributes = XML.emptyAttributes
} }
, XML.leaf , XML.leaf
{ name = "fs" { name = "fs"
, attributes = toMap { writeable = "yes" } , attributes = toMap
} { label = "nix/store"
, XML.element , root = "${params.bootPkg}"
{ name = "import" }
, attributes = toMap { overwrite = "no" } }
, content = ]
[ XML.leaf
{ name = "fs" in merge
, attributes = toMap { ISO = fsNode
{ label = "nix/store" , VDI =
, root = "${params.vdiPkg}" [ 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
} }
] ]
} }