Add optional durable runtime NTP server configuration - #225
Open
elielgordondensity wants to merge 1 commit into
Open
elielgordondensity wants to merge 1 commit into
elielgordondensity wants to merge 1 commit into
Conversation
elielgordondensity
force-pushed
the
durable-ntp-servers
branch
from
May 29, 2026 22:27
ad92f03 to
447553e
Compare
elielgordondensity
marked this pull request as draft
May 29, 2026 22:27
elielgordondensity
force-pushed
the
durable-ntp-servers
branch
from
May 29, 2026 22:34
447553e to
9bebde3
Compare
Introduce an optional `:servers_file` config key that durably persists the
runtime NTP server list. When configured, `NervesTime.set_ntp_servers/1`
writes the list to the file and it is reloaded on the next boot, taking
precedence over `:servers`. This helps devices that receive NTP servers
dynamically (provisioning, DHCP/ConnMan metadata, user configuration) keep
that choice across reboots.
* On startup, load `:servers_file` when configured and present, falling
back to `:servers` otherwise.
* `set_ntp_servers/1` persists the server list when `:servers_file` is set
and returns `{:error, reason}` if persistence fails.
* An empty list is persisted as an explicit "NTP disabled" marker so that
choice also survives a reboot.
Behavior is unchanged unless `:servers_file` is configured.
elielgordondensity
force-pushed
the
durable-ntp-servers
branch
from
May 29, 2026 22:34
9bebde3 to
8c075e7
Compare
elielgordondensity
marked this pull request as ready for review
May 29, 2026 22:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
:servers_fileconfig key for durably persisting the runtime NTP server list.Today,
NervesTime.set_ntp_servers/1updates the runningntpdconfiguration, but the new server list only lives in GenServer state. After a reboot,NervesTimefalls back toconfig :nerves_time, :servers. This makes it hard to support devices that receive their NTP servers dynamically (provisioning, legacy network migration, DHCP/ConnMan metadata, or user configuration).When
:servers_fileis configured, the list set at runtime is written to that file and reloaded on the next boot, taking precedence over:servers:Behavior
:servers_filewhen configured and present.:serverswhen no persisted file exists.set_ntp_servers/1persists the server list when:servers_fileis configured.[](NTP off) rather than falling back to:servers.set_ntp_servers/1now returns:ok | {:error, term()}) and logged. The running configuration is updated regardless.Behavior is unchanged unless
:servers_fileis configured.Implementation
NervesTime.ServerFilemodule encapsulates load/save. File format is one server per line; blank lines and#comments are ignored. Intermediate directories are created on save.NervesTime.Ntpd.init/1loads fromServerFilefirst, falling back to:servers(then the built-in pool default).set_ntp_servers/1persists before restartingntpdand returns the persistence result.Tests
test/server_file_test.exs— unit tests for load/save round-trip, directory creation, empty-list ("NTP disabled") semantics, comment/blank-line parsing, no-op when unconfigured, and write-failure error + log.test/nerves_time_test.exs— integration tests for startup precedence, fallback to:servers, persist-and-reload across an application restart, and disable-via-empty-list across a restart.All tests pass;
mix format,mix credo --strict, andmix dialyzerare clean.