2020-04-24 23:36:52 +00:00
|
|
|
{ pkgs, lib, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.gammu-smsd;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "gammu-smsd.conf" ''
|
|
|
|
[gammu]
|
|
|
|
Device = ${cfg.device.path}
|
|
|
|
Connection = ${cfg.device.connection}
|
|
|
|
SynchronizeTime = ${if cfg.device.synchronizeTime then "yes" else "no"}
|
|
|
|
LogFormat = ${cfg.log.format}
|
2023-04-29 16:46:19 +00:00
|
|
|
${optionalString (cfg.device.pin != null) "PIN = ${cfg.device.pin}"}
|
2020-04-24 23:36:52 +00:00
|
|
|
${cfg.extraConfig.gammu}
|
|
|
|
|
|
|
|
|
|
|
|
[smsd]
|
|
|
|
LogFile = ${cfg.log.file}
|
|
|
|
Service = ${cfg.backend.service}
|
|
|
|
|
|
|
|
${optionalString (cfg.backend.service == "files") ''
|
|
|
|
InboxPath = ${cfg.backend.files.inboxPath}
|
|
|
|
OutboxPath = ${cfg.backend.files.outboxPath}
|
|
|
|
SentSMSPath = ${cfg.backend.files.sentSMSPath}
|
|
|
|
ErrorSMSPath = ${cfg.backend.files.errorSMSPath}
|
|
|
|
''}
|
|
|
|
|
|
|
|
${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "sqlite") ''
|
|
|
|
Driver = ${cfg.backend.sql.driver}
|
|
|
|
DBDir = ${cfg.backend.sql.database}
|
|
|
|
''}
|
|
|
|
|
|
|
|
${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "native_pgsql") (
|
|
|
|
with cfg.backend; ''
|
|
|
|
Driver = ${sql.driver}
|
2023-04-29 16:46:19 +00:00
|
|
|
${optionalString (sql.database!= null) "Database = ${sql.database}"}
|
|
|
|
${optionalString (sql.host != null) "Host = ${sql.host}"}
|
|
|
|
${optionalString (sql.user != null) "User = ${sql.user}"}
|
|
|
|
${optionalString (sql.password != null) "Password = ${sql.password}"}
|
2020-04-24 23:36:52 +00:00
|
|
|
'')}
|
|
|
|
|
|
|
|
${cfg.extraConfig.smsd}
|
|
|
|
'';
|
|
|
|
|
|
|
|
initDBDir = "share/doc/gammu/examples/sql";
|
|
|
|
|
|
|
|
gammuPackage = with cfg.backend; (pkgs.gammu.override {
|
2022-12-02 08:20:57 +00:00
|
|
|
dbiSupport = service == "sql" && sql.driver == "sqlite";
|
|
|
|
postgresSupport = service == "sql" && sql.driver == "native_pgsql";
|
2020-04-24 23:36:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.gammu-smsd = {
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "gammu-smsd daemon");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "smsd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User that has access to the device";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
device = {
|
|
|
|
path = mkOption {
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Device node or address of the phone";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "/dev/ttyUSB2";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "root";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Owner group of the device";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "dialout";
|
|
|
|
};
|
|
|
|
|
|
|
|
connection = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "at";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Protocol which will be used to talk to the phone";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
synchronizeTime = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to set time from computer to the phone during starting connection";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pin = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "PIN code for the simcard";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
log = {
|
|
|
|
file = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "syslog";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path to file where information about communication will be stored";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
format = mkOption {
|
|
|
|
type = types.enum [ "nothing" "text" "textall" "textalldate" "errors" "errorsdate" "binary" ];
|
|
|
|
default = "errors";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Determines what will be logged to the LogFile";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extraConfig = {
|
|
|
|
gammu = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra config lines to be added into [gammu] section";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
smsd = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra config lines to be added into [smsd] section";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
backend = {
|
|
|
|
service = mkOption {
|
|
|
|
type = types.enum [ "null" "files" "sql" ];
|
|
|
|
default = "null";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Service to use to store sms data.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
files = {
|
|
|
|
inboxPath = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/spool/sms/inbox/";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Where the received SMSes are stored";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
outboxPath = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/spool/sms/outbox/";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Where SMSes to be sent should be placed";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sentSMSPath = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/spool/sms/sent/";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Where the transmitted SMSes are placed";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
errorSMSPath = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/spool/sms/error/";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Where SMSes with error in transmission is placed";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
sql = {
|
|
|
|
driver = mkOption {
|
|
|
|
type = types.enum [ "native_mysql" "native_pgsql" "odbc" "dbi" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "DB driver to use";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sqlDialect = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "SQL dialect to use (odbc driver only)";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
database = mkOption {
|
2020-09-25 04:45:31 +00:00
|
|
|
type = types.nullOr types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database name to store sms data";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database server address";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User name used for connection to the database";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-12-28 21:21:41 +00:00
|
|
|
description = lib.mdDoc "User password used for connection to the database";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
users.users.${cfg.user} = {
|
|
|
|
description = "gammu-smsd user";
|
2021-09-22 15:38:15 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = cfg.device.group;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = with cfg.backend; [ gammuPackage ]
|
|
|
|
++ optionals (service == "sql" && sql.driver == "sqlite") [ pkgs.sqlite ];
|
|
|
|
|
|
|
|
systemd.services.gammu-smsd = {
|
|
|
|
description = "gammu-smsd daemon";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
wants = with cfg.backend; [ ]
|
|
|
|
++ optionals (service == "sql" && sql.driver == "native_pgsql") [ "postgresql.service" ];
|
|
|
|
|
|
|
|
preStart = with cfg.backend;
|
|
|
|
|
|
|
|
optionalString (service == "files") (with files; ''
|
|
|
|
mkdir -m 755 -p ${inboxPath} ${outboxPath} ${sentSMSPath} ${errorSMSPath}
|
|
|
|
chown ${cfg.user} -R ${inboxPath}
|
|
|
|
chown ${cfg.user} -R ${outboxPath}
|
|
|
|
chown ${cfg.user} -R ${sentSMSPath}
|
|
|
|
chown ${cfg.user} -R ${errorSMSPath}
|
|
|
|
'')
|
|
|
|
+ optionalString (service == "sql" && sql.driver == "sqlite") ''
|
|
|
|
cat "${gammuPackage}/${initDBDir}/sqlite.sql" \
|
|
|
|
| ${pkgs.sqlite.bin}/bin/sqlite3 ${sql.database}
|
|
|
|
''
|
|
|
|
+ (let execPsql = extraArgs: concatStringsSep " " [
|
|
|
|
(optionalString (sql.password != null) "PGPASSWORD=${sql.password}")
|
|
|
|
"${config.services.postgresql.package}/bin/psql"
|
|
|
|
(optionalString (sql.host != null) "-h ${sql.host}")
|
|
|
|
(optionalString (sql.user != null) "-U ${sql.user}")
|
|
|
|
"$extraArgs"
|
|
|
|
"${sql.database}"
|
|
|
|
]; in optionalString (service == "sql" && sql.driver == "native_pgsql") ''
|
|
|
|
echo '\i '"${gammuPackage}/${initDBDir}/pgsql.sql" | ${execPsql ""}
|
|
|
|
'');
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "${cfg.user}";
|
|
|
|
Group = "${cfg.device.group}";
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
ExecStart = "${gammuPackage}/bin/gammu-smsd -c ${configFile}";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|