🔄 Syncthing Configuration#
This snippet provides centralized Syncthing device and folder configurations for all hosts in the flake.
📂 Structure#
default.nix- Main module that imports device and folder configurationsdevices.nix- Defines all Syncthing devices with their IDsfolders.nix- Defines shared folders and which devices sync them
🛠️ Adding New Devices#
When provisioning a new host that should participate in Syncthing synchronization:
-
Generate Syncthing certificates and device ID:
syncthing -generate="$HOSTNAME" -
Extract device ID:
- Locate the device ID in the generated
config.xml - The device ID is a long alphanumeric string in the format:
XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX
- Locate the device ID in the generated
-
Add device to configuration:
- Add the new device to the
devices.nixfile with its hostname and device ID - Follow the existing format:
"hostname" = {id = "DEVICE-ID-HERE";};
- Add the new device to the
-
Configure folder access:
- Update
folders.nixto include the new device in the appropriate folder device lists - Add the hostname to the
devicesarray for each folder the device should sync
- Update
-
Encrypt certificates:
- Encrypt the generated
cert.pemandkey.pemusingagenix - Store them in the secrets repository at
github.com/alyraffauf/secrets - Configure the host to use these encrypted certificates in its Syncthing service configuration
- Encrypt the generated
📋 Usage by Hosts#
Hosts can reference the centralized device and folder configurations via either NixOS or home-manager.
{
services.syncthing = {
enable = true;
settings = {
devices = config.mySnippets.syncthing.devices;
folders = config.mySnippets.syncthing.folders;
};
};
}
This ensures all devices have a consistent view of the Syncthing network topology regardless of the configuration method used.