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 = lib.mdDoc ''
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 = lib.mdDoc ''
33 A device may be a local serial device for GPS input, or a URL of the form:
34 `[{dgpsip|ntrip}://][user:passwd@]host[:port][/stream]`
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 = lib.mdDoc ''
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 = lib.mdDoc ''
60 don't wait for client connects to poll GPS
61 '';
62 };
63
64 port = mkOption {
65 type = types.port;
66 default = 2947;
67 description = lib.mdDoc ''
68 The port where to listen for TCP connections.
69 '';
70 };
71
72 debugLevel = mkOption {
73 type = types.int;
74 default = 0;
75 description = lib.mdDoc ''
76 The debugging level.
77 '';
78 };
79
80 };
81
82 };
83
84
85 ###### implementation
86
87 config = mkIf cfg.enable {
88
89 users.users.gpsd =
90 { inherit uid;
91 group = "gpsd";
92 description = "gpsd daemon user";
93 home = "/var/empty";
94 };
95
96 users.groups.gpsd = { inherit gid; };
97
98 systemd.services.gpsd = {
99 description = "GPSD daemon";
100 wantedBy = [ "multi-user.target" ];
101 after = [ "network.target" ];
102 serviceConfig = {
103 Type = "forking";
104 ExecStart = ''
105 ${pkgs.gpsd}/sbin/gpsd -D "${toString cfg.debugLevel}" \
106 -S "${toString cfg.port}" \
107 ${optionalString cfg.readonly "-b"} \
108 ${optionalString cfg.nowait "-n"} \
109 "${cfg.device}"
110 '';
111 };
112 };
113
114 };
115
116}