1# 🔄 Syncthing Configuration
2
3This snippet provides centralized Syncthing device and folder configurations for all hosts in the flake.
4
5---
6
7## 📂 Structure
8
9- `default.nix` - Main module that imports device and folder configurations
10- `devices.nix` - Defines all Syncthing devices with their IDs
11- `folders.nix` - Defines shared folders and which devices sync them
12
13---
14
15## 🛠️ Adding New Devices
16
17When provisioning a new host that should participate in Syncthing synchronization:
18
191. **Generate Syncthing certificates and device ID**:
20
21 ```bash
22 syncthing -generate="$HOSTNAME"
23 ```
24
252. **Extract device ID**:
26 - Locate the device ID in the generated `config.xml`
27 - The device ID is a long alphanumeric string in the format: `XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX`
28
293. **Add device to configuration**:
30 - Add the new device to the `devices.nix` file with its hostname and device ID
31 - Follow the existing format: `"hostname" = {id = "DEVICE-ID-HERE";};`
32
334. **Configure folder access**:
34 - Update `folders.nix` to include the new device in the appropriate folder device lists
35 - Add the hostname to the `devices` array for each folder the device should sync
36
375. **Encrypt certificates**:
38 - Encrypt the generated `cert.pem` and `key.pem` using `agenix`
39 - Store them in the secrets repository at `github.com/alyraffauf/secrets`
40 - Configure the host to use these encrypted certificates in its Syncthing service configuration
41
42---
43
44## 📋 Usage by Hosts
45
46Hosts can reference the centralized device and folder configurations via either **NixOS** or **home-manager**.
47
48```nix
49{
50 services.syncthing = {
51 enable = true;
52
53 settings = {
54 devices = config.mySnippets.syncthing.devices;
55 folders = config.mySnippets.syncthing.folders;
56 };
57 };
58}
59```
60
61This ensures all devices have a consistent view of the Syncthing network topology regardless of the configuration method used.