1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 uid = config.ids.uids.gpsd;
8 gid = config.ids.gids.gpsd;
9 cfg = config.services.gpsd;
10
11in
12
13{
14
15 ###### interface
16
17 options = {
18
19 services.gpsd = {
20
21 enable = mkOption {
22 type = types.bool;
23 default = false;
24 description = ''
25 Whether to enable `gpsd', a GPS service daemon.
26 '';
27 };
28
29 device = mkOption {
30 type = types.str;
31 default = "/dev/ttyUSB0";
32 description = ''
33 A device may be a local serial device for GPS input, or a URL of the form:
34 <literal>[{dgpsip|ntrip}://][user:passwd@]host[:port][/stream]</literal>
35 in which case it specifies an input source for DGPS or ntrip data.
36 '';
37 };
38
39 readonly = mkOption {
40 type = types.bool;
41 default = true;
42 description = ''
43 Whether to enable the broken-device-safety, otherwise
44 known as read-only mode. Some popular bluetooth and USB
45 receivers lock up or become totally inaccessible when
46 probed or reconfigured. This switch prevents gpsd from
47 writing to a receiver. This means that gpsd cannot
48 configure the receiver for optimal performance, but it
49 also means that gpsd cannot break the receiver. A better
50 solution would be for Bluetooth to not be so fragile. A
51 platform independent method to identify
52 serial-over-Bluetooth devices would also be nice.
53 '';
54 };
55
56 nowait = mkOption {
57 type = types.bool;
58 default = false;
59 description = ''
60 don't wait for client connects to poll GPS
61 '';
62 };
63
64 port = mkOption {
65 type = types.int;
66 default = 2947;
67 description = ''
68 The port where to listen for TCP connections.
69 '';
70 };
71
72 debugLevel = mkOption {
73 type = types.int;
74 default = 0;
75 description = ''
76 The debugging level.
77 '';
78 };
79
80 };
81
82 };
83
84
85 ###### implementation
86
87 config = mkIf cfg.enable {
88
89 users.users = singleton
90 { name = "gpsd";
91 inherit uid;
92 description = "gpsd daemon user";
93 home = "/var/empty";
94 };
95
96 users.groups = singleton
97 { name = "gpsd";
98 inherit gid;
99 };
100
101 systemd.services.gpsd = {
102 description = "GPSD daemon";
103 wantedBy = [ "multi-user.target" ];
104 after = [ "network.target" ];
105 serviceConfig = {
106 Type = "forking";
107 ExecStart = ''
108 ${pkgs.gpsd}/sbin/gpsd -D "${toString cfg.debugLevel}" \
109 -S "${toString cfg.port}" \
110 ${optionalString cfg.readonly "-b"} \
111 ${optionalString cfg.nowait "-n"} \
112 "${cfg.device}"
113 '';
114 };
115 };
116
117 };
118
119}