{ config, pkgs, lib, mkDomain, ... }:

# don't mount if local VM
lib.mkIf (!config.virtualisation.isVmVariant)

{
  # Resilio Sync
  # Automatically sync files via secure, distributed technology

  services.resilio = {
    #enable = true;
    #downloadLimit = 0;
    #uploadLimit = 0;
    #directoryRoot = "/media" # Default directory to add folders in the web UI.
    #storagePath = "/var/lib/resilio-sync/"; # Where BitTorrent Sync will store it's database files
    httpLogin = "";
    httpPass = "";
    deviceName = "${config.networking.hostName}";
    #apiKey = ; # API key, which enables the developer API.
    #httpListenPort = 9000;
    #httpListenAddr = "[::1]";
    enableWebUI = false; # default is false
  };
  services.nginx.virtualHosts.${mkDomain "resilio"} = let
      cfg = config.services.resilio;
  in lib.mkIf (cfg.enable && cfg.enableWebUI) {
    forceSSL = true; # addSSL = true;
    enableACME = true; #useACMEHost = acmeDomain;
    locations."/" = {
      proxyPass = "http://127.0.0.1:${cfg.httpListenPort}";
      proxyWebsockets = true;
    };
  };

}