1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu services syncthing)
20 #:use-module (gnu packages syncthing)
21 #:use-module (gnu services)
22 #:use-module (gnu services shepherd)
23 #:use-module (guix gexp)
24 #:use-module (guix records)
25 #:use-module (ice-9 match)
26 #:use-module (srfi srfi-1)
27 #:export (syncthing-configuration
28 syncthing-configuration?
29 syncthing-service-type))
33 ;;; This module provides a service definition for the syncthing service.
37 (define-record-type* <syncthing-configuration>
38 syncthing-configuration make-syncthing-configuration
39 syncthing-configuration?
40 (syncthing syncthing-configuration-syncthing ;<package>
42 (arguments syncthing-configuration-arguments ;list of strings
44 (logflags syncthing-configuration-logflags ;number
46 (user syncthing-configuration-user ;string
48 (group syncthing-configuration-group ;string
50 (home syncthing-configuration-home ;string
53 (define syncthing-shepherd-service
55 (($ <syncthing-configuration> syncthing arguments logflags user group home)
58 (provision (list (string->symbol (string-append "syncthing-" user))))
59 (documentation "Run syncthing.")
60 (requirement '(loopback))
61 (start #~(make-forkexec-constructor
62 (append (list (string-append #$syncthing "/bin/syncthing")
65 (string-append "-logflags=" (number->string #$logflags)))
69 #:environment-variables
70 (append (list (string-append "HOME=" (or #$home (passwd:dir (getpw #$user))))
71 "SSL_CERT_DIR=/etc/ssl/certs"
72 "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt")
74 (or (string-prefix? "HOME=" str)
75 (string-prefix? "SSL_CERT_DIR=" str)
76 (string-prefix? "SSL_CERT_FILE=" str)))
79 (stop #~(make-kill-destructor)))))))
81 (define syncthing-service-type
82 (service-type (name 'syncthing)
83 (extensions (list (service-extension shepherd-root-service-type
84 syncthing-shepherd-service)))
86 "Run @uref{https://github.com/syncthing/syncthing, Syncthing}
87 decentralized continuous file system synchronization.")))
89 ;;; syncthing.scm ends here