nerves-project / nerves_bootstrap

Nerves mix integration bootstrap and new project generator
http://nerves-project.org
Apache License 2.0
40 stars 18 forks source link

Nerves vm.args.eex prevents proper application of cookie through config or env variables #182

Open LostKobrakai opened 3 years ago

LostKobrakai commented 3 years ago

Environment

Nerves environment MIX_TARGET: host MIX_ENV: dev

NERVES_SYSTEM is unset NERVES_TOOLCHAIN is unset |nerves_bootstrap| Environment Variable List target: host toolchain: unset system: unset app: …/05_elixir/edith

|nerves_bootstrap| Loadpaths End

Current behavior

Running a shoehorn release (on host) results in the cookie being read from $HOME/.erlang.cookie instead of the one configured through the normal mix release means (config or env variable)

❯❯❯❯ RELEASE_BOOT_SCRIPT=shoehorn RELEASE_COOKIE=shoehorn _build/dev/rel/shoehorn/bin/shoehorn start_iex
heart_beat_kill_pid = 3244
heart_beat_timeout = 30
2021-04-26 15:15:47.218544 Multiple -mode given to erl, using the first, ~p
        ["embedded"]
Erlang/OTP 23 [erts-11.1.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
=WARNING REPORT==== 26-Apr-2021::15:15:47.218544 ===
Multiple -mode given to erl, using the first, ["embedded"]
[Shoehorn] Init app :nerves_runtime undefined. Skipping
[Shoehorn] Init app :vintage_net undefined. Skipping
:JKIIVXBQQLKXJEANCEZM
…

Removing the -setcookie in vm.args.eex resolves the issue and also doesn't seem to break releases run on targets. Mix releases are always started with an cookie set on the cli. A random cookie is generated when building the release unless a specific one is explicitly set.

Expected behavior

The cookie configured in mix.exs or via the env variables is correctly applied.

fhunleth commented 3 years ago

Nerves only uses Mix releases to assist in creating firmware. Mix releases also creates shell scripts and batch scripts which aren't useful for Nerves. It looks like the shell scripts don't work. I can think of a few solutions:

  1. Have the Nerves tooling erase the shell scripts as a post-release step to avoid any confusion that they might be used. @mobileoverlord and I have discussed coding up our own release generator to avoid using Mix releases. This seems like a step in this direction, even though neither of us is super-excited about coding it up.

  2. Don't support hardcoding the cookie in the firmware at all. The effect would be to erase the line in vm.args as you suggest and then delete the line in the mix.exs that sets it. I'm a big fan of not hardcoding cookies in firmware, but it might cause confusion since mix release docs say that cookies can be set in the mix.exs. The Nerves core team discussed this a year or so ago. Perhaps we need to revisit.

I assume that the reason that you're making a mix release in a Nerves project is to debug something with Shoehorn. Otherwise, I'd think that you'd just run iex -S mix or mix test to run on the host. Is that right?

LostKobrakai commented 3 years ago

I assume that the reason that you're making a mix release in a Nerves project is to debug something with Shoehorn.

That's kinda the case. It's for creating tests for whatever the shoehorn handler is used for.

fhunleth commented 3 years ago

That is a very noble effort that I'd like to support. I will think more about this. I'm glad that the workaround for you is easy (i.e., delete the -setcookie line), though.