syncthing.nix (1855B)
1 { 2 config, 3 pkgs, 4 lib, 5 ... 6 }: 7 8 let 9 cfg = config.services.local.syncthing; 10 in 11 { 12 options.services.local.syncthing = { 13 enable = lib.mkEnableOption "Syncthing file synchronization"; 14 15 user = lib.mkOption { 16 type = lib.types.str; 17 description = "User to run syncthing as"; 18 }; 19 20 dataDir = lib.mkOption { 21 type = lib.types.path; 22 description = "Data directory"; 23 example = "/home/silas/.syncthing"; 24 }; 25 26 configDir = lib.mkOption { 27 type = lib.types.path; 28 description = "Config directory"; 29 example = "/home/silas/.config/syncthing"; 30 }; 31 32 devices = lib.mkOption { 33 type = lib.types.attrsOf (lib.types.submodule { 34 options.id = lib.mkOption { 35 type = lib.types.str; 36 description = "Device ID"; 37 }; 38 }); 39 default = { }; 40 description = "Syncthing devices"; 41 }; 42 43 folders = lib.mkOption { 44 type = lib.types.attrsOf (lib.types.submodule { 45 options = { 46 id = lib.mkOption { 47 type = lib.types.str; 48 description = "Folder ID"; 49 }; 50 path = lib.mkOption { 51 type = lib.types.str; 52 description = "Local path"; 53 }; 54 devices = lib.mkOption { 55 type = lib.types.listOf lib.types.str; 56 default = [ ]; 57 description = "Device names to sync with"; 58 }; 59 }; 60 }); 61 default = { }; 62 description = "Syncthing folders"; 63 }; 64 }; 65 66 config = lib.mkIf cfg.enable { 67 services.syncthing = { 68 enable = true; 69 user = cfg.user; 70 dataDir = cfg.dataDir; 71 configDir = cfg.configDir; 72 settings = { 73 devices = cfg.devices; 74 folders = lib.mapAttrs (name: folder: { 75 inherit (folder) id path devices; 76 }) cfg.folders; 77 }; 78 }; 79 }; 80 }