2
0
Fork 0
Browse Source

Update dhall-genode for Libc helper

hybda
Emery Hemingway 2 years ago
parent
commit
57a093afea
  1. 6
      flake.lock
  2. 94
      nixos-modules/dhall/console.dhall
  3. 51
      nixos-modules/dhall/vbox-guest.dhall
  4. 2
      nixos-modules/store-wrapper.dhall
  5. 54
      nixos-modules/systemd-runner.dhall
  6. 7
      nixos-modules/systemd.nix
  7. 18
      packages/dhall/genode.nix
  8. 54
      tests/bash.dhall
  9. 37
      tests/hello.dhall
  10. 2
      tests/hello.nix
  11. 33
      tests/posix.dhall

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

94
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>
<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,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
''
<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 }
}
)
[ "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

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

2
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

54
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

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

18
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;
}

54
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" }
}
}
}

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

2
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 = ''

33
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
''
<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::{
, caps = 256

Loading…
Cancel
Save