Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ the application partition. The following variables are important:
* `[partition].nerves_fw_application_part0_target` - where the partition should
be mounted (e.g. `/root` or `/mnt/appdata`)

This default behavior is handled by `Nerves.Runtime.Init`. To override it with your
own you can configure a different module that is a GenServer with no options:

```elixir
config :nerves_runtime,
init_module: MyApp.FilesystemInit
```

Or you can disable it:

```elixir
config :nerves_runtime,
init_module: nil
```

## Nerves System and Firmware Metadata

All official Nerves systems maintain a list of key-value pairs for tracking
Expand Down Expand Up @@ -357,4 +372,3 @@ All original source code in this project is licensed under Apache-2.0.

Additionally, this project follows the [REUSE recommendations](https://reuse.software)
and labels so that licensing and copyright are clear at the file level.

16 changes: 12 additions & 4 deletions lib/nerves_runtime/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ defmodule Nerves.Runtime.Application do
load_services()

options = Application.get_all_env(:nerves_runtime)
children = [{FwupOps, options}, {KV, options} | target_children()]
init_module = Keyword.get(options, :init_module, Nerves.Runtime.Init)
children = [{FwupOps, options}, {KV, options} | target_children(init_module)]

opts = [strategy: :one_for_one, name: Nerves.Runtime.Supervisor]
Supervisor.start_link(children, opts)
end

if Mix.target() == :host do
defp target_children(), do: []
defp target_children(_), do: []
defp load_services(), do: :ok
else
defp target_children() do
defp target_children(nil) do
[
NervesLogging.KmsgTailer,
NervesLogging.SyslogTailer
]
end

defp target_children(init_module) do
[
NervesLogging.KmsgTailer,
NervesLogging.SyslogTailer,
Nerves.Runtime.Init
init_module
]
end

Expand Down
12 changes: 12 additions & 0 deletions lib/nerves_runtime/init.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ defmodule Nerves.Runtime.Init do
have also had stalls when formatting while waiting for enough entropy to
generate a UUID. Look into hardcoding UUIDs or enabling a hw random number
generator to increase entropy.

This GenServer is started by default. It can be prevented or overriden by
setting the config option `:init_module` to another module or `nil`. This
allows customizing application filesystem initialization:

```elixir
# Override with GenServer module
config :nerves_runtime, init_module: MyApp.FilesystemInit
# Disable
config :nerves_runtime, init_module: nil
```

"""
use GenServer

Expand Down