2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2009-05-31 20:51:29 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-06-30 09:56:08 +02:00
|
|
|
uid = config.ids.uids.gpsd;
|
|
|
|
gid = config.ids.gids.gpsd;
|
2009-10-12 18:36:19 +02:00
|
|
|
cfg = config.services.gpsd;
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-05-31 20:51:29 +02:00
|
|
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.gpsd = {
|
2009-05-31 20:51:29 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
enable = mkOption {
|
2014-03-15 09:52:00 +01:00
|
|
|
type = types.bool;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable `gpsd', a GPS service daemon.
|
|
|
|
'';
|
|
|
|
};
|
2009-05-31 20:51:29 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
device = mkOption {
|
2014-03-15 09:52:00 +01:00
|
|
|
type = types.str;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = "/dev/ttyUSB0";
|
|
|
|
description = ''
|
|
|
|
A device may be a local serial device for GPS input, or a URL of the form:
|
|
|
|
<literal>[{dgpsip|ntrip}://][user:passwd@]host[:port][/stream]</literal>
|
|
|
|
in which case it specifies an input source for DGPS or ntrip data.
|
|
|
|
'';
|
|
|
|
};
|
2009-05-31 20:51:29 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
readonly = mkOption {
|
2014-03-15 09:52:00 +01:00
|
|
|
type = types.bool;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the broken-device-safety, otherwise
|
|
|
|
known as read-only mode. Some popular bluetooth and USB
|
|
|
|
receivers lock up or become totally inaccessible when
|
|
|
|
probed or reconfigured. This switch prevents gpsd from
|
|
|
|
writing to a receiver. This means that gpsd cannot
|
|
|
|
configure the receiver for optimal performance, but it
|
|
|
|
also means that gpsd cannot break the receiver. A better
|
|
|
|
solution would be for Bluetooth to not be so fragile. A
|
|
|
|
platform independent method to identify
|
|
|
|
serial-over-Bluetooth devices would also be nice.
|
|
|
|
'';
|
|
|
|
};
|
2009-05-31 20:51:29 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
port = mkOption {
|
2015-06-15 18:11:32 +02:00
|
|
|
type = types.int;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = 2947;
|
|
|
|
description = ''
|
|
|
|
The port where to listen for TCP connections.
|
|
|
|
'';
|
2009-05-31 20:51:29 +02:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
debugLevel = mkOption {
|
2015-06-15 18:11:32 +02:00
|
|
|
type = types.int;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = 0;
|
|
|
|
description = ''
|
|
|
|
The debugging level.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-31 20:51:29 +02:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-05-31 20:51:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf cfg.enable {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
users.extraUsers = singleton
|
2009-05-31 20:51:29 +02:00
|
|
|
{ name = "gpsd";
|
|
|
|
inherit uid;
|
|
|
|
description = "gpsd daemon user";
|
|
|
|
home = "/var/empty";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-05-31 20:51:29 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
users.extraGroups = singleton
|
2009-05-31 20:51:29 +02:00
|
|
|
{ name = "gpsd";
|
|
|
|
inherit gid;
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-05-31 20:51:29 +02:00
|
|
|
|
2014-03-14 23:01:32 +01:00
|
|
|
systemd.services.gpsd = {
|
|
|
|
description = "GPSD daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.gpsd}/sbin/gpsd -D "${toString cfg.debugLevel}" \
|
|
|
|
-S "${toString cfg.port}" \
|
|
|
|
${if cfg.readonly then "-b" else ""} \
|
|
|
|
"${cfg.device}"
|
|
|
|
'';
|
2009-05-31 20:51:29 +02:00
|
|
|
};
|
2014-03-14 23:01:32 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-05-31 20:51:29 +02:00
|
|
|
}
|