aboutsummaryrefslogtreecommitdiff
path: root/gn/services/pluto.scm
blob: 720b76992beec8a933ceb236a253a4c08032fe88 (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
(define-module (gn services pluto))

(use-modules (gnu)
             (gn packages julia)
             (guix modules)
             (guix records)
             (ice-9 match))
(use-service-modules shepherd)
(use-package-modules
  admin
  certs)

(define-record-type* <pluto-configuration>
  pluto-configuration
  make-pluto-configuration
  pluto-configuration?
  (package  pluto-configuration-package     ; package
            (default julia-visuals))
  ;; TODO: Currently port 4343 is hardcoded in the package definition.
  (port     pluto-configuration-port        ; integer
            (default 80)))

(define %julia-account
  (list (user-group
          (name "julia")
          (system? #t))
        (user-account
          (name "julia")
          (group "julia")
          (system? #t)
          (comment "Julia User")
          (home-directory "/home/jovyan")
          (shell (file-append shadow "/sbin/nologin")))))

(define pluto-shepherd-service
  (match-lambda
    (($ <pluto-configuration> package port)
     (with-imported-modules (source-module-closure
                              '((gnu build shepherd)
                                (gnu system file-systems)))
       (list (shepherd-service
               (provision '(pluto))
               (requirement '(networking))
               (modules '((gnu build shepherd)
                          (gnu system file-systems)))
               (start #~(make-forkexec-constructor/container
                          ;(list #$(file-append package "/runpluto.sh") #$port)
                          (list #$(file-append package "/runpluto"))
                          #:log-file "/var/log/pluto.log"
                          #:user "julia"
                          #:group "julia"
                          ;; This prevents the service from using /root as $HOME.
                          #:environment-variables '()
                          #:mappings (list (file-system-mapping
                                             (source "/home/jovyan")
                                             (target source)
                                             (writable? #t))
                                           (file-system-mapping
                                             (source "/etc/ssl")
                                             (target source)))))
               (stop  #~(make-kill-destructor))))))))

(define pluto-service-type
  (service-type
    (name 'pluto)
    (extensions
      (list
        (service-extension shepherd-root-service-type
                           pluto-shepherd-service)
        (service-extension account-service-type
                           (const %julia-account))))
    (default-value (pluto-configuration))
    (description
     "Run a Pluto Jupyter Webserver.")))

(operating-system
  (host-name "pluto")
  (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))
  ;; For testing
  ;(packages (cons* nss-certs %base-packages))

  (setuid-programs '())

  (services (list (service pluto-service-type
                           (pluto-configuration
                             (port "4343"))))))

;; guix system container -L /path/to/guix-bioinformatics/ -L /path/to/guix-past/modules/ /path/to/guix-bioinformatics/gn/services/pluto.scm --network
;; 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/pluto.scm --network
;; Docker instructions:
;; docker load --input guix-docker-image.tar.gz
;; docker run -d --privileged --net=host --name pluto guix