Created
March 15, 2020 09:21
-
-
Save samoht/6c96e2a73c45c90e3fda3a23e249a582 to your computer and use it in GitHub Desktop.
MirageOS + dune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Mirage | |
let disk = generic_kv_ro "t" | |
let main = foreign "Unikernel.Main" (kv_ro @-> job) | |
let () = register ~reporter:Mirage.no_reporter "kv_ro" [ main $ disk ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; should be compiled first | |
(executable | |
(name config) | |
(modules config) | |
(libraries mirage)) | |
; mirage configure | |
(rule | |
(targets key_gen.ml main.ml Makefile .mirage.config) ; the list of targets is dynamic (1) | |
(action | |
(run ./config.exe configure))) | |
; mirage build | |
(rule | |
(targets static.ml static.mli) ; the list of targets is dynamic (2) | |
(deps | |
.mirage.config | |
(source_tree t)) ; the list of deps depends on what is in config.ml but (source_tree .) could work too | |
(action | |
(run ./config.exe build))) | |
; mirage run | |
(test | |
(name main) | |
(package mirage) | |
(modules unikernel key_gen main static oS) ; the list of modules is dynamic ((1)+(2)) | |
(libraries mirage mirage-kv lwt.unix mirage-kv-mem mirage-bootvar-unix)) ; the list of libraries is dynamic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contents of extremely secret vital storage confirmed! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Lwt.Infix | |
let log fmt = Fmt.pr (fmt ^^ "\n%!") | |
module Main (KV : Mirage_kv.RO) = struct | |
let start kv = | |
let our_secret = "foo\n" in | |
KV.get kv (Mirage_kv.Key.v "secret") >|= function | |
| Error e -> | |
log "Could not compare the secret against a known constant: %a" | |
KV.pp_error e | |
| Ok stored_secret -> ( | |
match String.compare our_secret stored_secret with | |
| 0 -> log "Contents of extremely secret vital storage confirmed!" | |
| _ -> log "The secret provided does not match!" ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment