2
0
Fork 0

nixos: do not test with a disk without a store

This commit is contained in:
Ehmry - 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 { bootDriveImage = import ./lib/make-bootable-image.nix {
inherit config pkgs espImage storeFsImage; inherit config pkgs espImage storeFsImage;
}; };
in bootDriveImage; in lib.mkIf (config.genode.boot.storeBackend != "tarball") bootDriveImage;
# virtualisation.useEFIBoot = config.genode.boot.storeBackend == "usb"; # 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 = { hardware.genode = {
ahci.enable = lib.mkEnableOption "AHCI (SATA) block driver"; 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; assertions = with builtins;
let let
@ -99,7 +100,7 @@ with lib;
hardware.genode.usb.storage.enable = config.genode.boot.storeBackend hardware.genode.usb.storage.enable = config.genode.boot.storeBackend
== "usb"; == "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: hardware.genode.platform.policies = lib.lists.imap0 (i: name:
builtins.toFile (name + ".platform-policy.dhall") '' builtins.toFile (name + ".platform-policy.dhall") ''
@ -119,7 +120,7 @@ with lib;
] ]
} }
'') (builtins.attrNames config.networking.interfaces) '') (builtins.attrNames config.networking.interfaces)
++ (lib.optional config.hardware.genode.ahci.enable ++ (lib.optional cfg.ahci.enable
(builtins.toFile ("ahci.platform-policy.dhall") '' (builtins.toFile ("ahci.platform-policy.dhall") ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -131,7 +132,7 @@ with lib;
{ name = "pci", attributes = toMap { class = "AHCI" } } { name = "pci", attributes = toMap { class = "AHCI" } }
] ]
} }
'')) ++ (lib.optional config.hardware.genode.framebuffer.enable '')) ++ (lib.optional cfg.framebuffer.enable
(builtins.toFile ("framebuffer.platform-policy.dhall") '' (builtins.toFile ("framebuffer.platform-policy.dhall") ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -143,7 +144,7 @@ with lib;
{ name = "pci", attributes = toMap { class = "VGA" } } { name = "pci", attributes = toMap { class = "VGA" } }
] ]
} }
'')) ++ (lib.optional config.hardware.genode.usb.enable '')) ++ (lib.optional cfg.usb.enable
(builtins.toFile ("usb.platform-policy.dhall") '' (builtins.toFile ("usb.platform-policy.dhall") ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -296,7 +297,7 @@ with lib;
in lib.filterAttrs (n: v: v != null) (nics // sockets); 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 ]; inputs = [ pkgs.genodePackages.ahci_drv ];
configFile = pkgs.writeText "ahci_drv.dhall" '' configFile = pkgs.writeText "ahci_drv.dhall" ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -359,9 +360,8 @@ with lib;
genode.core.children.platform_drv = { genode.core.children.platform_drv = {
inputs = [ pkgs.genodePackages.platform_drv ]; inputs = [ pkgs.genodePackages.platform_drv ];
configFile = let configFile =
policies = let policies = map (policy: ", ${policy}") cfg.platform.policies;
map (policy: ", ${policy}") config.hardware.genode.platform.policies;
in pkgs.writeText "platform_drv.dhall" '' in pkgs.writeText "platform_drv.dhall" ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -390,12 +390,11 @@ with lib;
''; '';
}; };
genode.core.children.usb_drv = let genode.core.children.usb_drv = let toYesNo = b: if b then "yes" else "no";
cfg = config.hardware.genode.usb; in mkIf cfg.usb.enable {
toYesNo = b: if b then "yes" else "no";
in mkIf cfg.enable {
inputs = [ pkgs.genodePackages.usb_drv ]; 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 Genode = env:DHALL_GENODE
let XML = Genode.Prelude.XML let XML = Genode.Prelude.XML
@ -419,10 +418,10 @@ with lib;
in Init.Config::{ in Init.Config::{
, attributes = toMap , attributes = toMap
{ ehci = "${toYesNo cfg.ehciSupport}" { ehci = "${toYesNo ehciSupport}"
, ohci = "${toYesNo cfg.ohciSupport}" , ohci = "${toYesNo ohciSupport}"
, uhci = "${toYesNo cfg.uhciSupport}" , uhci = "${toYesNo uhciSupport}"
, xhci = "${toYesNo cfg.xhciSupport}" , xhci = "${toYesNo xhciSupport}"
} }
, content = , content =
[ XML.element [ XML.element
@ -443,8 +442,7 @@ with lib;
''; '';
}; };
genode.core.children.usb_block_drv = genode.core.children.usb_block_drv = mkIf cfg.usb.storage.enable {
mkIf config.hardware.genode.usb.storage.enable {
inputs = [ pkgs.genodePackages.usb_block_drv ]; inputs = [ pkgs.genodePackages.usb_block_drv ];
configFile = builtins.toFile "usb_block_drv.dhall" '' configFile = builtins.toFile "usb_block_drv.dhall" ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -470,19 +468,18 @@ with lib;
''; '';
}; };
genode.core.children.fb_drv = genode.core.children.fb_drv = mkIf cfg.framebuffer.enable {
mkIf config.hardware.genode.framebuffer.enable {
inputs = with pkgs.genodePackages; inputs = with pkgs.genodePackages;
{ {
"boot" = [ boot_fb_drv ]; "boot" = [ boot_fb_drv ];
"vesa" = [ vesa_drv ]; "vesa" = [ vesa_drv ];
}.${config.hardware.genode.framebuffer.driver}; }.${cfg.framebuffer.driver};
configFile = let configFile = let
binary = with pkgs.genodePackages; binary = with pkgs.genodePackages;
{ {
"boot" = "boot_fb_drv"; "boot" = "boot_fb_drv";
"vesa" = "vesa_fb_drv"; "vesa" = "vesa_fb_drv";
}.${config.hardware.genode.framebuffer.driver}; }.${cfg.framebuffer.driver};
in builtins.toFile "fb_drv.dhall" '' in builtins.toFile "fb_drv.dhall" ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -504,7 +501,7 @@ with lib;
virtualisation.useBootLoader = config.genode.boot.storeBackend != "tarball"; 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.isi686 || pkgs.stdenv.isx86_64) "-usb"
++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64) ++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64)
"-device usb-ehci,id=usb0"); "-device usb-ehci,id=usb0");

View File

@ -23,7 +23,7 @@ let
# Shell script to start the VM. # Shell script to start the VM.
startVM = '' startVM = ''
#! ${pkgs.buildPackages.runtimeShell} #! ${pkgs.buildPackages.runtimeShell}
'' + lib.optionalString (config.virtualisation.diskImage != null) ''
NIX_DISK_IMAGE=$(readlink -f ''${NIX_DISK_IMAGE:-${config.virtualisation.diskImage}}) NIX_DISK_IMAGE=$(readlink -f ''${NIX_DISK_IMAGE:-${config.virtualisation.diskImage}})
if ! test -w "$NIX_DISK_IMAGE"; then if ! test -w "$NIX_DISK_IMAGE"; then
@ -36,6 +36,7 @@ let
${toString config.virtualisation.diskSize}M || exit 1 ${toString config.virtualisation.diskSize}M || exit 1
fi fi
'' + ''
# Create a directory for storing temporary data of the running VM. # Create a directory for storing temporary data of the running VM.
if [ -z "$TMPDIR" -o -z "$USE_TMPDIR" ]; then if [ -z "$TMPDIR" -o -z "$USE_TMPDIR" ]; then
TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir) TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)
@ -72,7 +73,8 @@ in {
}; };
virtualisation.diskImage = mkOption { virtualisation.diskImage = mkOption {
default = "./${config.system.name}.qcow2"; type = with types; nullOr path;
default = null;
description = '' description = ''
Path to the disk image containing the root filesystem. Path to the disk image containing the root filesystem.
The image will be created on startup if it does not The image will be created on startup if it does not