blob: 716e5a3b5661ff4822c6c0d7635b5a3d48477c27 (
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
|
{
config,
lib,
pkgs,
...
}:
with builtins;
with lib; let
cnf = config.cynerd.syncthing;
hostName = config.networking.hostName;
allDevices = [
"albert"
"binky"
"errol"
"lipwig"
"ridcully"
"susan"
"spt-omnia"
];
mediaDevices = [
"lipwig"
"binky"
"errol"
"ridcully"
"spt-omnia"
];
bigStorageDevices = [
"errol"
"ridcully"
"spt-omnia"
];
filterDevice = folders: filterAttrs (n: v: any (d: d == hostName) v.devices) folders;
in {
options = {
cynerd.syncthing = {
enable = mkOption {
type = types.bool;
default = false;
description = "My personal Syncthing configuration";
};
baseDir = mkOption {
type = types.str;
default = "/home/cynerd";
description = "Base directory for all folders being synced.";
};
};
};
config = mkIf cnf.enable {
services.syncthing = {
enable = any (n: n == hostName) allDevices;
user = mkDefault "cynerd";
key = "/run/secrets/syncthing.key.pem";
cert = "/run/secrets/syncthing.cert.pem";
openDefaultPorts = true;
overrideFolders = true;
folders = filterDevice {
"${cnf.baseDir}/documents" = {
label = "Documents";
id = "documents";
devices = allDevices;
ignorePerms = false;
};
"${cnf.baseDir}/notes" = {
label = "Notes";
id = "notes";
devices = allDevices;
ignorePerms = false;
};
"${cnf.baseDir}/projects" = {
label = "Projects";
id = "projects";
devices = allDevices;
ignorePerms = false;
};
"${cnf.baseDir}/pictures" = {
label = "Pictures";
id = "pictures";
devices = mediaDevices;
ignorePerms = false;
};
# TODO phone-photos
"${cnf.baseDir}/music/primary" = {
label = "Music-primary";
id = "music-primary";
devices = mediaDevices;
ignorePerms = false;
};
"${cnf.baseDir}/music/secondary" = {
label = "Music-secondary";
id = "music-secondary";
devices = bigStorageDevices;
ignorePerms = false;
};
"${cnf.baseDir}/music/flac" = {
label = "Music-flac";
id = "music-flac";
devices = bigStorageDevices;
ignorePerms = false;
};
"${cnf.baseDir}/video" = {
label = "Video";
id = "video";
devices = bigStorageDevices;
ignorePerms = false;
};
};
overrideDevices = true;
devices =
recursiveUpdate
(genAttrs allDevices (name: {
id = config.secrets.syncthingIDs."${name}";
}))
{
lipwig.addresses = ["tcp://cynerd.cz"];
};
# TODO phone
};
};
}
|