From 85a108bdb3b4bc16ef8afb2b4e421a314af15877 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 16 Feb 2021 12:10:50 +0100 Subject: [PATCH] erisPatch nixos modules --- nixos-modules/genode-core.nix | 347 ++++++++++++++----------- nixos-modules/genode-init.nix | 75 +++++- nixos-modules/gui/default.nix | 4 +- nixos-modules/hardware/ahci.nix | 2 +- nixos-modules/hardware/default.nix | 4 +- nixos-modules/hardware/framebuffer.nix | 9 +- nixos-modules/hardware/nic.nix | 22 +- nixos-modules/hardware/usb.nix | 2 +- nixos-modules/lib/make-ext2-fs.nix | 9 +- nixos-modules/store-wrapper.dhall | 57 ++-- tests/ahci.nix | 2 +- tests/bash.nix | 2 +- tests/hello.nix | 3 +- tests/lib/build-vms.nix | 4 +- tests/lib/testing-python.nix | 1 + tests/lighttpd.nix | 10 - tests/log.nix | 9 +- tests/nim.nix | 2 +- tests/vmm_x86.nix | 2 +- 19 files changed, 308 insertions(+), 258 deletions(-) delete mode 100644 tests/lighttpd.nix diff --git a/nixos-modules/genode-core.nix b/nixos-modules/genode-core.nix index e2781d2..693408c 100644 --- a/nixos-modules/genode-core.nix +++ b/nixos-modules/genode-core.nix @@ -3,10 +3,18 @@ with lib; let localPackages = pkgs.buildPackages; - binary = mkOption { - description = "Program binary for this child."; - type = types.path; + description = "Program binary for this child. Must be an ERIS URN"; + default = null; + type = types.nullOr + (types.str // { check = lib.strings.hasPrefix "urn:erisx2:"; }); + example = + "urn:erisx2:AEAU4KT7AGJLA5BHPWFZ7HX2OVVNVFGDM2SIS726OPZBGXDED64QIDPHN2M5P5HIMOG3YDSWBGDPNUMZKCG4CRVU4DI5BOS5IJRFCSLQQY"; + }; + package = mkOption { + description = "Package to source the binary for this child."; + type = lib.types.package; + example = literalExample "pkg.genodePackages.init"; }; coreROMs = mkOption { type = with types; listOf str; @@ -22,6 +30,152 @@ let default = [ ]; type = types.listOf types.package; }; + + children' = with builtins; + lib.attrsets.mapAttrs (childName: child: + if child.binary != null then { + inherit (child) binary configFile; + roms = { }; + } else + let bin = lib.getEris "bin" child.package; + in { + config = ''${child.configFile} "${bin.cap}"''; + binary = bin.cap; + roms = [{ + name = bin.cap; + value = bin.path; + }] ++ lib.mapAttrsToList (path: cap: { + name = cap; + value = path; + }) bin.closure; + }) config.genode.core.children; + + coreErisCaps = with builtins; + let pkgNames = [ "cached_fs_rom" "jitter_sponge" "rtc_drv" ]; + in listToAttrs (map (name: + let pkg = pkgs.genodePackages.${name}; + in { + inherit name; + value = lib.getEris "bin" pkg; + }) pkgNames); + + tarball = + "${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar"; + + /* romDirectories = filterAttrs (_: value: value != null) (mapAttrs (name: value: + if value.extraInputs == [ ] then + null + else + pkgs.symlinkJoin { + name = "${name}-rom"; + paths = value.extraInputs; + }) config.genode.init.children); + */ + + bootConfigFile = let + + storeBackendInputs = { + fs = [ pkgs.genodePackages.rump ]; + memory = [ config.system.build.tarball ]; + }.${config.genode.boot.storeBackend}; + + coreInputs = with builtins; + concatMap (getAttr "extraInputs") + (attrValues config.genode.core.children); + + mergeManifests = inputs: + with builtins; + let + f = head: input: + if hasAttr "manifest" input then + '' + ${head}, { mapKey = "${ + lib.getName input + }", mapValue = ${input.manifest} }'' + else + abort "${input.pname} does not have a manifest"; + in (foldl' f "[" inputs) + "]"; + + addManifest = drv: + drv // { + manifest = + localPackages.runCommand "${drv.name}.dhall" { inherit drv; } '' + set -eu + echo -n '[' >> $out + find $drv/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out + ${if builtins.elem "lib" drv.outputs then + '' + find ${drv.lib}/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out'' + else + ""} + echo -n ']' >> $out + ''; + }; + + manifest = + # Manifests are Dhall metadata to be attached to every + # package to be used for dynamically buildings enviroments + # using Dhall expressions. Probably not worth pursuing. + pkgs.writeText "manifest.dhall" (mergeManifests (map addManifest + (with pkgs.genodePackages; storeBackendInputs ++ coreInputs)) + + lib.optionalString (config.genode.boot.romModules != { }) '' + # [ { mapKey = "romModules", mapValue = [ ${ + lib.concatStringsSep ", " (lib.lists.flatten ((mapAttrsToList + (k: v: ''{ mapKey = "${k}", mapValue = "${v}" }'') + config.genode.boot.romModules))) + }] } ]''); + + /* storeRomPolicies = mapAttrsToList + (name: value: '', { mapKey = "${name}", mapValue = "${value}" }'') + romDirectories; + */ + + extraRoutes = lib.concatStringsSep ", " (lib.lists.flatten + (lib.mapAttrsToList (name: value: + map (suffix: '' + { service = + { name = "ROM" + , label = + Genode.Init.LabelSelector.Type.Partial + { prefix = Some "nixos -> ${name}", suffix = Some "${suffix}" } + } + , route = Genode.Init.Route.parent (Some "${suffix}") + } + '') value.coreROMs) config.genode.init.children)); + + extraCoreChildren = "[ ${ + lib.concatStringsSep ", " (lib.mapAttrsToList + (name: value: ''{ mapKey = "${name}", mapValue = ${value.config} }'') + children') + } ]"; + + in with coreErisCaps; + localPackages.runCommand "boot.dhall" { } '' + cat > $out << EOF + let Genode = env:DHALL_GENODE in + let VFS = Genode.VFS + let XML = Genode.Prelude.XML + in + ${./store-wrapper.dhall} + { binaries = { + , cached_fs_rom = "${cached_fs_rom.cap}" + , jitter_sponge = "${jitter_sponge.cap}" + , rtc_drv = "${rtc_drv.cap}" + } + , extraCoreChildren = ${extraCoreChildren} + , subinit = ${config.genode.init.configFile} + , storeSize = $(stat --format '%s' ${tarball}) + , routes = [${extraRoutes} ] : List Genode.Init.ServiceRoute.Type + , bootManifest = ${manifest} + } + EOF + ''; + + erisContents = lib.attrsets.mapAttrsToList (urn: source: { + target = "eris/" + urn; + inherit source; + }) config.genode.init.romModules; + in { options.genode = { @@ -43,7 +197,7 @@ in { type = with types; attrsOf (submodule { options = { - inherit binary coreROMs extraInputs; + inherit binary coreROMs extraInputs package; configFile = mkOption { type = types.path; description = '' @@ -132,50 +286,7 @@ in { }; - config = let - - addManifest = drv: - drv // { - manifest = - localPackages.runCommand "${drv.name}.dhall" { inherit drv; } '' - set -eu - echo -n '[' >> $out - find $drv/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out - ${if builtins.elem "lib" drv.outputs then - '' - find ${drv.lib}/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out'' - else - ""} - echo -n ']' >> $out - ''; - }; - - mergeManifests = inputs: - with builtins; - let - f = head: input: - if hasAttr "manifest" input then - '' - ${head}, { mapKey = "${ - lib.getName input - }", mapValue = ${input.manifest} }'' - else - abort "${input.pname} does not have a manifest"; - in (foldl' f "[" inputs) + "]"; - - romDirectories = filterAttrs (_: value: value != null) (mapAttrs - (name: value: - if value.extraInputs == [ ] then - null - else - pkgs.symlinkJoin { - name = "${name}-rom"; - paths = value.extraInputs; - }) config.genode.init.children); - - tarball = - "${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar"; - in { + config = { assertions = [{ assertion = builtins.any (s: @@ -184,25 +295,23 @@ in { message = "invalid Genode core for this system"; }]; - genode.boot.romModules = with pkgs.genodePackages; - let - getBin = name: - "${builtins.getAttr name pkgs.genodePackages}/bin/${name}"; - in { - cached_fs_rom = getBin "cached_fs_rom"; - init = "${init}/bin/init"; - jitter_sponge = "${jitter_sponge}/bin/jitter_sponge"; - report_rom = "${report_rom}/bin/report_rom"; - rtc_drv = "${rtc_drv}/bin/rtc_drv"; - vfs = "${vfs}/bin/vfs"; - "vfs.lib.so" = "${vfs}/lib/vfs.lib.so"; - }; + genode.boot.romModules = with builtins; + let getBin = name: "${getAttr name pkgs.genodePackages}/bin/${name}"; + in listToAttrs (lib.lists.flatten + ((map (getAttr "roms") (attrValues children')) ++ (map + ({ cap, path, ... }: { + name = cap; + value = path; + }) (attrValues coreErisCaps)))) // { + "init" = "${pkgs.genodePackages.init}/bin/init"; + "report_rom" = "${pkgs.genodePackages.report_rom}/bin/report_rom"; + }; genode.core.children = # Component to steer the main fs to a specific partition (if config.genode.boot.storeBackend != "memory" then { part_block = { - binary = "${pkgs.genodePackages.part_block}/bin/part_block"; + package = pkgs.genodePackages.part_block; configFile = pkgs.writeText "part_block.dhall" '' let Genode = env:DHALL_GENODE @@ -234,7 +343,7 @@ in { } else { }) // { fs = { - binary = "${pkgs.genodePackages.vfs}/bin/vfs"; + package = pkgs.genodePackages.vfs; configFile = let vfsConfig = if config.genode.boot.storeBackend == "memory" then '' VFS.vfs @@ -324,97 +433,16 @@ in { }; }; - genode.boot.configFile = let + # genode.boot.storePaths = builtins.attrValues romDirectories; - storeBackendInputs = { - fs = [ pkgs.genodePackages.rump ]; - memory = [ config.system.build.tarball ]; - }.${config.genode.boot.storeBackend}; - - coreInputs = with builtins; - concatMap (getAttr "extraInputs") - (attrValues config.genode.core.children); - - manifest = - # Manifests are Dhall metadata to be attached to every - # package to be used for dynamically buildings enviroments - # using Dhall expressions. Probably not worth pursuing. - pkgs.writeText "manifest.dhall" (mergeManifests (map addManifest - (with pkgs.genodePackages; - storeBackendInputs ++ [ cached_fs_rom jitter_sponge report_rom vfs ] - ++ coreInputs)) - + lib.optionalString (config.genode.boot.romModules != { }) '' - # [ { mapKey = "romModules", mapValue = [ ${ - toString ((mapAttrsToList - (k: v: '', { mapKey = "${k}", mapValue = "${v}" }'') - config.genode.boot.romModules) ++ (lib.attrsets.mapAttrsToList - (name: value: - '' - , { mapKey = "${value.binary}", mapValue = "${value.binary}" }'') - config.genode.core.children)) - }] } ]''); - - storeRomPolicies = mapAttrsToList - (name: value: '', { mapKey = "${name}", mapValue = "${value}" }'') - romDirectories; - - extraRoutes = lib.concatStringsSep ", " (lib.lists.flatten - (lib.mapAttrsToList (name: value: - map (suffix: '' - { service = - { name = "ROM" - , label = - Genode.Init.LabelSelector.Type.Partial - { prefix = Some "nixos -> ${name}", suffix = Some "${suffix}" } - } - , route = Genode.Init.Route.parent (Some "${suffix}") - } - '') value.coreROMs) config.genode.init.children)); - - extraCoreChildren = "[ ${ - toString (lib.mapAttrsToList (name: value: - '' - , { mapKey = "${name}", mapValue = ${value.configFile} "${value.binary}" }'') - config.genode.core.children) - } ]"; - - in localPackages.runCommand "boot.dhall" { } '' - cat > $out << EOF - let Genode = env:DHALL_GENODE in - let VFS = Genode.VFS - let XML = Genode.Prelude.XML - in - ${./store-wrapper.dhall} - { extraCoreChildren = ${extraCoreChildren} - , subinit = ${config.genode.init.configFile} - , storeSize = $(stat --format '%s' ${tarball}) - , storeRomPolicies = [${ - toString storeRomPolicies - } ] : Genode.Prelude.Map.Type Text Text - , routes = [${extraRoutes} ] : List Genode.Init.ServiceRoute.Type - , bootManifest = ${manifest} - } - EOF - ''; - - genode.boot.storePaths = with builtins; - [ config.genode.init.configFile ] ++ (attrValues romDirectories); + genode.boot.configFile = bootConfigFile; # Create the tarball of the store to live in core ROM system.build.tarball = pkgs.callPackage "${modulesPath}/../lib/make-system-tarball.nix" { - contents = [ ]; - storeContents = let - romDirs = mapAttrsToList (name: object: { - symlink = "rom/${name}"; - inherit object; - }) romDirectories; - configFiles = mapAttrsToList (name: child: { - symlink = "config/${name}.dhall"; - object = pkgs.writeText "${name}.dhall" - "${child.configFile} ${child.binary}"; - }) config.genode.init.children; - in romDirs ++ configFiles; + extraInputs = lib.attrsets.mapAttrsToList (name: child: child.package) + config.genode.init.children; + contents = erisContents; compressCommand = "cat"; compressionExtension = ""; }; @@ -427,14 +455,16 @@ in { lndir -silent \ ${pkgs.genodePackages.dhallGenode}/.cache \ $XDG_CACHE_HOME - dhall text <<< "(env:DHALL_GENODE).Init.render (${config.genode.boot.configFile}).config" > $out + dhall text <<< "(env:DHALL_GENODE).Init.render (${bootConfigFile}).config" > $out xmllint --noout $out ''; virtualisation.diskImage = let espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; }; - storeFsImage = - pkgs.callPackage ./lib/make-ext2-fs.nix { inherit config pkgs; }; + storeFsImage = pkgs.callPackage ./lib/make-ext2-fs.nix { + inherit config lib pkgs; + contents = erisContents; + }; bootDriveImage = import ./lib/make-bootable-image.nix { inherit config pkgs espImage storeFsImage; }; @@ -442,12 +472,13 @@ in { virtualisation.useBootLoader = config.genode.boot.storeBackend != "memory"; - virtualisation.qemu.options = - let blockCommon = [ "-bios ${pkgs.buildPackages.buildPackages.OVMF.fd}/FV/OVMF.fd" ]; - in { - fs = blockCommon; - memory = [ ]; - }.${config.genode.boot.storeBackend}; + virtualisation.qemu.options = let + blockCommon = + [ "-bios ${pkgs.buildPackages.buildPackages.OVMF.fd}/FV/OVMF.fd" ]; + in { + fs = blockCommon; + memory = [ ]; + }.${config.genode.boot.storeBackend}; }; diff --git a/nixos-modules/genode-init.nix b/nixos-modules/genode-init.nix index f870f08..6a160de 100644 --- a/nixos-modules/genode-init.nix +++ b/nixos-modules/genode-init.nix @@ -6,8 +6,17 @@ let cfg = config.genode.init; binary = mkOption { - description = "Program binary for this child."; - type = types.path; + description = "Program binary for this child. Must be an ERIS URN."; + default = null; + type = types.nullOr + (types.str // { check = lib.strings.hasPrefix "urn:erisx2:"; }); + example = + "urn:erisx2:AEAU4KT7AGJLA5BHPWFZ7HX2OVVNVFGDM2SIS726OPZBGXDED64QIDPHN2M5P5HIMOG3YDSWBGDPNUMZKCG4CRVU4DI5BOS5IJRFCSLQQY"; + }; + package = mkOption { + description = "Package to source the binary for this child."; + type = lib.types.package; + example = literalExample "pkg.genodePackages.init"; }; coreROMs = mkOption { type = with types; listOf str; @@ -18,11 +27,41 @@ let ''; example = [ "platform_info" ]; }; - extraInputs = mkOption { - description = "List of packages to build a ROM store with."; + extraInputs = + # TODO: deprecated? + mkOption { + description = "List of packages to build a ROM store with."; + default = [ ]; + type = types.listOf types.package; + }; + + extraErisInputs = mkOption { + description = "List of ERIS inputs to add to the init closure."; default = [ ]; - type = types.listOf types.package; + type = types.listOf types.attrs; }; + + children' = with builtins; + lib.attrsets.mapAttrs (childName: child: + let + toRoms = { cap, closure, path }: + [{ + name = cap; + value = path; + }] ++ (lib.mapAttrsToList (value: name: { inherit name value; }) + closure); + extraRoms = lib.lists.flatten (map toRoms child.extraErisInputs); + in if child.binary != null then { + inherit (child) binary configFile; + roms = { }; # extraRoms; + } else + let bin = lib.getEris "bin" child.package; + in { + config = ''${child.configFile} "${bin.cap}"''; + binary = bin.cap; + roms = toRoms bin ++ extraRoms; + }) config.genode.init.children; + in { options.genode.init = { @@ -62,7 +101,7 @@ in { type = with types; attrsOf (submodule { options = { - inherit binary coreROMs extraInputs; + inherit binary coreROMs extraErisInputs extraInputs package; routeToNics = lib.mkOption { type = with types; listOf str; @@ -94,6 +133,12 @@ in { }); }; + romModules = mkOption { + type = types.attrsOf types.path; + default = { }; + description = "Attr set of initial ROM modules"; + }; + subinits = # Subinits are just a different kind of children. # Eventually this will be nested "genode.init" instances. @@ -102,7 +147,7 @@ in { type = with types; attrsOf (submodule { options = { - inherit binary coreROMs extraInputs; + inherit binary coreROMs extraErisInputs extraInputs; configFile = mkOption { type = types.path; description = '' @@ -121,7 +166,7 @@ in { # TODO: convert the subinits to children children = mapAttrs (name: value: { - inherit (value) extraInputs; + inherit (value) extraErisInputs extraInputs; configFile = pkgs.writeText "${name}.child.dhall" '' let Genode = env:DHALL_GENODE @@ -131,9 +176,9 @@ in { configFile = let - children = lib.mapAttrsToList - (name: value: '', `${name}` = ${value.configFile} "${value.binary}"'') - cfg.children; + children = + lib.mapAttrsToList (name: value: ", `${name}` = ${value.config} ") + children'; nicRoutes = lib.mapAttrsToList (child: value: (map (label: '' @@ -153,12 +198,16 @@ in { in baseConfig // { , verbose = ${if config.genode.init.verbose then "True" else "False"} , children = baseConfig.children # toMap {${toString children} } - , routes = baseConfig.routes # [${ + , routes = baseConfig.routes # ([${ toString nicRoutes - }] : List Genode.Init.ServiceRoute.Type + }] : List Genode.Init.ServiceRoute.Type) } : Genode.Init.Type ''; + romModules = with builtins; + listToAttrs (lib.lists.flatten + (map ({ roms, ... }: roms) (lib.lists.flatten (attrValues children')))); + }; } diff --git a/nixos-modules/gui/default.nix b/nixos-modules/gui/default.nix index 2e97774..ec8d291 100644 --- a/nixos-modules/gui/default.nix +++ b/nixos-modules/gui/default.nix @@ -16,7 +16,7 @@ in { hardware.genode.framebuffer.enable = cfg.enable; genode.core.children.nitpicker = mkIf cfg.enable { - binary = "${pkgs.genodePackages.nitpicker}/bin/nitpicker"; + binary = pkgs.genodePackages.nitpicker; configFile = pkgs.writeText "nitpicker.dhall" '' let Init = (env:DHALL_GENODE).Init @@ -38,7 +38,7 @@ in { }; genode.core.children.consoleLog = mkIf cfg.consoleLog.enable { - binary = "${pkgs.genodePackages.init}/bin/init"; + binary = pkgs.genodePackages.init; extraInputs = with pkgs.genodePackages; [ gui_fb log_core diff --git a/nixos-modules/hardware/ahci.nix b/nixos-modules/hardware/ahci.nix index 6fd2b49..b754dd3 100644 --- a/nixos-modules/hardware/ahci.nix +++ b/nixos-modules/hardware/ahci.nix @@ -25,7 +25,7 @@ with lib; ''); genode.core.children.ahci_drv = lib.mkIf cfg.enable { - binary = "${pkgs.genodePackages.ahci_drv}/bin/ahci_drv"; + package = pkgs.genodePackages.ahci_drv; configFile = pkgs.writeText "ahci_drv.dhall" '' let Genode = env:DHALL_GENODE diff --git a/nixos-modules/hardware/default.nix b/nixos-modules/hardware/default.nix index 791889b..460e4f3 100644 --- a/nixos-modules/hardware/default.nix +++ b/nixos-modules/hardware/default.nix @@ -17,7 +17,7 @@ with lib; config = { genode.core.children.acpi_drv = { - binary = "${pkgs.genodePackages.acpi_drv}/bin/acpi_drv"; + package = pkgs.genodePackages.acpi_drv; configFile = pkgs.writeText "acpi_drv.dhall" '' let Genode = env:DHALL_GENODE @@ -45,7 +45,7 @@ with lib; }; genode.core.children.platform_drv = { - binary = "${pkgs.genodePackages.platform_drv}/bin/platform_drv"; + package = pkgs.genodePackages.platform_drv; configFile = let policies = map (policy: ", ${policy}") config.hardware.genode.platform.policies; diff --git a/nixos-modules/hardware/framebuffer.nix b/nixos-modules/hardware/framebuffer.nix index 6cb4cab..a9ba1ab 100644 --- a/nixos-modules/hardware/framebuffer.nix +++ b/nixos-modules/hardware/framebuffer.nix @@ -15,16 +15,11 @@ with lib; genode.core.children.fb_drv = mkIf config.hardware.genode.framebuffer.enable { - 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}/bin/boot_fb_drv"; - vesa = "${vesa_drv}/bin/vesa_fb_drv"; + boot = boot_fb_drv; + vesa = vesa_drv; }.${config.hardware.genode.framebuffer.driver}; in builtins.toFile "fb_drv.dhall" '' let Genode = env:DHALL_GENODE diff --git a/nixos-modules/hardware/nic.nix b/nixos-modules/hardware/nic.nix index a01b0a4..63db860 100644 --- a/nixos-modules/hardware/nic.nix +++ b/nixos-modules/hardware/nic.nix @@ -44,8 +44,7 @@ with lib; else null) config.genode.init.children); in { - assertion = - trace clientList (clientList == [ ] || length clientList == 1); + assertion = clientList == [ ] || length clientList == 1; message = "Multiple routes to Nic ${name}, ${clientList}"; }; in lib.lists.concatMap @@ -79,10 +78,10 @@ with lib; in { name = name'; value = { - binary = with pkgs.genodePackages; + package = with pkgs.genodePackages; { - ipxe = "${ipxe_nic_drv}/bin/ipxe_nic_drv"; - virtio = "${virtio_nic_drv}/bin/virtio_nic_drv"; + ipxe = ipxe_nic_drv; + virtio = virtio_nic_drv; }.${interface.genode.driver}; configFile = let policy = lib.mapAttrsToList (childName: value: @@ -119,17 +118,18 @@ with lib; sockets = mapAttrs' (name: interface: let name' = name + ".sockets"; - vfsPlugin = with pkgs.genodePackages; + vfsPlugin = lib.getEris "lib" (with pkgs.genodePackages; { - lwip = "${vfs_lwip}/lib/vfs_lwip.lib.so"; - lxip = "${vfs_lxip}/lib/vfs_lxip.lib.so"; - }.${interface.genode.stack}; + lwip = vfs_lwip; + lxip = vfs_lxip; + }.${interface.genode.stack}); in { name = name'; value = if interface.genode.stack == null then null else { - binary = "${pkgs.genodePackages.vfs}/bin/vfs"; + package = pkgs.genodePackages.vfs; + extraErisInputs = [ vfsPlugin ]; routeToNics = [ name ]; configFile = let ram = { @@ -144,7 +144,7 @@ with lib; } { name = "load"; - value = vfsPlugin; + value = vfsPlugin.cap; } ] ++ lib.optionals (interface.ipv4.addresses != [ ]) (let addr = head interface.ipv4.addresses; diff --git a/nixos-modules/hardware/usb.nix b/nixos-modules/hardware/usb.nix index ec78b0e..1d33f46 100644 --- a/nixos-modules/hardware/usb.nix +++ b/nixos-modules/hardware/usb.nix @@ -88,7 +88,7 @@ with lib; genode.core.children.usb_block_drv = mkIf config.hardware.genode.usb.storage.enable { - binary = "${pkgs.genodePackages.usb_block_drv}/bin/usb_block_drv"; + binary = pkgs.genodePackages.usb_block_drv; configFile = builtins.toFile "usb_block_drv.dhall" '' let Genode = env:DHALL_GENODE diff --git a/nixos-modules/lib/make-ext2-fs.nix b/nixos-modules/lib/make-ext2-fs.nix index 8e12230..2fe591f 100644 --- a/nixos-modules/lib/make-ext2-fs.nix +++ b/nixos-modules/lib/make-ext2-fs.nix @@ -1,10 +1,15 @@ -{ config, pkgs }: +{ config, lib, pkgs, extraInputs ? [ ], contents }: let grub' = pkgs.buildPackages.grub2_efi; sdClosureInfo = pkgs.buildPackages.closureInfo { rootPaths = config.genode.boot.storePaths; }; + + copyEris = lib.strings.concatMapStrings ({ source, target }: '' + cp -a --reflink=auto -t "./rootImage/${target}" "${source}" + '') contents; + in pkgs.stdenv.mkDerivation { name = "ext2-fs.img.zstd"; @@ -49,6 +54,8 @@ in pkgs.stdenv.mkDerivation { done ) + ${copyEris} + # Also include a manifest of the closures in a format suitable for nix-store --load-db cp ${sdClosureInfo}/registration ./rootImage/nix-path-registration diff --git a/nixos-modules/store-wrapper.dhall b/nixos-modules/store-wrapper.dhall index 02b81b5..a912a1e 100644 --- a/nixos-modules/store-wrapper.dhall +++ b/nixos-modules/store-wrapper.dhall @@ -13,10 +13,11 @@ let ChildMapType = TextMapType Child.Type let Manifest/Type = TextMapType (TextMapType Text) in λ ( params - : { extraCoreChildren : ChildMapType + : { binaries : + { cached_fs_rom : Text, jitter_sponge : Text, rtc_drv : Text } + , extraCoreChildren : ChildMapType , subinit : Init.Type , storeSize : Natural - , storeRomPolicies : Prelude.Map.Type Text Text , routes : List Init.ServiceRoute.Type , bootManifest : Manifest/Type } @@ -46,7 +47,7 @@ in λ ( params "rtc" ( Child.flat Child.Attributes::{ - , binary = "rtc_drv" + , binary = params.binaries.rtc_drv , routes = [ Init.ServiceRoute.parent "IO_PORT" ] , config = Init.Config::{ , policies = @@ -62,7 +63,7 @@ in λ ( params "jitter_sponge" ( Child.flat Child.Attributes::{ - , binary = "jitter_sponge" + , binary = params.binaries.jitter_sponge , config = Init.Config::{ , policies = [ Init.Config.Policy::{ @@ -77,11 +78,14 @@ in λ ( params "store_rom" ( Child.flat Child.Attributes::{ - , binary = "cached_fs_rom" + , binary = params.binaries.cached_fs_rom , resources = Init.Resources::{ , ram = params.storeSize + Genode.units.MiB 1 } , config = Init.Config::{ + , defaultPolicy = Some Init.Config.DefaultPolicy::{ + , attributes = toMap { directory = "/eris" } + } , policies = let directStoreROMs = Prelude.List.map @@ -106,49 +110,22 @@ in λ ( params params.subinit.children ) - let indirectStoreROMS = - let Entry = Prelude.Map.Entry Text Text - - in Prelude.List.concatMap - Entry - Init.Config.Policy.Type - ( λ(e : Entry) → - [ Init.Config.Policy::{ - , service = "ROM" - , label = - Init.LabelSelector.prefix - "nixos -> ${e.mapKey}" - , attributes = toMap - { directory = - "${e.mapValue}/bin" - } - } - , Init.Config.Policy::{ - , service = "ROM" - , label = - Init.LabelSelector.Type.Partial - { prefix = Some - "nixos -> ${e.mapKey}" - , suffix = Some ".so" - } - , attributes = toMap - { directory = - "${e.mapValue}/lib" - } - } - ] - ) - params.storeRomPolicies - in [ Init.Config.Policy::{ , service = "ROM" , label = Init.LabelSelector.prefix "nixos -> /nix/store" } + , Init.Config.Policy::{ + , attributes = toMap + { directory = "/eris" } + , label = + Init.LabelSelector.prefix + "nixos -> " + , service = "ROM" + } ] # directStoreROMs - # indirectStoreROMS } } ) diff --git a/tests/ahci.nix b/tests/ahci.nix index 738584c..3e62dd7 100644 --- a/tests/ahci.nix +++ b/tests/ahci.nix @@ -8,7 +8,7 @@ }; genode.boot.storeBackend = "fs"; genode.init.children.hello = { - binary = "${pkgs.hello}/bin/hello"; + package = pkgs.hello; configFile = ./hello.dhall; }; }; diff --git a/tests/bash.nix b/tests/bash.nix index 0714cfb..ebccc7c 100644 --- a/tests/bash.nix +++ b/tests/bash.nix @@ -2,7 +2,7 @@ name = "bash"; machine = { pkgs, ... }: { genode.init.children.bash = { - binary = "${pkgs.genodePackages.init}/bin/init"; + package = pkgs.genodePackages.init; configFile = pkgs.writeText "bash.child.dhall" '' ${ ./bash.dhall diff --git a/tests/hello.nix b/tests/hello.nix index 9b054da..30475b6 100644 --- a/tests/hello.nix +++ b/tests/hello.nix @@ -1,8 +1,9 @@ { name = "hello"; machine = { pkgs, ... }: { + genode.init.verbose = true; genode.init.children.hello = { - binary = "${pkgs.hello}/bin/hello"; + package = pkgs.hello; configFile = ./hello.dhall; }; }; diff --git a/tests/lib/build-vms.nix b/tests/lib/build-vms.nix index 5899ee9..92a2510 100644 --- a/tests/lib/build-vms.nix +++ b/tests/lib/build-vms.nix @@ -1,6 +1,6 @@ { system, localSystem, crossSystem # Nixpkgs, for qemu, lib and more -, pkgs, modulesPath +, pkgs, lib, modulesPath # NixOS configuration to add to the VMs , extraConfigurations ? [ ] }: @@ -24,7 +24,7 @@ rec { buildVM = nodes: configurations: import "${modulesPath}/../lib/eval-config.nix" { - inherit system; + inherit lib system; modules = configurations ++ extraConfigurations; baseModules = (import "${modulesPath}/module-list.nix") ++ [ ../../nixos-modules/file-systems.nix diff --git a/tests/lib/testing-python.nix b/tests/lib/testing-python.nix index f9715d8..4bba159 100644 --- a/tests/lib/testing-python.nix +++ b/tests/lib/testing-python.nix @@ -4,6 +4,7 @@ with import ./build-vms.nix { inherit system localSystem crossSystem pkgs extraConfigurations; + inherit (flake) lib; modulesPath = "${flake.inputs.nixpkgs}/nixos/modules"; }; with pkgs.buildPackages.buildPackages; diff --git a/tests/lighttpd.nix b/tests/lighttpd.nix deleted file mode 100644 index 2904cad..0000000 --- a/tests/lighttpd.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ - name = "lighttpd"; - machine = { pkgs, ... }: { - imports = [ ../nixos-modules/systemd.nix ]; - services.lighttpd = { - enable = true; - }; - systemd.services.lighttpd.genode.enable = true; - }; -} diff --git a/tests/log.nix b/tests/log.nix index 7722196..65afd82 100644 --- a/tests/log.nix +++ b/tests/log.nix @@ -1,12 +1,11 @@ { name = "log"; - machine = { pkgs, ... }: { + machine = { lib, pkgs, ... }: { + genode.init.children.log = { - binary = "${pkgs.genodePackages.test-log}/bin/test-log"; + package = pkgs.genodePackages.test-log; configFile = pkgs.writeText "test-log.dhall" '' - let Genode = - env:DHALL_GENODE - ? https://git.sr.ht/~ehmry/dhall-genode/blob/master/package.dhall + let Genode = env:DHALL_GENODE let Child = Genode.Init.Child diff --git a/tests/nim.nix b/tests/nim.nix index 3fa6e20..4dfd4f9 100644 --- a/tests/nim.nix +++ b/tests/nim.nix @@ -23,7 +23,7 @@ ''; }; in { - binary = "${testNim}/bin/test_nim"; + package = testNim; extraInputs = with pkgs.genodePackages; [ libc stdcxx ]; configFile = builtins.toFile "nim.dhall" '' let Genode = env:DHALL_GENODE diff --git a/tests/vmm_x86.nix b/tests/vmm_x86.nix index a586c27..25fd753 100644 --- a/tests/vmm_x86.nix +++ b/tests/vmm_x86.nix @@ -5,7 +5,7 @@ all (f: any f specs) [ (spec: spec == "nova") (spec: spec == "x86") ]; machine = { pkgs, ... }: { genode.init.children.vmm = { - binary = "${pkgs.genodePackages.test-vmm_x86}/bin/test-vmm_x86"; + package = pkgs.genodePackages.test-vmm_x86; configFile = ./vmm_x86.dhall; coreROMs = [ "platform_info" ]; };