| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (gnu services science)
|
| 20 | #:export (<rshiny-configuration>
|
| 21 | rshiny-configuration
|
| 22 | rshiny-configuration?
|
| 23 | rshiny-configuration-package
|
| 24 | rshiny-configuration-binary
|
| 25 | rshiny-shepherd-service
|
| 26 | rshiny-service-type))
|
| 27 |
|
| 28 | (use-modules (gnu)
|
| 29 | (guix records)
|
| 30 | (ice-9 match))
|
| 31 | (use-service-modules shepherd)
|
| 32 | (use-package-modules cran)
|
| 33 |
|
| 34 | (define-record-type* <rshiny-configuration>
|
| 35 | rshiny-configuration
|
| 36 | make-rshiny-configuration
|
| 37 | rshiny-configuration?
|
| 38 | (package rshiny-configuration-package |
| 39 | (default r-shiny))
|
| 40 | (binary rshiny-configuration-binary |
| 41 | (default "rshiny")))
|
| 42 |
|
| 43 | (define rshiny-shepherd-service
|
| 44 | (match-lambda
|
| 45 | (($ <rshiny-configuration> package binary)
|
| 46 | (list
|
| 47 | (shepherd-service
|
| 48 | (documentation (string-append "R-Shiny service for " binary))
|
| 49 | (provision (list (symbol-append 'rshiny- (string->symbol
|
| 50 | (string-take binary 9)))))
|
| 51 | (requirement '(networking))
|
| 52 | (start
|
| 53 | #~(exec-command
|
| 54 | (list
|
| 55 | #$(string-append "/run/current-system/profile/bin/" binary))
|
| 56 | |
| 57 | #:environment-variables
|
| 58 | (list "R_LIBS_USER=/run/current-system/profile/site-library/")))
|
| 59 | (stop #~(make-kill-destructor)))))))
|
| 60 |
|
| 61 | (define rshiny-service-type
|
| 62 | (service-type
|
| 63 | (name 'rshiny)
|
| 64 | (extensions
|
| 65 | (list
|
| 66 | (service-extension shepherd-root-service-type
|
| 67 | rshiny-shepherd-service)
|
| 68 | (service-extension profile-service-type
|
| 69 | |
| 70 | |
| 71 | (lambda (config)
|
| 72 | (list
|
| 73 | (rshiny-configuration-package config))))))
|
| 74 | (description
|
| 75 | "Run an R-Shiny webapp as a Guix Service.")))
|