syncthing.scm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. (define-module (gnu services syncthing)
  19. #:use-module (gnu packages syncthing)
  20. #:use-module (gnu services)
  21. #:use-module (gnu services shepherd)
  22. #:use-module (guix gexp)
  23. #:use-module (guix records)
  24. #:use-module (ice-9 match)
  25. #:use-module (srfi srfi-1)
  26. #:export (syncthing-configuration
  27. syncthing-configuration?
  28. syncthing-service-type))
  29. ;;; Commentary:
  30. ;;;
  31. ;;; This module provides a service definition for the syncthing service.
  32. ;;;
  33. ;;; Code:
  34. (define-record-type* <syncthing-configuration>
  35. syncthing-configuration make-syncthing-configuration
  36. syncthing-configuration?
  37. (syncthing syncthing-configuration-syncthing ;<package>
  38. (default syncthing))
  39. (arguments syncthing-configuration-arguments ;list of strings
  40. (default '()))
  41. (logflags syncthing-configuration-logflags ;number
  42. (default 0))
  43. (user syncthing-configuration-user ;string
  44. (default #f))
  45. (group syncthing-configuration-group ;string
  46. (default "users"))
  47. (home syncthing-configuration-home ;string
  48. (default #f)))
  49. (define syncthing-shepherd-service
  50. (match-lambda
  51. (($ <syncthing-configuration> syncthing arguments logflags user group home)
  52. (list
  53. (shepherd-service
  54. (provision (list (string->symbol (string-append "syncthing-" user))))
  55. (documentation "Run syncthing.")
  56. (requirement '(loopback))
  57. (start #~(make-forkexec-constructor
  58. (append (list (string-append #$syncthing "/bin/syncthing")
  59. "-no-browser"
  60. "-no-restart"
  61. (string-append "-logflags=" (number->string #$logflags)))
  62. '#$arguments)
  63. #:user #$user
  64. #:group #$group
  65. #:environment-variables
  66. (append (list (string-append "HOME=" (or #$home (passwd:dir (getpw #$user))))
  67. "SSL_CERT_DIR=/etc/ssl/certs"
  68. "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt")
  69. (remove (lambda (str)
  70. (or (string-prefix? "HOME=" str)
  71. (string-prefix? "SSL_CERT_DIR=" str)
  72. (string-prefix? "SSL_CERT_FILE=" str)))
  73. (environ)))))
  74. (respawn? #f)
  75. (stop #~(make-kill-destructor)))))))
  76. (define syncthing-service-type
  77. (service-type (name 'syncthing)
  78. (extensions (list (service-extension shepherd-root-service-type
  79. syncthing-shepherd-service)))
  80. (description
  81. "Run @uref{https://github.com/syncthing/syncthing, Syncthing}
  82. decentralized continuous file system synchronization.")))
  83. ;;; syncthing.scm ends here