blob: 6f7aec0784a03c1061db689b56024a5c0c604499 (
plain) (
blame)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
{ config, lib, pkgs, utils, ... }:
with lib;
let
uid = config.ids.uids.gpsd;
gid = config.ids.gids.gpsd;
cfg = config.services.gpsd;
in {
###### interface
imports = [
(lib.mkRemovedOptionModule [ "services" "gpsd" "device" ]
"Use `services.gpsd.devices` instead.")
];
options = {
services.gpsd = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable `gpsd`, a GPS service daemon.
'';
};
devices = mkOption {
type = types.listOf types.str;
default = [ "/dev/ttyUSB0" ];
description = ''
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.
'';
};
readonly = mkOption {
type = types.bool;
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.
'';
};
nowait = mkOption {
type = types.bool;
default = false;
description = ''
don't wait for client connects to poll GPS
'';
};
port = mkOption {
type = types.port;
default = 2947;
description = ''
The port where to listen for TCP connections.
'';
};
debugLevel = mkOption {
type = types.int;
default = 0;
description = ''
The debugging level.
'';
};
listenany = mkOption {
type = types.bool;
default = false;
description = ''
Listen on all addresses rather than just loopback.
'';
};
extraArgs = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "-r" "-s" "19200" ];
description = ''
A list of extra command line arguments to pass to gpsd.
Check gpsd(8) mangpage for possible arguments.
'';
};
};
};
###### implementation
config = mkIf cfg.enable {
users.users.gpsd = {
inherit uid;
group = "gpsd";
description = "gpsd daemon user";
home = "/var/empty";
};
users.groups.gpsd = { inherit gid; };
systemd.services.gpsd = {
description = "GPSD daemon";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Type = "forking";
ExecStart = let
devices = utils.escapeSystemdExecArgs cfg.devices;
extraArgs = utils.escapeSystemdExecArgs cfg.extraArgs;
in ''
${pkgs.gpsd}/sbin/gpsd -D "${toString cfg.debugLevel}" \
-S "${toString cfg.port}" \
${optionalString cfg.readonly "-b"} \
${optionalString cfg.nowait "-n"} \
${optionalString cfg.listenany "-G"} \
${extraArgs} \
${devices}
'';
};
};
};
}
|