You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
5.8 KiB

(define-module (gn services ratspub-container))
(use-modules (gnu)
(gn packages ratspub)
(guix download)
(guix modules)
(guix packages)
(guix records)
(ice-9 match))
(use-service-modules shepherd)
(use-package-modules certs compression)
(define-record-type* <ratspub-configuration>
(package ratspub-configuration-package ; package
(default ratspub)))
(method url-fetch)
(uri "")
(base32 "0i01c5qzn1p8dxyrpx4hry2n6x6b8rgcq1sck091n0jp036f6x4s"))))
(define ratspub-activation
(($ <ratspub-configuration> package)
(let ((nltk_data "/var/cache/nltk_data/tokenizers")
(data_dir "/export/ratspub"))
(unless (file-exists? "/export2/PubMed")
(mkdir-p "/export2/PubMed"))
(unless (file-exists? nltk_data)
;; The correct way would be to use python-nltk to download the data
;; python3 -m nltk.downloader -d /var/cache/nltk_data punkt
(mkdir-p nltk_data)
(chdir nltk_data)
(invoke #$(file-append unzip "/bin/unzip") "-q" #$
(unless (file-exists? (string-append data_dir "/userspub.sqlite"))
(install-file #$(file-append package "/userspub.sqlite") data_dir)
(chmod (string-append data_dir "/userspub.sqlite") #o554))))))))
(define ratspub-shepherd-service
(($ <ratspub-configuration> package)
(with-imported-modules (source-module-closure
'((gnu build shepherd)
(gnu system file-systems)))
(list (shepherd-service
(provision '(ratspub))
(requirement '(networking))
(modules '((gnu build shepherd)
(gnu system file-systems)))
(start #~(make-forkexec-constructor/container
(list #$(file-append package "/"))
;; Needs to run from the directory it is located in.
#:directory #$package
#:log-file "/var/log/ratspub.log"
;; We don't need to set TMPDIR because we're inside a container.
#:mappings (list (file-system-mapping
(source "/export2/PubMed")
(target source)
(writable? #t))
(source "/export/ratspub")
(target source)
(writable? #t))
(source "/var/cache/nltk_data")
(target source))
(source "/etc/ssl/certs")
(target source)))))
(stop #~(make-kill-destructor))))))))
(define ratspub-service-type
(name 'ratspub)
(service-extension shepherd-root-service-type
(service-extension activation-service-type
;; Make sure we get all the dependencies of RatsPub.
(service-extension profile-service-type
(compose list ratspub-configuration-package))))
(default-value (ratspub-configuration))
"Run a RatsPub Webserver.")))
(host-name "ratspub")
(timezone "Etc/UTC")
(locale "en_US.utf8")
(bootloader (bootloader-configuration
(bootloader grub-bootloader)
(targets '("does-not-matter"))))
(file-systems (list (file-system
(device "does-not-matter")
(mount-point "/")
(type "does-not-matter"))))
;; TODO: A more minimal kernel for use in a docker image
;; (kernel linux-libre-vm)
;; No firmware for VMs.
(firmware '())
(packages (list nss-certs))
(services (list (service ratspub-service-type
;; ratspub for docker, ratspub-with-tensorflow-native for architecture specific speed optimizations.
;(package ratspub))))))
(package ratspub-with-tensorflow-native))))))
;; guix system container -L /path/to/guix-bioinformatics/ -L /path/to/guix-past/modules/ /path/to/guix-bioinformatics/gn/services/ratspub-container.scm --network --share=/export2/PubMed=/export2/PubMed --share=/export/ratspub=/export/ratspub
;; For docker it isn't necessary to list the shared folders at build time.
;; guix system docker-image -L /path/to/guix-bioinformatics/ -L /path/to/guix-past/modules/ /path/to/guix-bioinformatics/gn/services/ratspub-container.scm --network
;; Docker instructions:
;; docker load --input ratspub-docker-image.tar.gz
;; docker run -d --privileged --net=host --name ratspub --volume /path/to/PubMed:/export2/PubMed guix