From 87339e362043d038c7be298890766db04643f5f0 Mon Sep 17 00:00:00 2001 From: Lars Wikman Date: Thu, 18 Sep 2025 08:49:16 +0200 Subject: [PATCH 1/2] Allow overriding or disabling Nerves.Runtime.Init --- lib/nerves_runtime/application.ex | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/nerves_runtime/application.ex b/lib/nerves_runtime/application.ex index c676029..264457a 100644 --- a/lib/nerves_runtime/application.ex +++ b/lib/nerves_runtime/application.ex @@ -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 From ff6f74363b51d64fc90dbd0242cdeab0915a5dd8 Mon Sep 17 00:00:00 2001 From: Lars Wikman Date: Thu, 18 Sep 2025 08:49:43 +0200 Subject: [PATCH 2/2] Add documentation for Nerves.Runtime.Init override configuration --- README.md | 16 +++++++++++++++- lib/nerves_runtime/init.ex | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7063f49..574bbda 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. - diff --git a/lib/nerves_runtime/init.ex b/lib/nerves_runtime/init.ex index f2c509a..d9218df 100644 --- a/lib/nerves_runtime/init.ex +++ b/lib/nerves_runtime/init.ex @@ -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