Commit | Line | Data |
---|---|---|
533935cc EF |
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 | ||
8f19e63f EF |
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 ; package | |
39 | (default r-shiny)) | |
40 | (binary rshiny-configuration-binary ; string | |
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 | ;#:log-file #$(string-append "/var/log/" binary ".log") ; kills shepherd | |
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 | ;; We want the package installed so that it | |
70 | ;; pulls in the propagated inputs as well. | |
71 | (lambda (config) | |
72 | (list | |
73 | (rshiny-configuration-package config)))))) | |
74 | (description | |
75 | "Run an R-Shiny webapp as a Guix Service."))) |