about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--genenetwork/services/genecup.scm121
1 files changed, 121 insertions, 0 deletions
diff --git a/genenetwork/services/genecup.scm b/genenetwork/services/genecup.scm
new file mode 100644
index 0000000..6ee2812
--- /dev/null
+++ b/genenetwork/services/genecup.scm
@@ -0,0 +1,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.")))