From 57a093afeabd1ef6088755a3cf927133a739ff4c Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 24 Nov 2020 20:24:07 +0100 Subject: [PATCH] Update dhall-genode for Libc helper --- flake.lock | 6 +- nixos-modules/dhall/console.dhall | 94 ++++++++++++++++------------ nixos-modules/dhall/vbox-guest.dhall | 51 +++++---------- nixos-modules/store-wrapper.dhall | 2 - nixos-modules/systemd-runner.dhall | 54 ++++++---------- nixos-modules/systemd.nix | 7 ++- packages/dhall/genode.nix | 18 ++---- tests/bash.dhall | 54 +++++----------- tests/hello.dhall | 37 +---------- tests/hello.nix | 2 +- tests/posix.dhall | 33 ++++------ 11 files changed, 136 insertions(+), 222 deletions(-) diff --git a/flake.lock b/flake.lock index af5af5c..a33a5f8 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1605706415, - "narHash": "sha256-TNMK7m95qrHyauJAz5b6FonwMFZvMl75GL/Zpk7FMSE=", + "lastModified": 1606240001, + "narHash": "sha256-XaZWsa2SAtvgH6qC8DBPe8/MAEX+hbHQ2E2HqB7GeqM=", "owner": "ehmry", "repo": "nixpkgs", - "rev": "1f87da9eaa90afacc256f842e05e1111aa03ffa1", + "rev": "1ab17e1a3abf3005974cd4c09732efb635f44483", "type": "github" }, "original": { diff --git a/nixos-modules/dhall/console.dhall b/nixos-modules/dhall/console.dhall index 4ff9373..160799d 100644 --- a/nixos-modules/dhall/console.dhall +++ b/nixos-modules/dhall/console.dhall @@ -12,6 +12,10 @@ let Resources = Init.Resources let ServiceRoute = Init.ServiceRoute +let Libc = Genode.Libc + +let VFS = Genode.VFS + in λ(params : { bash : Text, coreutils : Text, path : Text }) → let init = Init::{ @@ -81,24 +85,40 @@ in λ(params : { bash : Text, coreutils : Text, path : Text }) → , binary = "vfs" , config = Init.Config::{ , content = - [ Prelude.XML.text - '' - - - - - - - - - - - - - - - - '' + [ VFS.vfs + [ VFS.dir + "dev" + [ VFS.leaf "log" + , VFS.leaf "null" + , VFS.dir "pipe" [ VFS.leaf "pipe" ] + , VFS.leaf "rtc" + , VFS.leaf "terminal" + , VFS.leaf "zero" + ] + , VFS.dir + "usr" + [ VFS.dir + "bin" + [ VFS.symlink + "${params.coreutils}/bin/env" + "env" + ] + ] + , VFS.dir "tmp" [ VFS.leaf "ram" ] + , VFS.dir + "nix" + [ VFS.dir + "store" + [ VFS.fs VFS.FS::{ label = "nix-store" } ] + ] + ] + ] + , policies = + [ Init.Config.Policy::{ + , service = "File_system" + , attributes = toMap + { root = "/", writeable = "yes" } + } ] } , provides = [ "File_system" ] @@ -126,28 +146,22 @@ in λ(params : { bash : Text, coreutils : Text, path : Text }) → Child.flat Child.Attributes::{ , binary = "bash" - , config = Genode.Init.Config::{ - , content = - [ Prelude.XML.text - '' - - - - - - '' - ] - # Prelude.List.map - Text - XML.Type - ( λ(x : Text) → - XML.leaf - { name = "arg" - , attributes = toMap { value = x } - } - ) - [ "bash" ] - } + , config = + Libc.toConfig + Libc::{ + , stdin = Some "/dev/terminal" + , stdout = Some "/dev/terminal" + , stderr = Some "/dev/terminal" + , pipe = Some "/dev/pipe" + , rtc = Some "/dev/rtc" + , vfs = [ VFS.leaf "fs" ] + , env = toMap + { TERM = "screen" + , PATH = "${params.path}" + , PS1 = "system:\$PWD" + } + , args = [ "bash" ] + } , exitPropagate = True , resources = Resources::{ , caps = 256 diff --git a/nixos-modules/dhall/vbox-guest.dhall b/nixos-modules/dhall/vbox-guest.dhall index 2ec939f..4e26bee 100644 --- a/nixos-modules/dhall/vbox-guest.dhall +++ b/nixos-modules/dhall/vbox-guest.dhall @@ -12,14 +12,9 @@ let Resources = Init.Resources let ServiceRoute = Init.ServiceRoute -let Vfs/inline = - λ(name : Text) → - λ(body : Text) → - XML.element - { name = "inline" - , attributes = toMap { name } - , content = [ XML.text body ] - } +let Libc = Genode.Libc + +let VFS = Genode.VFS let BootFormat = < ISO | VDI > @@ -143,24 +138,10 @@ let toVbox = in Child.flat Child.Attributes::{ , binary = "virtualbox5" - , config = Init.Config::{ - , attributes = toMap - { vbox_file = "machine.vbox", vm_name = params.vmName } - , content = - [ XML.leaf - { name = "libc" - , attributes = toMap - { stdout = "/log", stderr = "/log", rtc = "/dev/rtc" } - } - , XML.element - { name = "vfs" - , attributes = XML.emptyAttributes - , content = - let tag = - λ(name : Text) → - XML.leaf - { name, attributes = XML.emptyAttributes } - + , config = + ( Libc.toConfig + Libc::{ + , vfs = let mutableVfs = let fsNode = [ XML.leaf @@ -202,17 +183,19 @@ let toVbox = } params.bootFormat - in [ Vfs/inline "machine.vbox" vboxConfig - , XML.element - { name = "dir" - , attributes = toMap { name = "dev" } - , content = [ tag "log", tag "rtc" ] - } + in [ VFS.inline "machine.vbox" vboxConfig + , VFS.dir + "dev" + [ VFS.leaf "log" + , VFS.leaf "null" + , VFS.leaf "rtc" + ] ] # mutableVfs } - ] - } + ) + with attributes = toMap + { vbox_file = "machine.vbox", vm_name = params.vmName } , resources = Resources::{ , caps = 1024 , ram = diff --git a/nixos-modules/store-wrapper.dhall b/nixos-modules/store-wrapper.dhall index 5aaa9eb..c8f6aa7 100644 --- a/nixos-modules/store-wrapper.dhall +++ b/nixos-modules/store-wrapper.dhall @@ -2,8 +2,6 @@ let Genode = env:DHALL_GENODE let Prelude = Genode.Prelude -let XML = Prelude.XML - let Init = Genode.Init let Child = Init.Child diff --git a/nixos-modules/systemd-runner.dhall b/nixos-modules/systemd-runner.dhall index e11c5cc..78cc769 100644 --- a/nixos-modules/systemd-runner.dhall +++ b/nixos-modules/systemd-runner.dhall @@ -4,6 +4,8 @@ let Prelude = Genode.Prelude let XML = Prelude.XML +let Libc = Genode.Libc + let VFS = Genode.VFS let Init = Genode.Init @@ -14,11 +16,7 @@ let parentRoutes = Prelude.List.map Text Init.ServiceRoute.Type Init.ServiceRoute.parent in λ ( params - : { name : Text - , coreutils : Text - , execStart : Text - , interface : Optional Text - } + : { args : List Text, coreutils : Text, interface : Optional Text } ) → let socketsVfs = merge @@ -80,7 +78,7 @@ in λ ( params , policies = [ Init.Config.Policy::{ , service = "File_system" - , label = Init.LabelSelector.prefix "shell" + , label = Init.LabelSelector.prefix "ExecStart" , attributes = toMap { root = "/", writeable = "yes" } } @@ -106,12 +104,12 @@ in λ ( params [ Init.Config.Policy::{ , service = "ROM" , diag = Some True - , label = Init.LabelSelector.prefix "shell" + , label = Init.LabelSelector.prefix "ExecStart" } ] } } - , shell = + , ExecStart = Child.flat Child.Attributes::{ , binary = "bash" @@ -120,32 +118,20 @@ in λ ( params , caps = 256 , ram = Genode.units.MiB 8 } - , config = Init.Config::{ - , content = - [ XML.leaf - { name = "libc" - , attributes = toMap - { stdin = "/dev/null" - , stdout = "/dev/log" - , stderr = "/dev/log" - , pipe = "/dev/pipes" - , rtc = "/dev/rtc" - , socket = "/dev/sockets" - } - } - , VFS.vfs [ VFS.leaf "fs" ] - ] - # Prelude.List.map - Text - XML.Type - ( λ(x : Text) → - XML.leaf - { name = "arg" - , attributes = toMap { value = x } - } - ) - [ "bash", "-c", params.execStart ] - } + , config = + ( Libc.toConfig + Libc::{ + , stdin = Some "/dev/null" + , stdout = Some "/dev/log" + , stderr = Some "/dev/log" + , pipe = Some "/dev/pipes" + , rtc = Some "/dev/rtc" + , socket = Some "/dev/sockets" + , vfs = [ VFS.leaf "fs" ] + , args = params.args + } + ) + with attributes = toMap { ld_verbose = "yes" } , routes = Prelude.List.map Text diff --git a/nixos-modules/systemd.nix b/nixos-modules/systemd.nix index d4d3b80..d86f630 100644 --- a/nixos-modules/systemd.nix +++ b/nixos-modules/systemd.nix @@ -46,15 +46,18 @@ with lib; { vfs_pipe ]; configFile = let + args = ''[ "'' + concatStringsSep ''", "'' + ((lib.strings.splitString " ") + (toString service.serviceConfig.ExecStart)) + ''" ]''; + # TODO: service.environment; interface = if service.genode.interface == null then "None Text" else ''Some "${service.genode.interface}"''; in pkgs.writeText "${name'}.dhall" '' ${./systemd-runner.dhall} { - , name = "${name'}" + , args = ${args} , coreutils = "${pkgs.coreutils}" - , execStart = "${toString service.serviceConfig.ExecStart}" , interface = ${interface} } ''; diff --git a/packages/dhall/genode.nix b/packages/dhall/genode.nix index 2558341..81185be 100644 --- a/packages/dhall/genode.nix +++ b/packages/dhall/genode.nix @@ -1,17 +1,11 @@ { stdenv, fetchgit, dhallPackages }: -dhallPackages.buildDhallPackage { +dhallPackages.buildDhallDirectoryPackage { name = "dhall-genode"; - - code = let - src = fetchgit { - url = "https://git.sr.ht/~ehmry/dhall-genode"; - rev = "882740d78425bb1a6c4b1b34b1b201ace9d71317"; - sha256 = "0cqlrbjb6023x7yynnglv11755xiw0wy4g16r88nsflcw119czqm"; - }; - in src + "/package.dhall"; - + src = fetchgit { + url = "https://git.sr.ht/~ehmry/dhall-genode"; + rev = "01b99d53f597cac40c6b4761d6dd750fc89f63da"; + sha256 = "1df4plhr72rhva9rdphlyq244j0rmldkpa7bj6mjzwarisdxw9vv"; + }; dependencies = [ dhallPackages.Prelude ]; - - source = true; } diff --git a/tests/bash.dhall b/tests/bash.dhall index 020aa8e..5bce1ed 100644 --- a/tests/bash.dhall +++ b/tests/bash.dhall @@ -2,8 +2,6 @@ let Genode = env:DHALL_GENODE let Prelude = Genode.Prelude -let XML = Prelude.XML - let VFS = Genode.VFS let Init = Genode.Init @@ -126,43 +124,21 @@ in λ(params : { bash : Text, coreutils : Text }) → , "posix.lib.so" , "vfs.lib.so" ] - , config = Genode.Init.Config::{ - , attributes = toMap { ld_verbose = "true" } - , content = - let env = - λ(key : Text) → - λ(value : Text) → - XML.leaf - { name = "env" - , attributes = toMap { key, value } - } - - let arg = - λ(value : Text) → - XML.leaf - { name = "arg" - , attributes = toMap { value } - } - - in [ XML.leaf - { name = "libc" - , attributes = toMap - { stdin = "/dev/null" - , stdout = "/dev/log" - , stderr = "/dev/log" - , pipe = "/dev/pipe" - , rtc = "/dev/rtc" - } - } - , VFS.vfs [ VFS.fs VFS.FS::{ label = "root" } ] - , env "TERM" "screen" - , env - "PATH" - "${params.coreutils}/bin:${params.bash}/bin" - , arg "bash" - , arg "/script.sh" - ] - } + , config = + ( Libc.toConfig + Libc::{ + , pipe = Some "/dev/pipe" + , rtc = Some "/dev/rtc" + , vfs = [ VFS.fs VFS.FS::{ label = "root" } ] + , env = toMap + { TERM = "screen" + , PATH = + "${params.coreutils}/bin:${params.bash}/bin" + } + , args = [ "bash", "/script.sh" ] + } + ) + with attributes = toMap { ld_verbose = "true" } } } } diff --git a/tests/hello.dhall b/tests/hello.dhall index 34a6ad6..c3773f2 100644 --- a/tests/hello.dhall +++ b/tests/hello.dhall @@ -6,6 +6,8 @@ let Init = Genode.Init let Child = Init.Child +let Libc = Genode.Libc + in Child.flat Child.Attributes::{ , binary = "hello" @@ -14,38 +16,5 @@ in Child.flat , caps = 500 , ram = Genode.units.MiB 10 } - , config = Init.Config::{ - , content = - let XML = Genode.Prelude.XML - - in [ XML.leaf - { name = "libc" - , attributes = toMap - { stdin = "/dev/null" - , stdout = "/dev/log" - , stderr = "/dev/log" - } - } - , XML.element - { name = "vfs" - , attributes = XML.emptyAttributes - , content = - let dir = - λ(name : Text) → - λ(content : List XML.Type) → - XML.element - { name = "dir" - , content - , attributes = toMap { name } - } - - let leaf = - λ(name : Text) → - XML.leaf - { name, attributes = XML.emptyAttributes } - - in [ dir "dev" [ leaf "log", leaf "null" ] ] - } - ] - } + , config = Libc.toConfig Libc.default } diff --git a/tests/hello.nix b/tests/hello.nix index 138fed4..b01400a 100644 --- a/tests/hello.nix +++ b/tests/hello.nix @@ -19,7 +19,7 @@ genode.init.children.hello = { configFile = ./hello.dhall; inputs = [ hello pkgs.genodePackages.vfs.lib ]; - # TODO: libc.lib.so has only relative linking to vfs.lib.so + # TODO: libc.lib.so has only relative linking to vfs.lib.so }; }; testScript = '' diff --git a/tests/posix.dhall b/tests/posix.dhall index 0b6a6dd..5fb9ce3 100644 --- a/tests/posix.dhall +++ b/tests/posix.dhall @@ -4,12 +4,14 @@ let Genode = Test.Genode let Prelude = Genode.Prelude -let XML = Prelude.XML - let Init = Genode.Init let Child = Init.Child +let Libc = Genode.Libc + +let VFS = Genode.VFS + in λ(params : { bash : Text, coreutils : Text, script : Text }) → let init = Init::{ @@ -78,25 +80,14 @@ in λ(params : { bash : Text, coreutils : Text, script : Text }) → Child.flat Child.Attributes::{ , binary = "bash" - , config = Genode.Init.Config::{ - , content = - [ Prelude.XML.text - '' - - - '' - ] - # Prelude.List.map - Text - XML.Type - ( λ(x : Text) → - XML.leaf - { name = "arg" - , attributes = toMap { value = x } - } - ) - [ "bash", params.script ] - } + , config = + Libc.toConfig + Libc::{ + , pipe = Some "/dev/pipe" + , rtc = Some "/dev/rtc" + , vfs = [ VFS.leaf "fs" ] + , args = [ "bash", params.script ] + } , exitPropagate = True , resources = Genode.Init.Resources::{ , caps = 256