I’m not sure about your problem but mirage
works with functoria
which is able to describe how to connect a device and give the result to the start function. For example, the syslog
device provided by the mirage distribution needs several implementations and there representations into mirage
:
let syslog = impl @@ object
method ty = console @-> stackv4 @-> syslog
...
end
The object which is the description of a device can describe how to connect (or create) the syslog
representation:
method! connect _ modname = function
| [ console; stack; ] ->
Fmt.strf "%s.connect %s %s" modname console stack
| _ -> assert false
Where modname
is the name of the syslog
module and console
, and stack
are already connected values. Then, mirage
will generates a main.ml
which will call all connect
of all used implementations such as our stackv4
and pass them to others devices where it’s needed.
I use some terms which can misleading the comprehension of mirage
. When we talk about connect
or device
, it’s an abstraction where syslog
in our example is a device. A device should have a witness, a type t
and you must have something to create/connect
this type t
. Usually, MirageOS libraries provides a connect
function which is able to create the witness from some arguments.
In your case, we can imagine than Pgx
can be described with:
type pgx = Pgx
let pgx = Type Pgx
let pgx = impl @@ object
method ty = random @-> clock @-> stackv4 @-> pgx
...
And the connect
function should be:
method connect _ modname =
| [ random; clock; stack; ]
Fmt.strf "Pgx.open_connection %s %s %s" random clock stack"
Then, your config.ml
should describe how to create/connect your value such as:
let pgx = pgx default_random default_clock default_stack
let () =
register "my_unikernel"
[ my_unikernel $ pgx ]
In your unikernel.ml
you should be able to put a new functor such as:
module Make (Pgx : Pgx.S) = struct
let start my_pgx_connection = ...
end
mirage
will generate the main.ml
which will call your connect
function applied with right arguments. Then, it will call Unikernal.start
with what it created.
Of course, all of that is an example but a look into the mirage
distribution should help you about how to use functoria
. I think your problem is mostly about the lack of documentation on this specific part of mirage
. However, when you understand then how you can describe your device, the life is much more easier for any !