summaryrefslogtreecommitdiff
path: root/profiles/core/syncthing.nix
blob: f8d6ee2693a3c906f400b767ac5792de08a23cb1 (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
{machine, config, lib,...}: with lib; let
    group = if machine.isDarwin then (builtins.toString config.ivi.gid) else config.ivi.group;
in {
  imports = [
    (mkAliasOptionModule [ "synced" ] [ "services" "syncthing" "settings" "folders" ])
  ];

  services.syncthing = {
    enable = machine.syncthing.enable;
    user = ivi.username;
    inherit group;
    dataDir = config.ivi.home;
    overrideDevices = true;
    overrideFolders = true;

    key = config.secrets.syncthing.path;

    settings = let
      allDevices = (filterAttrs (_: m: m.syncthing.id != "") ivi.machines);
    in {
      gui = {
        theme = "default";
        insecureAdminAccess = true;
      };

      devices = mapAttrs (_: m: {
        inherit (m.syncthing) id;
        introducer = m.isServer;
      }) allDevices;

      folders = let
        trashcan = {
          type = "trashcan";
          params.cleanoutDays = "0";
        };
        simple = {
          type = "simple";
          params = {
            keep = "5";
            cleanoutDays = "0";
          };
        };
        allNames = attrNames allDevices;
      in {
        my = {
          path = "${config.ivi.home}/sync/my";
          devices = allNames;
          versioning = simple;
        };
        pictures = {
          path = "${config.ivi.home}/sync/pictures";
          devices = allNames;
          versioning = trashcan;
        };
        password-store = {
          path = "${config.ivi.home}/sync/password-store";
          devices = allNames;
          versioning = trashcan;
        };
      };
    };
  };
  environment.systemPackages = [config.services.syncthing.package];
}