added manual secrets

This commit is contained in:
ari committed 2026-06-26 16:07:47 -04:00
1 parent 672657c111
commit d9cacefa0f
34 files changed
+1428 -10

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
# modules/openwrt/
Config generator + deploy tooling for the homelab's **OpenWrt** router. This is *not* a NixOS
module — it's a Nix function that builds a Rust generator and wraps it in an
`openwrt-deploy` shell script. OpenWrt is managed out-of-band (the router isn't a NixOS host),
so this provides a declarative, reviewable way to push `dnsmasq.conf` and `/etc/ethers`.
## Structure
```
openwrt/
├── default.nix # Builds the Rust generator + the openwrt-deploy script
└── generator/ # Rust crate (openwrt-gen) that turns a JSON config into OpenWrt files
```
## How it works
1. The router config lives as an **agenix secret** (e.g. `secrets/glmain.json.age`).
2. `openwrt-deploy` reads the decrypted JSON from stdin, runs `openwrt-gen dnsmasq` and
`openwrt-gen ethers` to render the two target files.
3. It SSHes to the router, shows a **colorized diff** against the current files, and prompts
for confirmation before writing.
4. `dnsmasq.conf` is validated with `dnsmasq --test` on the router and **automatically
reverted** if the new config is invalid.
```
age -d secrets/glmain.json.age | openwrt-deploy
```
`router.ip` / `router.user` are taken from the `config` passed into `default.nix`.
## Conventions
- The router config is a **secret** — decrypt it on the fly; never commit the plaintext JSON.
- Deploys are interactive and reviewed by a human; the script intentionally requires
confirmation and self-reverts on a bad dnsmasq config.
- `generator/target/` is gitignored Rust build output — ignore it.
+44
View File
@@ -0,0 +1,44 @@
# modules/openwrt/generator/
`openwrt-gen` — a small Rust CLI that converts a single JSON network description into OpenWrt
config files. Built by `../default.nix` with `rustPlatform.buildRustPackage` and invoked by
the `openwrt-deploy` script.
## Layout
```
generator/
├── Cargo.toml # crate metadata; deps: serde, serde_json
├── Cargo.lock # pinned for the Nix build (cargoLock.lockFile)
├── src/
│ ├── main.rs # CLI entry: reads JSON from stdin, dispatches on argv[1]
│ ├── config.rs # serde Deserialize structs for the input JSON (+ unit tests)
│ ├── network.rs # process_network — expands per-network device lists
│ └── generators/
│ ├── mod.rs # re-exports dnsmasq + ethers
│ ├── dnsmasq.rs # renders dnsmasq.conf (server= + address= lines)
│ └── ethers.rs # renders /etc/ethers (MAC → name/IP)
└── target/ # gitignored Cargo build output — ignore it
```
## Usage
```
openwrt-gen dnsmasq < config.json # prints dnsmasq.conf
openwrt-gen ethers < config.json # prints /etc/ethers
```
## Input shape (`config.rs`)
- `generalMappings`: `[{ ip, domains[] }]` — shared domain→IP records.
- `networks`: `{ <network>: [ { mac, name, id?, domains?, justMac? } ] }` — per-network hosts.
- `dnsResolvers`: `[{ ip, port?, name? }]` — upstream `server=` entries for dnsmasq.
## Conventions
- This crate has **no I/O of its own** beyond stdin/stdout — config decryption and SSH
delivery are the deploy script's job. Keep it a pure JSON → text transformer.
- `config.rs` carries unit tests; run `cargo test` here when changing the parser. Building
the Nix package is fine (it doesn't touch a live system), but is not required — the user
validates deploys via `openwrt-deploy`.
- Keep `Cargo.lock` committed and in sync (the Nix build pins to it).