aboutsummaryrefslogtreecommitdiffstats
path: root/oni/home/services/syncthing.scm
blob: c12de05b7922d23a05718ef0029ee6ef19cec333 (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
(define-module (oni home services syncthing)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages syncthing)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu home services utils)
  #:use-module (guix packages)
  #:use-module (guix gexp)

  #:export (home-syncthing-service-type
            home-syncthing-configuration))

(define-configuration home-syncthing-configuration
  (package
   (package syncthing)
   "Package to use for setting syncthing"))

(define (add-syncthing-packages config)
  (list (home-syncthing-configuration-package config)))

(define (home-syncthing-shepherd-service config)
  (list
   (shepherd-service
    (documentation "Start syncthing")
    (provision '(syncthing))
    (auto-start? #t)
    (start
     #~(make-forkexec-constructor
        (list #$(file-append (home-syncthing-configuration-package config) "/bin/syncthing")
              "serve"
              "--logfile" (format #f "~a/.local/var/log/syncthing.log" (getenv "HOME"))
              "--no-browser")))
    (stop
     #~(make-kill-destructor)))))

(define home-syncthing-service-type
  (service-type
   (name 'home-syncthing)
   (extensions
    (list (service-extension
           home-profile-service-type
           add-syncthing-packages)
          (service-extension
           home-shepherd-service-type
           home-syncthing-shepherd-service)))
   (compose identity)
   (default-value (home-syncthing-configuration))
   (description "Install and configure syncthing.")))