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