diff --git a/flake.nix b/flake.nix index bc32f67..0da83b8 100644 --- a/flake.nix +++ b/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; + }; }; }; + }) ]; }; diff --git a/nixos-modules/default.nix b/nixos-modules/default.nix index a90e366..02dbaa4 100644 --- a/nixos-modules/default.nix +++ b/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; }; diff --git a/nixos-modules/dhall/root.dhall b/nixos-modules/dhall/root.dhall index c2e5c5b..548b694 100644 --- a/nixos-modules/dhall/root.dhall +++ b/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 } diff --git a/nixos-modules/dhall/vbox-guest.dhall b/nixos-modules/dhall/vbox-guest.dhall index bd6bb31..3185369 100644 --- a/nixos-modules/dhall/vbox-guest.dhall +++ b/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 = - '' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '' + 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 '' + + + + ${XML.render hardDisks} + ${XML.render dvdImages} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${XML.render attachedDevices} + + + + + '' 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 } ] }