syncthing.scm 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
  3. ;;; Copyright © 2023 Justin Veilleux <terramorpha@cock.li>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; 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))
  30. ;;; Commentary:
  31. ;;;
  32. ;;; This module provides a service definition for the syncthing service.
  33. ;;;
  34. ;;; Code:
  35. (define-record-type* <syncthing-configuration>
  36. syncthing-configuration make-syncthing-configuration
  37. syncthing-configuration?
  38. (syncthing syncthing-configuration-syncthing ;file-like
  39. (default syncthing))
  40. (arguments syncthing-configuration-arguments ;list of strings
  41. (default '()))
  42. (logflags syncthing-configuration-logflags ;number
  43. (default 0))
  44. (user syncthing-configuration-user ;string
  45. (default #f))
  46. (group syncthing-configuration-group ;string
  47. (default "users"))
  48. (home syncthing-configuration-home ;string
  49. (default #f))
  50. (home-service? syncthing-configuration-home-service?
  51. (default for-home?) (innate)))
  52. (define syncthing-shepherd-service
  53. (match-record-lambda <syncthing-configuration>
  54. (syncthing arguments logflags user group home home-service?)
  55. (list
  56. (shepherd-service
  57. (provision (if home-service?
  58. '(syncthing)
  59. (list (string->symbol
  60. (string-append "syncthing-" user)))))
  61. (documentation "Run syncthing.")
  62. (requirement (if home-service? '() '(loopback user-processes)))
  63. (start #~(make-forkexec-constructor
  64. (append (list (string-append #$syncthing "/bin/syncthing")
  65. "--no-browser"
  66. "--no-restart"
  67. (string-append "--logflags=" (number->string #$logflags)))
  68. '#$arguments)
  69. #:user #$(and (not home-service?) user)
  70. #:group #$(and (not home-service?) group)
  71. #:environment-variables
  72. (append (list (string-append "HOME=" (or #$home (passwd:dir (getpw #$user))))
  73. "SSL_CERT_DIR=/etc/ssl/certs"
  74. "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt")
  75. (filter (negate ;XXX: 'remove' is not in (guile)
  76. (lambda (str)
  77. (or (string-prefix? "HOME=" str)
  78. (string-prefix? "SSL_CERT_DIR=" str)
  79. (string-prefix? "SSL_CERT_FILE=" str))))
  80. (environ)))))
  81. (respawn? #f)
  82. (stop #~(make-kill-destructor))))))
  83. (define syncthing-service-type
  84. (service-type (name 'syncthing)
  85. (extensions (list (service-extension shepherd-root-service-type
  86. syncthing-shepherd-service)))
  87. (description
  88. "Run @uref{https://github.com/syncthing/syncthing, Syncthing}
  89. decentralized continuous file system synchronization.")))
  90. ;;; syncthing.scm ends here