summaryrefslogtreecommitdiff
path: root/hostnix/elmo/syncthing.nix
blob: 1f3518fc77e3b0b4777896db99df0906c766a45e (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{ lib, ... }:

# TODO iCloud bridge

let
  staggeredVersioning = {
    type = "staggered";
    params = {
      cleanInterval = "3600";
      maxAge = "31536000";
    };
  };
in
{
  # Syncthing generally ignores umask and makes it hard to set permission bits
  # by default, so use ACLs to grant access. Also nginx is particularly
  # difficult to grant granular access with classic permissions.
  systemd.tmpfiles.rules = let
    acls = builtins.concatStringsSep "," [
      "user:joe:rwX"
      "default:user:joe:rwX"
      "user:nginx:rX"
      "default:user:nginx:rX"
    ];
  in
  [
    "d /srv/syncthing 0700 syncthing syncthing"
    "A /srv/syncthing - - - - ${acls}"
  ];

  # Disable Syncthing service home creation which clobbers above permissions.
  users.users.syncthing.createHome = lib.mkForce false;

  services.syncthing = {
    enable = true;
    openDefaultPorts = true;
    # Syncthing supports named sockets but the NixOS module assumes network.
    guiAddress = "[::1]:8384";
    dataDir = "/srv/syncthing";
    settings = {
      devices = {
        "Asus Nexus 7" = {
          id = "BVZARYC-2D56A6I-V6L2VQF-MU7IVCT-ITJTCGQ-IGMZG2W-RZRCTOT-K4GDHAY";
        };
        "DESKTOP-SFVBFBU" = {
          id = "T547Y5S-HUO5WIC-DM3Z7LS-UG647YR-ZQAMZHU-LIZHDY5-Q5WQLXL-RNH2GAV";
          autoAcceptFolders = true;
        };
        "Joes-iPhone" = {
          id = "P25LZDL-ZCHYEB3-FE3W4WW-YMMPWWF-27VY7DR-7Y25WNI-NJN7FXX-5PZZTQ5";
          autoAcceptFolders = true;
        };
        "Joes-iPad" = {
          id = "LJRC74M-EKUZO73-GAZPTUL-ZIQXHKR-IWR5Y5X-VDOPV6T-3BNOTR3-6CTG3AG";
          autoAcceptFolders = true;
        };
        "Joes-Mac-mini.local" = {
          id = "K532ULN-SMFZDJR-U2NSGTY-HY35MXX-6POK7KI-CETEKLV-RMCGRHL-DVROHAF";
          autoAcceptFolders = true;
        };
        "doughboy" = {
          id = "BI3SWOB-NHPQBVW-XM46DB6-BQBO2PP-DI2OVAS-WBVX24P-WM7CZ3U-NXMBGAV";
          autoAcceptFolders = true;
        };
        "penguin" = {
          id = "5BEB6SZ-YAPV3CC-54RZF3V-HQXXP3Y-TTVDWDU-SHHNVCH-IXKZ3O2-6RXG6QL";
          autoAcceptFolders = true;
        };
        "sparky" = {
          id = "FE43LDI-33WS467-LIGFWCC-5PPSKN6-GYODEWJ-KLQZLN7-H3GYGLG-IJ2JGQW";
          autoAcceptFolders = true;
        };
        "sparky-win" = {
          id = "UWA5IFV-CKFMLRS-CUMUB7X-LABLQST-QK2ULLM-BUVW6CW-PBT5AQX-AUNPBAK";
        };
        "steamdeck" = {
          id = "SCUAABL-XU6AS5H-IZZE4PN-LY5J4LH-OYZMXTU-2UMTVUL-I7B7QKE-ZBPSAQ5";
          autoAcceptFolders = true;
        };
      };
      folders = {
        "Deck/Documents" = {
          id = "mwxed-yy9gn";
          path = "~/Deck/Documents";
          versioning = staggeredVersioning;
          devices = [ "steamdeck" ];
        };
        "Deck/extra" = {
          id = "jzncl-7nkcq";
          path = "~/Deck/extra";
          versioning = staggeredVersioning;
          devices = [ "steamdeck" ];
        };
        "Documents" = {
          id = "bhemx-9nh3v";
          path = "~/Documents";
          versioning = staggeredVersioning;
          devices = [ "doughboy" "sparky" ];
        };
        "Downloads" = {
          id = "kvq6q-axjhu";
          path = "~/Downloads";
          versioning = staggeredVersioning;
          devices = [ "doughboy" "sparky" "Joes-iPad" ];
        };
        "Game/Epic Games/TheTalosPrinciple/UserData" = {
          id = "vek7u-iausx";
          path = "~/Game/Epic Games/TheTalosPrinciple/UserData";
          versioning = staggeredVersioning;
          devices = [ "DESKTOP-SFVBFBU" "steamdeck" ];
        };
        "Game/PCSX2" = {
          id = "chxsg-hpqgm";
          path = "~/Game/PCSX2";
          versioning = staggeredVersioning;
          devices = [ "steamdeck" ];
        };
        "Pictures" = {
          id = "vfjsd-4fczh";
          path = "~/Pictures";
          versioning = staggeredVersioning;
          devices = [ "doughboy" "sparky" ];
        };
        "Public" = {
          id = "f6iys-eunyf";
          path = "~/Public";
          versioning = staggeredVersioning;
          devices = [ "doughboy" "sparky" ];
        };
        "Sync" = {
          id = "7thks-5badk";
          path = "~/Sync";
          versioning = staggeredVersioning;
          devices = [
            "Asus Nexus 7"
            "DESKTOP-SFVBFBU"
            "Joes-iPad"
            "Joes-iPhone"
            "doughboy"
            "penguin"
            "sparky"
            "sparky-win"
          ];
        };
        "Windows" = {
          id = "gjcn7-qrsjr";
          path = "~/Windows";
          versioning = staggeredVersioning;
          devices = [
            "DESKTOP-SFVBFBU"
            "sparky-win"
          ];
        };
        "iPad" = {
          id = "qtzmu-fqdrs";
          path = "~/iPad";
          devices = [ "Joes-iPad" ];
        };
      };
    };
  };

  services.nginx.virtualHosts."st.mou.fo" = {
    enableACME = true;
    forceSSL = true;
    locations."/" = {
      proxyPass = "http://[::1]:8384";
      # https://docs.syncthing.net/users/faq.html#why-do-i-get-host-check-error-in-the-gui-api
      recommendedProxySettings = false;
    };
  };

  services.oauth2-proxy.nginx.virtualHosts = { "st.mou.fo" = {}; };
}