Ok I gave it a spin with a module wrapper like so:
defmodule PeerNode do
def start(name) do
{:ok, node} =
:peer.start_link(%{
host: :localhost,
name: name,
args: peer_args()
})
IO.puts("DONE Starting peer node!")
add_code_paths(node)
ensure_applications_started(node)
end
def peer_args do
Enum.join(
[
"-loader inet -hosts 127.0.0.1",
"-setcookie #{:erlang.get_cookie()}",
# "-env MIX_BUILD_ROOT /tmp/gviz_build"
],
" "
)
|> to_charlist()
end
defp rpc(node, module, function, args) do
:rpc.block_call(node, module, function, args)
end
defp add_code_paths(node) do
rpc(node, :code, :add_paths, [:code.get_path()])
end
@apps_to_start [
# :iex,
:logger,
# :file_system,
# :jason,
:erlexec,
:runtime_tools,
# :inets,
:stdlib,
:crypto,
# :hex,
:elixir,
# :public_key,
# :gviz,
# :mix,
# :gettext,
:kernel,
:ssl,
:compiler
# :asn1,
]
defp ensure_applications_started(node) do
rpc(node, Application, :ensure_all_started, [:mix])
rpc(node, Mix, :env, [Mix.env()])
# for {app_name, _, _} <- Application.loaded_applications() do
# rpc(node, Application, :ensure_all_started, [app_name])
# end
for app_name <- @apps_to_start do
IO.inspect(app_name, label: "starting app_name")
rpc(node, Application, :ensure_all_started, [app_name])
|> IO.inspect(label: "started #{inspect(app_name)}")
end
end
end
Then I ran:
PeerNode.start("first_peer_node")
Node.list(:hidden)
But its complaining about :peer args:
** (ErlangError) Erlang error: {:invalid_arg, 45}
(stdlib 5.0.2) peer.erl:563: :peer.“-verify_args/1-lc$^0/1-0-”/1
(stdlib 5.0.2) peer.erl:563: :peer.verify_args/1
(stdlib 5.0.2) peer.erl:626: :peer.start_it/2
For debugging I tried both with no luck:
:peer.start_link(%{
host: :localhost,
name: name,
args: ["-loader inet -hosts 127.0.0.1 -setcookie #{:erlang.get_cookie()}"]
})
:peer.start_link(%{
host: :localhost,
name: name,
args: ~c"-loader inet -hosts 127.0.0.1 -setcookie hardcoded_cookie"
})