science.scm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (define-module (gnu services science)
  2. #:export (<rshiny-configuration>
  3. rshiny-configuration
  4. rshiny-configuration?
  5. rshiny-configuration-package
  6. rshiny-configuration-binary
  7. rshiny-shepherd-service
  8. rshiny-service-type))
  9. (use-modules (gnu)
  10. (guix records)
  11. (ice-9 match))
  12. (use-service-modules shepherd)
  13. (use-package-modules cran)
  14. (define-record-type* <rshiny-configuration>
  15. rshiny-configuration
  16. make-rshiny-configuration
  17. rshiny-configuration?
  18. (package rshiny-configuration-package ; package
  19. (default r-shiny))
  20. (binary rshiny-configuration-binary ; string
  21. (default "rshiny")))
  22. (define rshiny-shepherd-service
  23. (match-lambda
  24. (($ <rshiny-configuration> package binary)
  25. (list
  26. (shepherd-service
  27. (documentation (string-append "R-Shiny service for " binary))
  28. (provision (list (symbol-append 'rshiny- (string->symbol
  29. (string-take binary 9)))))
  30. (requirement '(networking))
  31. (start
  32. #~(exec-command
  33. (list
  34. #$(string-append "/run/current-system/profile/bin/" binary))
  35. ;#:log-file #$(string-append "/var/log/" binary ".log") ; kills shepherd
  36. #:environment-variables
  37. (list "R_LIBS_USER=/run/current-system/profile/site-library/")))
  38. (stop #~(make-kill-destructor)))))))
  39. (define rshiny-service-type
  40. (service-type
  41. (name 'rshiny)
  42. (extensions
  43. (list
  44. (service-extension shepherd-root-service-type
  45. rshiny-shepherd-service)
  46. (service-extension profile-service-type
  47. ;; We want the package installed so that it
  48. ;; pulls in the propagated inputs as well.
  49. (lambda (config)
  50. (list
  51. (rshiny-configuration-package config))))))
  52. (description
  53. "Run an R-Shiny webapp as a Guix Service.")))