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 = {
flakeCheck = {
config = { config, lib, pkgs, ... }: { config = { config, lib, pkgs, ... }: {
networking.firewall.allowedTCPPorts = [ 80 ]; networking.firewall.allowedTCPPorts = [ 80 ];
services.mingetty.autologinUser = lib.mkDefault "root"; services.mingetty.autologinUser =
lib.mkDefault "root";
services.nginx.enable = true; services.nginx.enable = true;
services.openssh.permitRootLogin = lib.mkDefault "yes"; services.openssh.permitRootLogin =
lib.mkDefault "yes";
services.sshd.enable = true; services.sshd.enable = true;
users.users.root.password = "nixos"; users.users.root.password = "nixos";
virtualbox.memorySize = 128; 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 = {
iso = [
"${modulesPath}/installer/cd-dvd/iso-image.nix"
];
vdi = [
"${modulesPath}/virtualisation/virtualbox-image.nix" "${modulesPath}/virtualisation/virtualbox-image.nix"
] ++ (map (x: x.value) defs); {
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,24 +23,81 @@ let Vfs/inline =
, content = [ XML.text body ] , content = [ XML.text body ]
} }
let toVbox = let BootFormat = < ISO | VDI >
λ ( params
: { vdiFilename : Text let Params
, vdiPkg : Text : Type
, vdiUuid : Text = { bootFilename : Text
, bootPkg : Text
, bootUuid : Text
, bootFormat : BootFormat
, memorySize : Natural , memorySize : Natural
, vmName : Text , vmName : Text
} }
)
let toVbox =
λ(params : Params)
→ let vboxConfig = → let vboxConfig =
'' 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"> <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"> <Machine uuid="{37ab43a5-38d8-4491-93f5-5b0b077f5c32}" name="${params.vmName}" OSType="Linux26_64" snapshotFolder="Snapshots" lastStateChange="2018-01-23T18:40:00Z">
<MediaRegistry> <MediaRegistry>
<HardDisks> <HardDisks>${XML.render hardDisks}</HardDisks>
<HardDisk uuid="{${params.vdiUuid}}" location="${params.vdiFilename}" format="VDI" type="Normal"/> <DVDImages>${XML.render dvdImages}</DVDImages>
</HardDisks>
<DVDImages/>
</MediaRegistry> </MediaRegistry>
<Hardware> <Hardware>
<CPU count="2"> <CPU count="2">
@ -78,9 +135,7 @@ let toVbox =
</Hardware> </Hardware>
<StorageControllers> <StorageControllers>
<StorageController name="SATA" type="AHCI" PortCount="4" useHostIOCache="true" Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3"> <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"> ${XML.render attachedDevices}
<Image uuid="{${params.vdiUuid}}"/>
</AttachedDevice>
</StorageController> </StorageController>
</StorageControllers> </StorageControllers>
</Machine> </Machine>
@ -113,30 +168,47 @@ let toVbox =
, attributes = XML.emptyAttributes , attributes = XML.emptyAttributes
} }
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 in [ Vfs/inline "machine.vbox" vboxConfig
, XML.element , XML.element
{ name = "dir" { name = "dir"
, attributes = toMap { name = "dev" } , attributes = toMap { name = "dev" }
, content = [ tag "log", tag "rtc" ] , 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}"
}
}
]
}
] ]
# mutableVfs
} }
] ]
} }