-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncthing.nix
64 lines (59 loc) · 1.84 KB
/
syncthing.nix
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
{ flake, config, ... }:
let
ids = {
laptop = "PRAP2CM-Y5G32PN-37S5DF7-GJ3N536-BCGDPMS-3DHH7O2-KQXDCKQ-FY4WHAT";
phone = "LGVEZX6-TYKLGEY-JJWU3ND-Y7TWKWX-U4FHOAG-MY2PK3J-3YQW3HI-BYADJAX";
server = "EQVFF5C-GXNV2EP-IQRVWGC-YSQSFIP-5TRKGCD-FT4NKRC-LLRHCZK-SLXPWQW";
work = "4AQBOHQ-3OYTLXQ-JTOT7VF-WG5GKF7-QHZDUTE-WAF5G7F-YG5HEOF-VHJ34AU";
};
# only share with those in your group (names are arbitrary)
groups = {
personal = {
devices = [ "laptop" "phone" "server" ];
folders = [ "drawings" "notes" "library" "sessions" "stash" ];
};
work = {
devices = [ "work" ];
folders = [ "notes" ];
};
};
home = config.users.users.${flake.lib.username}.home;
# all resources which contain the current host
shared = resource: (builtins.concatMap (group: group.${resource}) (builtins.filter
(group: builtins.elem config.networking.hostName group.devices)
(builtins.attrValues groups)
));
in
{
services = {
syncthing = {
# if host has an id
enable = builtins.elem config.networking.hostName (builtins.attrNames ids);
user = flake.lib.username;
openDefaultPorts = true;
dataDir = home;
settings = {
devices = builtins.listToAttrs (builtins.map
(device: {
name = device;
value.id = ids.${device};
})
(builtins.attrNames ids)
# (shared "devices")
);
folders = builtins.listToAttrs (builtins.map
(folder: {
name = folder;
value = {
path = "${home}/${folder}";
devices = builtins.concatMap (group: group.devices)
(builtins.filter (group: builtins.elem folder group.folders)
(builtins.attrValues groups));
};
})
(shared "folders")
);
};
};
};
}