From 696dffcbfb4899e1a83fb4314ae0ec4d06c65d07 Mon Sep 17 00:00:00 2001 From: hektor Date: Thu, 23 Jul 2026 19:17:29 +0200 Subject: [PATCH] feat(syncthing): set up LAN-only sync for 'readings' --- hosts/andromache/default.nix | 11 +++++++- hosts/astyanax/default.nix | 10 +++++++ modules/syncthing/default.nix | 50 ++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/hosts/andromache/default.nix b/hosts/andromache/default.nix index 36275e4..a7c6b2c 100644 --- a/hosts/andromache/default.nix +++ b/hosts/andromache/default.nix @@ -67,7 +67,16 @@ in }; ssh.enable = true; storage.enable = true; - syncthing.enable = true; + syncthing = { + enable = true; + folders.readings = { + path = "/home/${config.host.username}/doc/readings"; + devices = [ + "astyanax" + "boox" + ]; + }; + }; tailscale.enable = true; taskwarrior.enable = true; wol = { diff --git a/hosts/astyanax/default.nix b/hosts/astyanax/default.nix index 31a46dd..3f8121a 100644 --- a/hosts/astyanax/default.nix +++ b/hosts/astyanax/default.nix @@ -49,6 +49,16 @@ in secrets.enable = true; ssh.enable = true; storage.enable = true; + syncthing = { + enable = true; + folders.readings = { + path = "/home/${config.host.username}/doc/readings"; + devices = [ + "andromache" + "boox" + ]; + }; + }; taskwarrior.enable = true; secrets.nixSigningKey.enable = true; diff --git a/modules/syncthing/default.nix b/modules/syncthing/default.nix index 248c3e2..98d146e 100644 --- a/modules/syncthing/default.nix +++ b/modules/syncthing/default.nix @@ -3,9 +3,42 @@ let cfg = config.syncthing; inherit (config.host) username; + + deviceRegistry = import ./devices.nix; + deviceName = lib.types.enum (builtins.attrNames deviceRegistry); + referencedDevices = lib.unique ( + lib.concatMap (folder: folder.devices) (lib.attrValues cfg.folders) + ); in { - options.syncthing.enable = lib.mkEnableOption "syncthing"; + options.syncthing = { + enable = lib.mkEnableOption "syncthing"; + folders = lib.mkOption { + default = { }; + type = lib.types.attrsOf ( + lib.types.submodule { + options = { + path = lib.mkOption { + type = lib.types.str; + }; + type = lib.mkOption { + type = lib.types.enum [ + "sendreceive" + "sendonly" + "receiveonly" + "receiveencrypted" + ]; + default = "sendreceive"; + }; + devices = lib.mkOption { + type = lib.types.listOf deviceName; + default = [ ]; + }; + }; + } + ); + }; + }; config = lib.mkIf cfg.enable { users.groups.${username} = { }; @@ -17,6 +50,21 @@ in group = username; configDir = "/home/${username}/.local/state/syncthing"; openDefaultPorts = true; + settings = { + devices = lib.getAttrs referencedDevices deviceRegistry; + folders = lib.mapAttrs (_: folder: { + inherit (folder) + path + type + devices + ; + }) cfg.folders; + options = { + globalAnnounceEnabled = false; + localAnnounceEnabled = true; + relaysEnabled = false; + }; + }; }; }; }