2
0
Fork 0

Update dhall-genode for Libc helper

This commit is contained in:
Emery Hemingway 2020-11-24 20:24:07 +01:00
parent 143c0c5551
commit 57a093afea
11 changed files with 136 additions and 222 deletions

View File

@ -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": {

View File

@ -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>
<dir name="dev">
<log name="stderr" label="stderr"/>
<log name="stdout" label="stdout"/>
<null/>
<pipe/>
<rtc/>
<terminal/>
<zero/>
</dir>
<dir name="usr"><dir name="bin"><symlink name="env" target="${params.coreutils}/bin/env"/></dir></dir>
<dir name="tmp"><ram/></dir>
<dir name="nix"><dir name="store"><fs label="nix/store" writeable="no"/></dir></dir>
</vfs>
<default-policy root="/" writeable="yes"/>
''
[ 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,27 +146,21 @@ in λ(params : { bash : Text, coreutils : Text, path : Text }) →
Child.flat
Child.Attributes::{
, binary = "bash"
, config = Genode.Init.Config::{
, content =
[ Prelude.XML.text
''
<libc stdin="/dev/terminal" stdout="/dev/terminal" stderr="/dev/terminal" pipe="/dev/pipe" rtc="/dev/rtc"/>
<vfs> <fs/> </vfs>
<env key="TERM" value="screen"/>
<env key="PATH" value="${params.path}" />
<env key="PS1" value="system:$PWD> " />
''
]
# Prelude.List.map
Text
XML.Type
( λ(x : Text) →
XML.leaf
{ name = "arg"
, attributes = toMap { value = x }
, 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"
}
)
[ "bash" ]
, args = [ "bash" ]
}
, exitPropagate = True
, resources = Resources::{

View File

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

View File

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

View File

@ -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 }
, 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
}
)
[ "bash", "-c", params.execStart ]
}
with attributes = toMap { ld_verbose = "yes" }
, routes =
Prelude.List.map
Text

View File

@ -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}
}
'';

View File

@ -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";
rev = "01b99d53f597cac40c6b4761d6dd750fc89f63da";
sha256 = "1df4plhr72rhva9rdphlyq244j0rmldkpa7bj6mjzwarisdxw9vv";
};
in src + "/package.dhall";
dependencies = [ dhallPackages.Prelude ];
source = true;
}

View File

@ -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"
, 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"
, arg "bash"
, arg "/script.sh"
]
}
, args = [ "bash", "/script.sh" ]
}
)
with attributes = toMap { ld_verbose = "true" }
}
}
}

View File

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

View File

@ -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,24 +80,13 @@ in λ(params : { bash : Text, coreutils : Text, script : Text }) →
Child.flat
Child.Attributes::{
, binary = "bash"
, config = Genode.Init.Config::{
, content =
[ Prelude.XML.text
''
<libc stdin="/dev/null" stdout="/dev/stdout" stderr="/dev/stderr" pipe="/dev/pipe" rtc="/dev/rtc"/>
<vfs> <fs/> </vfs>
''
]
# 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::{