{ config, lib, pkgs, modulesPath, ... }: with lib; let cfg = config.genode.vbox; in { options.genode.vbox.guests = mkOption { type = types.attrsOf (types.submodule ({ 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. ''; }; routeToNics = lib.mkOption { type = with types; listOf str; default = [ "eth0" ]; example = [ "eth0" "br0" ]; description = '' Grant access to these Nic interfaces. ''; }; config = mkOption { description = '' A specification of the desired configuration of this guest VM, as a NixOS module. ''; default = { }; type = mkOptionType { name = "Toplevel NixOS config"; merge = loc: defs: (import "${modulesPath}/../lib/eval-config.nix" { inherit (config.nixpkgs) system; modules = { iso = [ "${modulesPath}/installer/cd-dvd/iso-image.nix" ]; vdi = [ "${modulesPath}/virtualisation/virtualbox-image.nix" { virtualbox.memorySize = cfg.guests.${name}.memorySize; } ]; }.${genodeConfig.guests.${name}.bootFormat} ++ [{ system.nixos.tags = [ name ]; }] ++ (map (x: x.value) defs); prefix = [ "guests" name ]; }).config; }; }; }; })); }; config = { genode.init.children = mapAttrs' (name: cfg: let 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 { inherit (cfg) routeToNics; inputs = with pkgs.genodePackages; [ libiconv vbox5 vfs_pipe ]; coreROMs = [ "platform_info" ]; configFile = pkgs.writeText "${name}.vbox.dhall" '' ${./vbox-guest.dhall} { bootFilename = "${boot.filename}" , bootFormat = "${boot.format}" , bootPkg = "${boot.storeRoot}" , bootUuid = ${boot.uuid} , memorySize = ${toString cfg.memorySize} , nicLabels = ${builtins.toJSON cfg.routeToNics} : List Text , vmName = "${vmName}" } ''; }) config.genode.vbox.guests; }; }