science.scm 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
  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 science)
  19. #:export (<rshiny-configuration>
  20. rshiny-configuration
  21. rshiny-configuration?
  22. rshiny-configuration-package
  23. rshiny-configuration-binary
  24. rshiny-shepherd-service
  25. rshiny-service-type))
  26. (use-modules (gnu)
  27. (guix records)
  28. (ice-9 match))
  29. (use-service-modules shepherd)
  30. (use-package-modules cran)
  31. (define-record-type* <rshiny-configuration>
  32. rshiny-configuration
  33. make-rshiny-configuration
  34. rshiny-configuration?
  35. (package rshiny-configuration-package ; package
  36. (default r-shiny))
  37. (binary rshiny-configuration-binary ; string
  38. (default "rshiny")))
  39. (define rshiny-shepherd-service
  40. (match-lambda
  41. (($ <rshiny-configuration> package binary)
  42. (list
  43. (shepherd-service
  44. (documentation (string-append "R-Shiny service for " binary))
  45. (provision (list (symbol-append 'rshiny- (string->symbol
  46. (string-take binary 9)))))
  47. (requirement '(networking))
  48. (start
  49. #~(exec-command
  50. (list
  51. #$(string-append "/run/current-system/profile/bin/" binary))
  52. ;#:log-file #$(string-append "/var/log/" binary ".log") ; kills shepherd
  53. #:environment-variables
  54. (list "R_LIBS_USER=/run/current-system/profile/site-library/")))
  55. (stop #~(make-kill-destructor)))))))
  56. (define rshiny-service-type
  57. (service-type
  58. (name 'rshiny)
  59. (extensions
  60. (list
  61. (service-extension shepherd-root-service-type
  62. rshiny-shepherd-service)
  63. (service-extension profile-service-type
  64. ;; We want the package installed so that it
  65. ;; pulls in the propagated inputs as well.
  66. (lambda (config)
  67. (list
  68. (rshiny-configuration-package config))))))
  69. (description
  70. "Run an R-Shiny webapp as a Guix Service.")))