2
0
Förgrening 0
genodepkgs/nixos-modules/default.nix

285 rader
9.1 KiB
Nix

{ self }: {
genodeHost = { config, lib, pkgs, modulesPath, ... }:
let
apps' = self.apps.x86_64-linux-x86_64-genode;
config' = config;
lib' = self.lib.x86_64-linux-x86_64-genode;
pkgs' = self.packages.x86_64-linux-x86_64-genode;
legacyPackages' = self.legacyPackages.x86_64-linux-x86_64-genode;
modulesPath' = "${self.inputs.nixpkgs}/nixos/modules";
genodeConfig = config.genode;
console = lib'.runDhallCommand "vbox.dhall" { } ''
dhall > $out <<< '${
./dhall/console.dhall
} { bash = "${legacyPackages'.bash}", coreutils = "${legacyPackages'.coreutils}", path = "${
lib.makeSearchPathOutput "bin" "bin"
(with legacyPackages'; [ bash coreutils ])
}" }'
'';
guestChildren = lib'.runDhallCommand "vbox.dhall" { } (''
dhall > $out << END
let Genode = env:DHALL_GENODE
in [
'' + builtins.concatStringsSep "," (lib.mapAttrsToList (vmName: cfg:
let
inherit (cfg) 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" { } ''
bootUuid=${boot.uuid}
dhall > $out << END
{ mapKey = "vbox-${vmName}"
, mapValue =
${./dhall/vbox-guest.dhall}
{ bootFilename = "${boot.filename}"
, bootFormat = ${boot.format}
, bootPkg = "${boot.storeRoot}"
, bootUuid = "$bootUuid"
, memorySize = ${toString cfg.memorySize}
, vmName = "${vmName}"
}
}
END
'') config.genode.guests) + ''
] : Genode.Init.Children.Type
END
'');
initConfig = let
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 = ${genodeConfig.inputFilter.extraChargen}, partitionType = ${
./dhall/partition-type
}, wm = ${./dhall/wm.dhall}, graphical-log = ${
./dhall/graphical-log.dhall
}, fs-log = ${
./dhall/fs-log.dhall
}, systemLabel = "${config.system.nixos.label}" }'';
buildBootDescription = self.legacyPackages.x86_64-linux.callPackage
./buildBootDescription.nix { lib = lib'; };
bootDescription = buildBootDescription {
inherit initConfig;
imageInputs = [ legacyPackages'.bash ] ++ map pkgs'.genodeSources.depot
([
"acpi_drv"
"ahci_drv"
"cached_fs_rom"
"chroot"
"decorator"
"event_filter"
"fs_log"
"gui_fb"
"init"
"ipxe_nic_drv"
"libc"
"libiconv"
"log_core"
"nic_router"
"nitpicker"
"part_block"
"platform_drv"
"posix"
"ps2_drv"
"report_rom"
"rom_to_file"
"rtc_drv"
"rump"
"stdcxx"
"terminal"
"terminal_log"
"usb_drv"
"vfs"
"vfs_audit"
"vfs_import"
"vfs_pipe"
"vfs_ttf"
"window_layouter"
"wm"
] ++ 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"
"libc.so"
"libm.so"
"libposix.so"
"librump.so"
"librump_fs.so"
"libstdcxx.so"
"libvfs.so"
"libvfs_audit.so"
"libvfs_import.so"
"libvfs_pipe.so"
"libvfs_rump.so"
"libvfs_ttf.so"
] ++ lib.optionals (genodeConfig.guests != { }) [
"libc_pipe.so"
"libiconv.so"
"libqemu-usb.so"
];
extraRoms = {
"Inconsolata.ttf" =
"${pkgs.inconsolata}/share/fonts/truetype/inconsolata/Inconsolata-Regular.ttf";
"focus" = builtins.toFile "nitpicker-is-too-complicated.xml" ''
<focus label="focus"/>
'';
};
};
firmware = lib'.novaImage "stage0" { gzip = true; } bootDescription;
in {
options.genode = with lib; {
fbDriver = mkOption {
default = "vesa";
type = types.enum [ "intel" "vesa" ];
description = ''
Set framebuffer driver.
'';
};
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.
'';
};
config = mkOption {
description = ''
A specification of the desired configuration of this
guest VM, as a NixOS module.
'';
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 =
genodeConfig.guests.${name}.memorySize;
}
];
}.${genodeConfig.guests.${name}.bootFormat}
++ [{ system.nixos.tags = [ name ]; }]
++ (map (x: x.value) defs);
prefix = [ "guests" name ];
}).config;
};
};
};
}));
default = { };
};
inputFilter = {
extraChargen = mkOption {
description =
"Dhall expression of the type <code>List Prelude.XML.Type</code>";
type = types.str;
default = "${./dhall/qwerty.chargen.dhall}";
};
};
};
config = {
system.build.genode = {
inherit firmware console;
config = lib'.runDhallCommand "config.dhall" { }
''dhall > $out <<< "${initConfig}"'';
xml = lib'.runDhallCommand "config.xml" { }
''${apps'.render-init.program} <<< "${initConfig}" > $out'';
};
boot.loader.grub = {
extraEntries = ''
menuentry Genode on NOVA {
insmod multiboot2
insmod gzio
multiboot2 /bender
module2 /hypervisor hypervisor iommu novpid serial logmem
module2 /image.elf.gz image.elf
}
'';
extraFiles = {
"bender" = "${pkgs'.genodeSources}/tool/boot/bender";
"hypervisor" = "${pkgs'.NOVA}/hypervisor-x86_64";
"image.elf.gz" = "${firmware}/image.elf.gz";
};
};
};
};
workman-layout.genode.inputFilter.extraChargen =
"${./dhall/workman.chargen.dhall}";
}