summaryrefslogtreecommitdiff
path: root/Omni/Cloud/Syncthing.nix
blob: 7c13e6c847131be667c698add005a3ee950cf8fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{config, ...}: let
  ports = import ./Ports.nix;
  rootDomain = config.networking.domain;
in {
  services.syncthing = {
    enable = true;
    guiAddress = "0.0.0.0:${toString ports.syncthing-gui}";
    openDefaultPorts = true;
    systemService = true;
    configDir = "/var/lib/syncthing/.config/syncthing";

    # Default settings for new users
    settings = {
      options = {
        relaysEnabled = true;
        urAccepted = -1; # Usage reporting: -1 = not decided, 0 = no, 1 = yes
      };
    };
  };

  # Configure nginx as a reverse proxy for the Syncthing GUI
  services.nginx.virtualHosts."syncthing.${rootDomain}" = {
    forceSSL = true;
    enableACME = true;
    locations."/" = {
      proxyPass = "http://localhost:${toString ports.syncthing-gui}/";
      proxyWebsockets = true;
      extraConfig = ''
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 600s;
        proxy_send_timeout 600s;
      '';
    };
  };
}