2
0
Fork 0

nixos: do not test with a disk without a store

This commit is contained in:
Emery Hemingway 2020-12-31 11:05:13 +01:00
parent 26d4f6b62e
commit 983c63aa0b
3 changed files with 138 additions and 139 deletions

View File

@ -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";

View File

@ -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");

View File

@ -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