tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
gammu-smsd service: init
Al Zohali
10 years ago
7b7cf281
f13333d4
+255
3 changed files
expand all
collapse all
unified
split
nixos
modules
misc
ids.nix
module-list.nix
services
misc
gammu-smsd.nix
+1
nixos/modules/misc/ids.nix
···
248
248
matrix-synapse = 224;
249
249
rspamd = 225;
250
250
rmilter = 226;
251
251
+
gammu-smsd = 227;
251
252
252
253
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
253
254
+1
nixos/modules/module-list.nix
···
210
210
./services/misc/etcd.nix
211
211
./services/misc/felix.nix
212
212
./services/misc/folding-at-home.nix
213
213
+
./services/misc/gammu-smsd.nix
213
214
#./services/misc/gitit.nix
214
215
./services/misc/gitlab.nix
215
216
./services/misc/gitolite.nix
+253
nixos/modules/services/misc/gammu-smsd.nix
···
1
1
+
{ pkgs, lib, config, ... }:
2
2
+
3
3
+
with lib;
4
4
+
let
5
5
+
cfg = config.services.gammu-smsd;
6
6
+
7
7
+
configFile = pkgs.writeText "gammu-smsd.conf" ''
8
8
+
[gammu]
9
9
+
Device = ${cfg.device.path}
10
10
+
Connection = ${cfg.device.connection}
11
11
+
SynchronizeTime = ${if cfg.device.synchronizeTime then "yes" else "no"}
12
12
+
LogFormat = ${cfg.log.format}
13
13
+
${if (cfg.device.pin != null) then "PIN = ${cfg.device.pin}" else ""}
14
14
+
${cfg.extraConfig.gammu}
15
15
+
16
16
+
17
17
+
[smsd]
18
18
+
LogFile = ${cfg.log.file}
19
19
+
Service = ${cfg.backend.service}
20
20
+
21
21
+
${optionalString (cfg.backend.service == "files") ''
22
22
+
InboxPath = ${cfg.backend.files.inboxPath}
23
23
+
OutboxPath = ${cfg.backend.files.outboxPath}
24
24
+
SentSMSPath = ${cfg.backend.files.sentSMSPath}
25
25
+
ErrorSMSPath = ${cfg.backend.files.errorSMSPath}
26
26
+
''}
27
27
+
28
28
+
${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "sqlite") ''
29
29
+
Driver = ${cfg.backend.sql.driver}
30
30
+
DBDir = ${cfg.backend.sql.database}
31
31
+
''}
32
32
+
33
33
+
${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "native_pgsql") (
34
34
+
with cfg.backend; ''
35
35
+
Driver = ${sql.driver}
36
36
+
${if (sql.database!= null) then "Database = ${sql.database}" else ""}
37
37
+
${if (sql.host != null) then "Host = ${sql.host}" else ""}
38
38
+
${if (sql.user != null) then "User = ${sql.user}" else ""}
39
39
+
${if (sql.password != null) then "Password = ${sql.password}" else ""}
40
40
+
'')}
41
41
+
42
42
+
${cfg.extraConfig.smsd}
43
43
+
'';
44
44
+
45
45
+
initDBDir = "share/doc/gammu/examples/sql";
46
46
+
47
47
+
gammuPackage = with cfg.backend; (pkgs.gammu.override {
48
48
+
dbiSupport = (service == "sql" && sql.driver == "sqlite");
49
49
+
postgresSupport = (service == "sql" && sql.driver == "native_pgsql");
50
50
+
});
51
51
+
52
52
+
in {
53
53
+
options = {
54
54
+
services.gammu-smsd = {
55
55
+
56
56
+
enable = mkEnableOption "gammu-smsd daemon";
57
57
+
58
58
+
user = mkOption {
59
59
+
type = types.str;
60
60
+
default = "smsd";
61
61
+
description = "User that has access to the device";
62
62
+
};
63
63
+
64
64
+
device = {
65
65
+
path = mkOption {
66
66
+
type = types.path;
67
67
+
description = "Device node or address of the phone";
68
68
+
example = "/dev/ttyUSB2";
69
69
+
};
70
70
+
71
71
+
group = mkOption {
72
72
+
type = types.str;
73
73
+
default = "root";
74
74
+
description = "Owner group of the device";
75
75
+
example = "dialout";
76
76
+
};
77
77
+
78
78
+
connection = mkOption {
79
79
+
type = types.str;
80
80
+
default = "at";
81
81
+
description = "Protocol which will be used to talk to the phone";
82
82
+
};
83
83
+
84
84
+
synchronizeTime = mkOption {
85
85
+
type = types.bool;
86
86
+
default = true;
87
87
+
description = "Whether to set time from computer to the phone during starting connection";
88
88
+
};
89
89
+
90
90
+
pin = mkOption {
91
91
+
type = types.nullOr types.str;
92
92
+
default = null;
93
93
+
description = "PIN code for the simcard";
94
94
+
};
95
95
+
};
96
96
+
97
97
+
98
98
+
log = {
99
99
+
file = mkOption {
100
100
+
type = types.str;
101
101
+
default = "syslog";
102
102
+
description = "Path to file where information about communication will be stored";
103
103
+
};
104
104
+
105
105
+
format = mkOption {
106
106
+
type = types.enum [ "nothing" "text" "textall" "textalldate" "errors" "errorsdate" "binary" ];
107
107
+
default = "errors";
108
108
+
description = "Determines what will be logged to the LogFile";
109
109
+
};
110
110
+
};
111
111
+
112
112
+
113
113
+
extraConfig = {
114
114
+
gammu = mkOption {
115
115
+
type = types.lines;
116
116
+
default = "";
117
117
+
description = "Extra config lines to be added into [gammu] section";
118
118
+
};
119
119
+
120
120
+
121
121
+
smsd = mkOption {
122
122
+
type = types.lines;
123
123
+
default = "";
124
124
+
description = "Extra config lines to be added into [smsd] section";
125
125
+
};
126
126
+
};
127
127
+
128
128
+
129
129
+
backend = {
130
130
+
service = mkOption {
131
131
+
type = types.enum [ "null" "files" "sql" ];
132
132
+
default = "null";
133
133
+
description = "Service to use to store sms data.";
134
134
+
};
135
135
+
136
136
+
files = {
137
137
+
inboxPath = mkOption {
138
138
+
type = types.path;
139
139
+
default = "/var/spool/sms/inbox/";
140
140
+
description = "Where the received SMSes are stored";
141
141
+
};
142
142
+
143
143
+
outboxPath = mkOption {
144
144
+
type = types.path;
145
145
+
default = "/var/spool/sms/outbox/";
146
146
+
description = "Where SMSes to be sent should be placed";
147
147
+
};
148
148
+
149
149
+
sentSMSPath = mkOption {
150
150
+
type = types.path;
151
151
+
default = "/var/spool/sms/sent/";
152
152
+
description = "Where the transmitted SMSes are placed";
153
153
+
};
154
154
+
155
155
+
errorSMSPath = mkOption {
156
156
+
type = types.path;
157
157
+
default = "/var/spool/sms/error/";
158
158
+
description = "Where SMSes with error in transmission is placed";
159
159
+
};
160
160
+
};
161
161
+
162
162
+
sql = {
163
163
+
driver = mkOption {
164
164
+
type = types.enum [ "native_mysql" "native_pgsql" "odbc" "dbi" ];
165
165
+
description = "DB driver to use";
166
166
+
};
167
167
+
168
168
+
sqlDialect = mkOption {
169
169
+
type = types.nullOr types.str;
170
170
+
default = null;
171
171
+
description = "SQL dialect to use (odbc driver only)";
172
172
+
};
173
173
+
174
174
+
database = mkOption {
175
175
+
type = types.str;
176
176
+
default = null;
177
177
+
description = "Database name to store sms data";
178
178
+
};
179
179
+
180
180
+
host = mkOption {
181
181
+
type = types.str;
182
182
+
default = "localhost";
183
183
+
description = "Database server address";
184
184
+
};
185
185
+
186
186
+
user = mkOption {
187
187
+
type = types.nullOr types.str;
188
188
+
default = null;
189
189
+
description = "User name used for connection to the database";
190
190
+
};
191
191
+
192
192
+
password = mkOption {
193
193
+
type = types.nullOr types.str;
194
194
+
default = null;
195
195
+
description = "User password used for connetion to the database";
196
196
+
};
197
197
+
};
198
198
+
};
199
199
+
};
200
200
+
};
201
201
+
202
202
+
config = mkIf cfg.enable {
203
203
+
users.extraUsers.${cfg.user} = {
204
204
+
description = "gammu-smsd user";
205
205
+
uid = config.ids.uids.gammu-smsd;
206
206
+
extraGroups = [ "${cfg.device.group}" ];
207
207
+
};
208
208
+
209
209
+
environment.systemPackages = with cfg.backend; [ gammuPackage ]
210
210
+
++ optionals (service == "sql" && sql.driver == "sqlite") [ pkgs.sqlite ];
211
211
+
212
212
+
systemd.services.gammu-smsd = {
213
213
+
description = "gammu-smsd daemon";
214
214
+
215
215
+
wantedBy = [ "multi-user.target" ];
216
216
+
217
217
+
wants = with cfg.backend; [ ]
218
218
+
++ optionals (service == "sql" && sql.driver == "native_pgsql") [ "postgresql.service" ];
219
219
+
220
220
+
preStart = with cfg.backend;
221
221
+
222
222
+
optionalString (service == "files") (with files; ''
223
223
+
mkdir -m 755 -p ${inboxPath} ${outboxPath} ${sentSMSPath} ${errorSMSPath}
224
224
+
chown ${cfg.user} -R ${inboxPath}
225
225
+
chown ${cfg.user} -R ${outboxPath}
226
226
+
chown ${cfg.user} -R ${sentSMSPath}
227
227
+
chown ${cfg.user} -R ${errorSMSPath}
228
228
+
'')
229
229
+
+ optionalString (service == "sql" && sql.driver == "sqlite") ''
230
230
+
cat "${gammuPackage}/${initDBDir}/sqlite.sql" \
231
231
+
| ${pkgs.sqlite}/bin/sqlite3 ${sql.database}
232
232
+
''
233
233
+
+ (let execPsql = extraArgs: concatStringsSep " " [
234
234
+
(optionalString (sql.password != null) "PGPASSWORD=${sql.password}")
235
235
+
"${config.services.postgresql.package}/bin/psql"
236
236
+
(optionalString (sql.host != null) "-h ${sql.host}")
237
237
+
(optionalString (sql.user != null) "-U ${sql.user}")
238
238
+
"$extraArgs"
239
239
+
"${sql.database}"
240
240
+
]; in optionalString (service == "sql" && sql.driver == "native_pgsql") ''
241
241
+
echo '\i '"${gammuPackage}/${initDBDir}/pgsql.sql" | ${execPsql ""}
242
242
+
'');
243
243
+
244
244
+
serviceConfig = {
245
245
+
User = "${cfg.user}";
246
246
+
Group = "${cfg.device.group}";
247
247
+
PermissionsStartOnly = true;
248
248
+
ExecStart = "${gammuPackage}/bin/gammu-smsd -c ${configFile}";
249
249
+
};
250
250
+
251
251
+
};
252
252
+
};
253
253
+
}