blob: 5c1b33f24e8264e6f9ef5f9c69f1915d63e3727d (
about) (
plain)
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
|
;;; Whispers --- Stealth VPN and ssh tunneler
;;; Copyright © 2024 Runciter <runciter@whispers-vpn.org>
;;;
;;; This file is part of Whispers.
;;;
;;; Whispers is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; Whispers is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Whispers. If not, see <http://www.gnu.org/licenses/>.
(define-module (whispers services gps)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (gnu services)
#:use-module (gnu services shepherd)
#:use-module (gnu services admin)
#:use-module (gnu packages gps)
#:export (gpsd-configuration
gpsd-configuration?
gpsd-service-type))
(define-record-type* <gpsd-configuration>
gpsd-configuration make-gpsd-configuration
gpsd-configuration?
this-gpsd-configuration
;; A file-like object
(gpsd-package gpsd-configuration-gpsd-package
(default gpsd))
;; A symbol
(provision gpsd-configuration-provision
(default (string->symbol
(string-append
"gpsd-"
(number->string
(gpsd-configuration-port
this-gpsd-configuration)))))
(thunked))
;; A string
(source gpsd-configuration-source
(default "/dev/ttyUSB0"))
;; An integer
(port gpsd-configuration-port
(default 2947))
;; An integer
(listen-any? gpsd-configuration-listen-any?
(default #f))
;; A boolean value
(%auto-start? gpsd-configuration-auto-start?
(default #t)))
(define (constructor-gexp config)
"Returns a G-exp to start a gpsd shepherd service, configurable by
CONFIG, a record of the <gpsd-configuration> type."
(let ((gpsd-package (gpsd-configuration-gpsd-package config))
(listen-any? (gpsd-configuration-listen-any? config))
(port (gpsd-configuration-port config))
(source (gpsd-configuration-source config)))
#~(make-forkexec-constructor (append (list #$(file-append gpsd-package
"/sbin/gpsd")
"-N"
"-P"
#$(number->string port))
(if #$listen-any?
(list "-G")
(list))
(list #$source)))))
(define (gpsd-shepherd-services config)
"Returns a list of shepherd services handling a gpsd daemon
configured by CONFIG, a record of the <gpsd-configuration>
type."
(let ((auto-start? (gpsd-configuration-auto-start? config)))
(list
(shepherd-service
(documentation (string-append "gpsd service."))
(provision (list (gpsd-configuration-provision config)))
(requirement '())
(start (constructor-gexp config))
(stop #~(make-kill-destructor))
(auto-start? auto-start?)))))
(define gpsd-service-type
(service-type
(name 'gpsd)
(description "gpsd service")
(extensions
(list (service-extension shepherd-root-service-type
gpsd-shepherd-services)
(service-extension
profile-service-type
(lambda (config)
(list
(gpsd-configuration-gpsd-package config))))))
(default-value (gpsd-configuration))))
|