Skip to content

Commit

Permalink
GITBOOK-7: Project config files
Browse files Browse the repository at this point in the history
  • Loading branch information
amclain authored and gitbook-bot committed Aug 18, 2024
1 parent 24b990d commit ed1a638
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions pages/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Table of contents

* [Introduction](README.md)
* [Config files](config-files.md)
* [Development workstation](<README (1).md>)
* [Nerves systems for commercial products](nerves\_systems\_for\_commercial\_development.md)
* [Serial cable](serial\_cable.md)
Expand Down
26 changes: 26 additions & 0 deletions pages/config-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Config files

An Elixir project configuration resides in the `<project>/config` directory. When creating a new Nerves project, the official Nerves project generator creates configuration files for the host (development computer) and target (hardware). While this makes things simple for people learning Nerves, we prefer a more configurable, granular approach for commercial projects.

For professional firmware projects, there are two axes we take into consideration: environment, and target. Environment (dev, prod, test) deals with the context in which the firmware is running. For example, in dev we may want to see debug logs over the serial console, whereas in prod where we don't have access to the serial port, we only want to write errors to disk to reduce flash wear. Target, on the other hand, is the hardware platform that the firmware is running on. This could be a development kit, production PCB, or even the computer used to develop the code or run CI. Since different targets have different capabilities, we need to turn various functionality on/off, select different drivers, or inject mocks depending on the target the firmware is running on.

To do this, we add a directory for environment configuration files, and a directory for target configuration files. The top level config directory includes `config.exs` which applies to all environments and targets, `target.exs` which applies to all targets, and `runtime.exs` which is able to access environment variables at runtime instead of compile time. The file structure looks like this:

```
config
├── env
│   ├── dev.exs
│   ├── prod.exs
│   └── test.exs
├── target
│   ├── host.exs
│   └── imx8.exs
├── config.exs
├── runtime.exs
└── target.exs
```

## Mix Task

It can be a fair amount of work to set up these config files by hand, so the `mix red.nerves.new` task is available from the [Redwire Tasks](https://github.com/redwirelabs/redwire\_tasks) package.

0 comments on commit ed1a638

Please sign in to comment.