From af5bbe630cb990daf9f29b307572f965ee9fa099 Mon Sep 17 00:00:00 2001 From: Runciter Date: Mon, 28 Oct 2024 02:19:54 +0800 Subject: Initial. A .guix-authorizations A .guix-channel A COPYING A README A whispers/packages/dict.scm A whispers/packages/doc.scm A whispers/packages/pdf.scm A whispers/packages/sh.scm A whispers/packages/whispers.scm A whispers/services/console.scm A whispers/services/dict.scm A whispers/services/finance.scm A whispers/services/gps.scm A whispers/services/proton.scm A whispers/services/ssh-agent.scm A whispers/services/ssh-tunneler.scm A whispers/services/whispers.scm A whispers/services/whispers/finance.scm A whispers/services/whispers/gps.scm A whispers/services/whispers/mail.scm A whispers/services/whispers/ssh.scm A whispers/services/whispers/vpn.scm A whispers/services/whispers/xdg.scm A whispers/tests/ssh-tunneler.scm --- whispers/services/gps.scm | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 whispers/services/gps.scm (limited to 'whispers/services/gps.scm') diff --git a/whispers/services/gps.scm b/whispers/services/gps.scm new file mode 100644 index 0000000..5c1b33f --- /dev/null +++ b/whispers/services/gps.scm @@ -0,0 +1,102 @@ +;;; Whispers --- Stealth VPN and ssh tunneler +;;; Copyright © 2024 Runciter +;;; +;;; 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 . + +(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 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 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 +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)))) -- cgit v1.2.3