about summary refs log tree commit diff
path: root/genenetwork/services/genecup.scm
blob: 6ee28122c7adbad50d0c5aad5c70231945b1fe0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
;;; genenetwork-machines --- Guix configuration for genenetwork machines
;;; Copyright © 2024 jgart <jgart@dismail.de>
;;;
;;; This file is part of genenetwork-machines.
;;;
;;; genenetwork-machines is free software: you can redistribute it
;;; and/or modify it under the terms of the GNU General Public License
;;; as published by the Free Software Foundation, either version 3 of
;;; the License, or (at your option) any later version.
;;;
;;; genenetwork-machines is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the implied
;;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;;; See the GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with genenetwork-machines.  If not, see
;;; <https://www.gnu.org/licenses/>.

(define-module (genenetwork services genecup)
  #:use-module (guix)
  #:use-module (gnu)
  #:use-module (guix git)
  #:use-module (guix modules)
  #:use-module (guix profiles)
  #:use-module (guix records)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match)
  #:use-module (forge utils)
  #:use-module (gn packages genecup)
  #:use-module (gn packages mouse-longevity)
  #:use-module (gn services rshiny)
  #:use-module (gn packages machine-learning)
  #:use-module (gnu packages certs)
  #:use-module (gnu packages curl)
  #:use-module (gn packages python)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages bioinformatics)
  #:use-module (gnu packages compression)
  #:use-module ((gnu packages python) #:select (python))
  #:use-module (gnu packages python-xyz)
  #:use-module (guix build python-build-system)
  #:use-module (gnu packages python-crypto)
  #:use-module (gnu packages python-web)
  #:use-module (gnu services shepherd)
  #:use-module (gnu packages python-science)
  #:use-module (gnu packages machine-learning)
  #:use-module ((gnu packages admin) #:select (shepherd))
  #:export (genecup-configuration
            genecup-configuration?
            genecup-configuration-package
            genecup-service-type))

(define-record-type* <genecup-configuration>
  genecup-configuration make-genecup-configuration
  genecup-configuration?
  (package genecup-configuration-package ; <package>
           (default genecup-latest-with-tensorflow-native)))

(define (genecup-activation config)
  (match-record config <genecup-configuration>
                (package)
    (with-packages
     (list python
           python-nltk
           nss-certs ; Needed for downloading data with nltk.downloader.
           curl)
     (with-imported-modules '((guix build utils))
       #~(begin
           (use-modules (guix build utils))
           (let ((nltk-data "/var/cache/nltk_data/")
                 (data-dir "/export/ratspub/tmp"))
             (unless (file-exists? nltk-data)
               (begin
                 (mkdir-p nltk-data)
                 (chdir nltk-data)
                 (invoke #$(file-append python "/bin/python3") "-m" "nltk.downloader" "-d" nltk-data "punkt")))
             (unless (file-exists? (string-append data-dir "/userspub.sqlite"))
               (begin
                 (install-file #$(file-append package "/userspub.sqlite") data-dir)
                 (chmod (string-append data-dir "/userspub.sqlite") #o554)))))))))

(define genecup-shepherd-service
  (match-lambda
    (($ <genecup-configuration> package)
     (with-imported-modules (source-module-closure
                             '((guix search-paths)
                               (gnu build shepherd)
                               (gnu system file-systems)))
       (list (shepherd-service
              (provision '(genecup))
              (requirement '(networking))
              (modules '((gnu build shepherd)
                         (gnu system file-systems)))
              (start
               #~(make-forkexec-constructor
                  (list #$(file-append package "/server.py"))
                  #:directory #$package
                  #:environment-variables
                  (list
                   "NLTK_DATA=/var/cache/nltk_data"
                   (string-append "EDIRECT_PUBMED_MASTER="
                                  #$(file-append package "/minipubmed"))
                   (string-append "PERL_LWP_SSL_CA_FILE="
                                  #$(file-append (profile (content (packages->manifest (list curl nss-certs))))
                                                 "/etc/ssl/certs/ca-certificates.crt")))
                  #:log-file "/var/log/genecup.log"))
              (stop  #~(make-kill-destructor))))))))

(define genecup-service-type
  (service-type
   (name 'genecup)
   (extensions
    (list
     (service-extension activation-service-type
                        genecup-activation)
     (service-extension shepherd-root-service-type
                        genecup-shepherd-service)))
   (default-value (genecup-configuration))
   (description
    "Run a GeneCup Webserver.")))