2023-04-12 12:48:02 +00:00
|
|
|
{ config, lib, pkgs, utils, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
uid = config.ids.uids.gpsd;
|
|
|
|
gid = config.ids.gids.gpsd;
|
|
|
|
cfg = config.services.gpsd;
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
in {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
imports = [
|
|
|
|
(lib.mkRemovedOptionModule [ "services" "gpsd" "device" ]
|
|
|
|
"Use `services.gpsd.devices` instead.")
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.gpsd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2023-02-02 18:25:31 +00:00
|
|
|
Whether to enable `gpsd`, a GPS service daemon.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
devices = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "/dev/ttyUSB0" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2023-04-12 12:48:02 +00:00
|
|
|
List of devices that `gpsd` should subscribe to.
|
|
|
|
|
|
|
|
A device may be a local serial device for GPS input, or a
|
|
|
|
URL of the form:
|
|
|
|
`[{dgpsip|ntrip}://][user:passwd@]host[:port][/stream]` in
|
|
|
|
which case it specifies an input source for DGPS or ntrip
|
|
|
|
data.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
readonly = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nowait = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
don't wait for client connects to poll GPS
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-07-14 22:03:04 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 2947;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The port where to listen for TCP connections.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
debugLevel = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The debugging level.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
listenany = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Listen on all addresses rather than just loopback.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "-r" "-s" "19200" ];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
A list of extra command line arguments to pass to gpsd.
|
|
|
|
Check gpsd(8) mangpage for possible arguments.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
users.users.gpsd = {
|
|
|
|
inherit uid;
|
|
|
|
group = "gpsd";
|
|
|
|
description = "gpsd daemon user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
users.groups.gpsd = { inherit gid; };
|
|
|
|
|
|
|
|
systemd.services.gpsd = {
|
|
|
|
description = "GPSD daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
2023-04-12 12:48:02 +00:00
|
|
|
ExecStart = let
|
|
|
|
devices = utils.escapeSystemdExecArgs cfg.devices;
|
2023-10-09 19:29:22 +00:00
|
|
|
extraArgs = utils.escapeSystemdExecArgs cfg.extraArgs;
|
2023-04-12 12:48:02 +00:00
|
|
|
in ''
|
2020-04-24 23:36:52 +00:00
|
|
|
${pkgs.gpsd}/sbin/gpsd -D "${toString cfg.debugLevel}" \
|
|
|
|
-S "${toString cfg.port}" \
|
|
|
|
${optionalString cfg.readonly "-b"} \
|
|
|
|
${optionalString cfg.nowait "-n"} \
|
2022-12-17 10:02:37 +00:00
|
|
|
${optionalString cfg.listenany "-G"} \
|
2023-10-09 19:29:22 +00:00
|
|
|
${extraArgs} \
|
2023-04-12 12:48:02 +00:00
|
|
|
${devices}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|