gnu: Add tlf.
[jackhill/guix/guix.git] / gnu / services / syncthing.scm
CommitLineData
79ba12a1
OP
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
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))
30
31;;; Commentary:
32;;;
33;;; This module provides a service definition for the syncthing service.
34;;;
35;;; Code:
36
37(define-record-type* <syncthing-configuration>
38 syncthing-configuration make-syncthing-configuration
39 syncthing-configuration?
40 (syncthing syncthing-configuration-syncthing ;<package>
41 (default syncthing))
42 (arguments syncthing-configuration-arguments ;list of strings
43 (default '()))
44 (logflags syncthing-configuration-logflags ;number
45 (default 0))
46 (user syncthing-configuration-user ;string
47 (default #f))
48 (group syncthing-configuration-group ;string
49 (default "users"))
50 (home syncthing-configuration-home ;string
51 (default #f)))
52
53(define syncthing-shepherd-service
54 (match-lambda
55 (($ <syncthing-configuration> syncthing arguments logflags user group home)
56 (list
57 (shepherd-service
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")
63 "-no-browser"
64 "-no-restart"
65 (string-append "-logflags=" (number->string #$logflags)))
66 '#$arguments)
67 #:user #$user
68 #:group #$group
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")
73 (remove (lambda (str)
74 (or (string-prefix? "HOME=" str)
75 (string-prefix? "SSL_CERT_DIR=" str)
76 (string-prefix? "SSL_CERT_FILE=" str)))
77 (environ)))))
78 (respawn? #f)
79 (stop #~(make-kill-destructor)))))))
80
81(define syncthing-service-type
82 (service-type (name 'syncthing)
83 (extensions (list (service-extension shepherd-root-service-type
84 syncthing-shepherd-service)))
85 (description
86 "Run @uref{https://github.com/syncthing/syncthing, Syncthing}
87decentralized continuous file system synchronization.")))
88
89;;; syncthing.scm ends here