|
| 1 | +# SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | +# Cloud Sync Tuner - Nickel Configuration Schema |
| 3 | +# Validates and generates TOML configuration |
| 4 | + |
| 5 | +let CacheMode = [| 'Off, 'Minimal, 'Writes, 'Full |] in |
| 6 | + |
| 7 | +let ConflictStrategy = [| 'None, 'Newer, 'Older, 'Larger, 'Smaller, 'Path1, 'Path2 |] in |
| 8 | + |
| 9 | +let RateLimiting = { |
| 10 | + tps_limit | Number | default = 4 |
| 11 | + | doc "Transactions per second (1-100)", |
| 12 | + tps_burst | Number | default = 1 |
| 13 | + | doc "Burst allowance (1-10)", |
| 14 | + chunk_size_mb | Number | default = 32 |
| 15 | + | doc "Read chunk size in MB (1-512)", |
| 16 | + cache_age_hours | Number | default = 72 |
| 17 | + | doc "Cache entry max age in hours (1-168)", |
| 18 | + dir_cache_min | Number | default = 5 |
| 19 | + | doc "Directory cache time in minutes (1-60)", |
| 20 | +} in |
| 21 | + |
| 22 | +let SmartSync = { |
| 23 | + cache_max_size_gb | Number | default = 10 |
| 24 | + | doc "Maximum cache size in GB (0 = unlimited)", |
| 25 | + min_free_space_gb | Number | default = 5 |
| 26 | + | doc "Minimum free disk space in GB", |
| 27 | + write_back_sec | Number | default = 5 |
| 28 | + | doc "Write-back delay in seconds (1-60)", |
| 29 | + poll_interval_min | Number | default = 1 |
| 30 | + | doc "Remote change poll interval in minutes (1-60)", |
| 31 | + buffer_size_mb | Number | default = 16 |
| 32 | + | doc "Buffer size in MB (1-128)", |
| 33 | + transfers | Number | default = 4 |
| 34 | + | doc "Concurrent transfers (1-32)", |
| 35 | + checkers | Number | default = 8 |
| 36 | + | doc "Concurrent checkers (1-64)", |
| 37 | +} in |
| 38 | + |
| 39 | +let ScheduleEntry = { |
| 40 | + start | Number |
| 41 | + | doc "Start hour (0-23)", |
| 42 | + end | Number |
| 43 | + | doc "End hour (0-23)", |
| 44 | + limit_kbps | Number |
| 45 | + | doc "Bandwidth limit in KB/s (0 = unlimited)", |
| 46 | +} in |
| 47 | + |
| 48 | +let Bandwidth = { |
| 49 | + enabled | Bool | default = false |
| 50 | + | doc "Enable bandwidth scheduling", |
| 51 | + schedule | Array ScheduleEntry | default = [] |
| 52 | + | doc "Schedule entries", |
| 53 | +} in |
| 54 | + |
| 55 | +let Service = { |
| 56 | + name | String |
| 57 | + | doc "Display name", |
| 58 | + remote | String |
| 59 | + | doc "rclone remote name (e.g., 'dropbox:')", |
| 60 | + mount_point | String |
| 61 | + | doc "Local mount path", |
| 62 | + service_name | String |
| 63 | + | doc "systemd service name", |
| 64 | + enabled | Bool | default = true |
| 65 | + | doc "Whether service is enabled", |
| 66 | + rc_port | Number | optional |
| 67 | + | doc "rclone RC port for this service", |
| 68 | + |
| 69 | + # Service-specific overrides |
| 70 | + tps_limit | Number | optional, |
| 71 | + tps_burst | Number | optional, |
| 72 | + chunk_size_mb | Number | optional, |
| 73 | +} in |
| 74 | + |
| 75 | +let PinnedFolder = { |
| 76 | + service | String |
| 77 | + | doc "Service name (dropbox, gdrive, onedrive)", |
| 78 | + remote_path | String |
| 79 | + | doc "Path on remote (e.g., 'Documents/Important')", |
| 80 | + local_path | String |
| 81 | + | doc "Local sync path (e.g., '~/Offline/Dropbox/Documents')", |
| 82 | + enabled | Bool | default = true |
| 83 | + | doc "Whether folder is pinned", |
| 84 | +} in |
| 85 | + |
| 86 | +let Config = { |
| 87 | + general | { |
| 88 | + cache_mode | CacheMode | default = 'Writes |
| 89 | + | doc "VFS cache mode", |
| 90 | + desktop_notify | Bool | default = true |
| 91 | + | doc "Desktop notifications", |
| 92 | + tray_icon | Bool | default = true |
| 93 | + | doc "System tray icon", |
| 94 | + offline_dir | String | default = "~/Offline" |
| 95 | + | doc "Offline sync directory", |
| 96 | + }, |
| 97 | + |
| 98 | + rate_limiting | RateLimiting | default = {}, |
| 99 | + smart_sync | SmartSync | default = {}, |
| 100 | + |
| 101 | + conflict_resolution | { |
| 102 | + strategy | ConflictStrategy | default = 'Newer |
| 103 | + | doc "Conflict resolution strategy", |
| 104 | + } | default = {}, |
| 105 | + |
| 106 | + bandwidth | Bandwidth | default = {}, |
| 107 | + |
| 108 | + services | Array Service | default = [], |
| 109 | + pinned_folders | Array PinnedFolder | default = [], |
| 110 | +} in |
| 111 | + |
| 112 | +# Presets |
| 113 | +let presets = { |
| 114 | + dropbox = { |
| 115 | + general.cache_mode = 'Writes, |
| 116 | + rate_limiting = { |
| 117 | + tps_limit = 4, |
| 118 | + tps_burst = 1, |
| 119 | + chunk_size_mb = 32, |
| 120 | + }, |
| 121 | + }, |
| 122 | + |
| 123 | + gdrive = { |
| 124 | + general.cache_mode = 'Writes, |
| 125 | + rate_limiting = { |
| 126 | + tps_limit = 8, |
| 127 | + tps_burst = 2, |
| 128 | + chunk_size_mb = 64, |
| 129 | + }, |
| 130 | + }, |
| 131 | + |
| 132 | + onedrive = { |
| 133 | + general.cache_mode = 'Writes, |
| 134 | + rate_limiting = { |
| 135 | + tps_limit = 6, |
| 136 | + tps_burst = 2, |
| 137 | + chunk_size_mb = 32, |
| 138 | + }, |
| 139 | + }, |
| 140 | + |
| 141 | + minimal = { |
| 142 | + general.cache_mode = 'Writes, |
| 143 | + smart_sync = { |
| 144 | + cache_max_size_gb = 2, |
| 145 | + transfers = 2, |
| 146 | + checkers = 4, |
| 147 | + buffer_size_mb = 8, |
| 148 | + }, |
| 149 | + }, |
| 150 | + |
| 151 | + performance = { |
| 152 | + general.cache_mode = 'Full, |
| 153 | + smart_sync = { |
| 154 | + cache_max_size_gb = 50, |
| 155 | + transfers = 8, |
| 156 | + checkers = 16, |
| 157 | + buffer_size_mb = 64, |
| 158 | + }, |
| 159 | + }, |
| 160 | +} in |
| 161 | + |
| 162 | +# Export schema and presets |
| 163 | +{ |
| 164 | + Config, |
| 165 | + presets, |
| 166 | + |
| 167 | + # Validation function |
| 168 | + validate = fun config => |
| 169 | + let valid_tps = config.rate_limiting.tps_limit >= 1 |
| 170 | + && config.rate_limiting.tps_limit <= 100 in |
| 171 | + let valid_burst = config.rate_limiting.tps_burst >= 1 |
| 172 | + && config.rate_limiting.tps_burst <= 10 in |
| 173 | + let valid_chunk = config.rate_limiting.chunk_size_mb >= 1 |
| 174 | + && config.rate_limiting.chunk_size_mb <= 512 in |
| 175 | + valid_tps && valid_burst && valid_chunk, |
| 176 | + |
| 177 | + # Generate TOML output |
| 178 | + to_toml = fun config => std.serialize 'Toml config, |
| 179 | +} |
0 commit comments