diff --git a/nixos-modules/genode-core.nix b/nixos-modules/genode-core.nix index c3bae3b..84ff944 100644 --- a/nixos-modules/genode-core.nix +++ b/nixos-modules/genode-core.nix @@ -394,7 +394,7 @@ in { bootDriveImage = import ./lib/make-bootable-image.nix { inherit config pkgs espImage storeFsImage; }; - in bootDriveImage; + in lib.mkIf (config.genode.boot.storeBackend != "tarball") bootDriveImage; # virtualisation.useEFIBoot = config.genode.boot.storeBackend == "usb"; diff --git a/nixos-modules/hardware.nix b/nixos-modules/hardware.nix index 5e630d8..8755fd0 100644 --- a/nixos-modules/hardware.nix +++ b/nixos-modules/hardware.nix @@ -25,15 +25,6 @@ with lib; })); }; - hardware.genode.platform.policies = lib.mkOption { - type = with types; listOf path; - default = [ ]; - description = '' - List of policies to append to the Genode platform driver. - Type is Init.Config.Policy.Type. - ''; - }; - hardware.genode = { ahci.enable = lib.mkEnableOption "AHCI (SATA) block driver"; @@ -58,11 +49,21 @@ with lib; }; + platform.policies = lib.mkOption { + type = with types; listOf path; + default = [ ]; + description = '' + List of policies to append to the Genode platform driver. + Type is Init.Config.Policy.Type. + ''; + }; + }; }; - config = { + config = let cfg = config.hardware.genode; + in { assertions = with builtins; let @@ -99,7 +100,7 @@ with lib; hardware.genode.usb.storage.enable = config.genode.boot.storeBackend == "usb"; - hardware.genode.usb.enable = config.hardware.genode.usb.storage.enable; + hardware.genode.usb.enable = cfg.usb.storage.enable; hardware.genode.platform.policies = lib.lists.imap0 (i: name: builtins.toFile (name + ".platform-policy.dhall") '' @@ -119,7 +120,7 @@ with lib; ] } '') (builtins.attrNames config.networking.interfaces) - ++ (lib.optional config.hardware.genode.ahci.enable + ++ (lib.optional cfg.ahci.enable (builtins.toFile ("ahci.platform-policy.dhall") '' let Genode = env:DHALL_GENODE @@ -131,7 +132,7 @@ with lib; { name = "pci", attributes = toMap { class = "AHCI" } } ] } - '')) ++ (lib.optional config.hardware.genode.framebuffer.enable + '')) ++ (lib.optional cfg.framebuffer.enable (builtins.toFile ("framebuffer.platform-policy.dhall") '' let Genode = env:DHALL_GENODE @@ -143,7 +144,7 @@ with lib; { name = "pci", attributes = toMap { class = "VGA" } } ] } - '')) ++ (lib.optional config.hardware.genode.usb.enable + '')) ++ (lib.optional cfg.usb.enable (builtins.toFile ("usb.platform-policy.dhall") '' let Genode = env:DHALL_GENODE @@ -296,7 +297,7 @@ with lib; in lib.filterAttrs (n: v: v != null) (nics // sockets); - genode.core.children.ahci_drv = { + genode.core.children.ahci_drv = lib.mkIf cfg.ahci.enable { inputs = [ pkgs.genodePackages.ahci_drv ]; configFile = pkgs.writeText "ahci_drv.dhall" '' let Genode = env:DHALL_GENODE @@ -359,43 +360,91 @@ with lib; genode.core.children.platform_drv = { inputs = [ pkgs.genodePackages.platform_drv ]; - configFile = let - policies = - map (policy: ", ${policy}") config.hardware.genode.platform.policies; - in pkgs.writeText "platform_drv.dhall" '' - let Genode = env:DHALL_GENODE + configFile = + let policies = map (policy: ", ${policy}") cfg.platform.policies; + in pkgs.writeText "platform_drv.dhall" '' + let Genode = env:DHALL_GENODE - let Init = Genode.Init + let Init = Genode.Init - in Init.Child.flat - Init.Child.Attributes::{ - , binary = "platform_drv" - , resources = Init.Resources::{ - , caps = 800 - , ram = Genode.units.MiB 4 - , constrainPhys = True + in Init.Child.flat + Init.Child.Attributes::{ + , binary = "platform_drv" + , resources = Init.Resources::{ + , caps = 800 + , ram = Genode.units.MiB 4 + , constrainPhys = True + } + , reportRoms = let label = "acpi" in [ { local = label, route = label } ] + , routes = + [ Init.ServiceRoute.parent "IRQ" + , Init.ServiceRoute.parent "IO_MEM" + , Init.ServiceRoute.parent "IO_PORT" + ] + , config = Init.Config::{ + , policies = [ ${ + toString policies + } ] : List Init.Config.Policy.Type + } } - , reportRoms = let label = "acpi" in [ { local = label, route = label } ] - , routes = - [ Init.ServiceRoute.parent "IRQ" - , Init.ServiceRoute.parent "IO_MEM" - , Init.ServiceRoute.parent "IO_PORT" - ] - , config = Init.Config::{ - , policies = [ ${ - toString policies - } ] : List Init.Config.Policy.Type - } - } - ''; + ''; }; - genode.core.children.usb_drv = let - cfg = config.hardware.genode.usb; - toYesNo = b: if b then "yes" else "no"; - in mkIf cfg.enable { + genode.core.children.usb_drv = let toYesNo = b: if b then "yes" else "no"; + in mkIf cfg.usb.enable { inputs = [ pkgs.genodePackages.usb_drv ]; - configFile = builtins.toFile "usb_drv.dhall" '' + configFile = with cfg.usb; + builtins.toFile "usb_drv.dhall" '' + let Genode = env:DHALL_GENODE + + let XML = Genode.Prelude.XML + + let Init = Genode.Init + + in Init.Child.flat + Init.Child.Attributes::{ + , binary = "usb_drv" + , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 } + , romReports = let local = "devices" in [ { local, route = local } ] + , routes = [ Init.ServiceRoute.parent "IO_MEM" ] + , config = + let storagePolicy = + Init.Config.Policy::{ + , service = "Usb" + , label = Init.LabelSelector.prefix "usb_block_drv" + , attributes = toMap { class = "8" } + , diag = Some True + } + + in Init.Config::{ + , attributes = toMap + { ehci = "${toYesNo ehciSupport}" + , ohci = "${toYesNo ohciSupport}" + , uhci = "${toYesNo uhciSupport}" + , xhci = "${toYesNo xhciSupport}" + } + , content = + [ XML.element + { name = "raw" + , attributes = XML.emptyAttributes + , content = + [ XML.leaf + { name = "report" + , attributes = toMap { devices = "yes" } + } + , Init.Config.Policy.toXML storagePolicy + ] + } + ] + , policies = [ storagePolicy ] : List Init.Config.Policy.Type + } + } + ''; + }; + + genode.core.children.usb_block_drv = mkIf cfg.usb.storage.enable { + inputs = [ pkgs.genodePackages.usb_block_drv ]; + configFile = builtins.toFile "usb_block_drv.dhall" '' let Genode = env:DHALL_GENODE let XML = Genode.Prelude.XML @@ -404,107 +453,55 @@ with lib; in Init.Child.flat Init.Child.Attributes::{ - , binary = "usb_drv" - , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 } - , romReports = let local = "devices" in [ { local, route = local } ] - , routes = [ Init.ServiceRoute.parent "IO_MEM" ] - , config = - let storagePolicy = - Init.Config.Policy::{ - , service = "Usb" - , label = Init.LabelSelector.prefix "usb_block_drv" - , attributes = toMap { class = "8" } - , diag = Some True - } - - in Init.Config::{ - , attributes = toMap - { ehci = "${toYesNo cfg.ehciSupport}" - , ohci = "${toYesNo cfg.ohciSupport}" - , uhci = "${toYesNo cfg.uhciSupport}" - , xhci = "${toYesNo cfg.xhciSupport}" - } - , content = - [ XML.element - { name = "raw" - , attributes = XML.emptyAttributes - , content = - [ XML.leaf - { name = "report" - , attributes = toMap { devices = "yes" } - } - , Init.Config.Policy.toXML storagePolicy - ] - } - ] - , policies = [ storagePolicy ] : List Init.Config.Policy.Type - } + , binary = "usb_block_drv" + , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 4 } + , config = Init.Config::{ + , attributes = toMap { writeable = "yes" } + , policies = + [ Init.Config.Policy::{ + , service = "Block" + , label = Init.LabelSelector.prefix "part_block" + } + ] + } } ''; }; - genode.core.children.usb_block_drv = - mkIf config.hardware.genode.usb.storage.enable { - inputs = [ pkgs.genodePackages.usb_block_drv ]; - configFile = builtins.toFile "usb_block_drv.dhall" '' - let Genode = env:DHALL_GENODE - - let XML = Genode.Prelude.XML - - let Init = Genode.Init - - in Init.Child.flat - Init.Child.Attributes::{ - , binary = "usb_block_drv" - , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 4 } - , config = Init.Config::{ - , attributes = toMap { writeable = "yes" } - , policies = - [ Init.Config.Policy::{ - , service = "Block" - , label = Init.LabelSelector.prefix "part_block" - } - ] - } - } - ''; - }; - - genode.core.children.fb_drv = - mkIf config.hardware.genode.framebuffer.enable { - inputs = with pkgs.genodePackages; + genode.core.children.fb_drv = mkIf cfg.framebuffer.enable { + inputs = with pkgs.genodePackages; + { + "boot" = [ boot_fb_drv ]; + "vesa" = [ vesa_drv ]; + }.${cfg.framebuffer.driver}; + configFile = let + binary = with pkgs.genodePackages; { - "boot" = [ boot_fb_drv ]; - "vesa" = [ vesa_drv ]; - }.${config.hardware.genode.framebuffer.driver}; - configFile = let - binary = with pkgs.genodePackages; - { - "boot" = "boot_fb_drv"; - "vesa" = "vesa_fb_drv"; - }.${config.hardware.genode.framebuffer.driver}; - in builtins.toFile "fb_drv.dhall" '' - let Genode = env:DHALL_GENODE + "boot" = "boot_fb_drv"; + "vesa" = "vesa_fb_drv"; + }.${cfg.framebuffer.driver}; + in builtins.toFile "fb_drv.dhall" '' + let Genode = env:DHALL_GENODE - let XML = Genode.Prelude.XML + let XML = Genode.Prelude.XML - let Init = Genode.Init + let Init = Genode.Init - in Init.Child.flat - Init.Child.Attributes::{ - , binary = "${binary}" - , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 32 } - , routes = - [ Init.ServiceRoute.parent "IO_MEM" - , Init.ServiceRoute.parent "IO_PORT" - ] - } - ''; - }; + in Init.Child.flat + Init.Child.Attributes::{ + , binary = "${binary}" + , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 32 } + , routes = + [ Init.ServiceRoute.parent "IO_MEM" + , Init.ServiceRoute.parent "IO_PORT" + ] + } + ''; + }; virtualisation.useBootLoader = config.genode.boot.storeBackend != "tarball"; - virtualisation.qemu.options = lib.optional config.hardware.genode.usb.enable + virtualisation.qemu.options = lib.optional cfg.usb.enable (lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "-usb" ++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64) "-device usb-ehci,id=usb0"); diff --git a/nixos-modules/qemu-vm.nix b/nixos-modules/qemu-vm.nix index e61421e..e4f5bcc 100644 --- a/nixos-modules/qemu-vm.nix +++ b/nixos-modules/qemu-vm.nix @@ -23,7 +23,7 @@ let # Shell script to start the VM. startVM = '' #! ${pkgs.buildPackages.runtimeShell} - + '' + lib.optionalString (config.virtualisation.diskImage != null) '' NIX_DISK_IMAGE=$(readlink -f ''${NIX_DISK_IMAGE:-${config.virtualisation.diskImage}}) if ! test -w "$NIX_DISK_IMAGE"; then @@ -36,6 +36,7 @@ let ${toString config.virtualisation.diskSize}M || exit 1 fi + '' + '' # Create a directory for storing temporary data of the running VM. if [ -z "$TMPDIR" -o -z "$USE_TMPDIR" ]; then TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir) @@ -72,7 +73,8 @@ in { }; virtualisation.diskImage = mkOption { - default = "./${config.system.name}.qcow2"; + type = with types; nullOr path; + default = null; description = '' Path to the disk image containing the root filesystem. The image will be created on startup if it does not