summaryrefslogtreecommitdiff
path: root/gnu/services
diff options
context:
space:
mode:
authorNicolas Graves <ngraves@ngraves.fr>2026-05-14 02:03:11 +0200
committerSharlatan Hellseher <sharlatanus@gmail.com>2026-08-09 13:30:03 +0100
commit83022166effd7ecf68f82d0616cf6d6b27d39d1d (patch)
tree3cbce14aa3c864c037c89ba78970d7dca3025dee /gnu/services
parentd1c611f6dda078b75154faacdeb8dfe0d9ee3d8f (diff)
gnu: services: Add jupyter services.
* gnu/services/jupyter.scm : New file. Introduce jupyter-service-type and jupyter-configuration. * gnu/home/services/jupyter.scm : New file. Introduce home variants. * gnu/local.mk : Record files. Relates-to: guix/guix!8657 Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/jupyter.scm116
1 files changed, 116 insertions, 0 deletions
diff --git a/gnu/services/jupyter.scm b/gnu/services/jupyter.scm
new file mode 100644
index 00000000000..6b18d20f633
--- /dev/null
+++ b/gnu/services/jupyter.scm
@@ -0,0 +1,116 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2026 Nicolas Graves <ngraves@ngraves.fr>
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
19(define-module (gnu services jupyter)
20 #:use-module (gnu packages guile)
21 #:use-module (gnu packages jupyter)
22 #:use-module (gnu services)
23 #:use-module (gnu services configuration)
24 #:use-module (gnu services shepherd)
25 #:use-module (guix gexp)
26 #:use-module (guix packages)
27 #:use-module (guix records)
28 #:use-module (ice-9 match)
29 #:export (jupyter-service-type
30 jupyter-configuration))
31
32(define list-of-file-likes? (list-of file-like?))
33
34(define-configuration/no-serialization jupyter-configuration
35 (python-jupyter-core
36 (file-like python-jupyter-core)
37 "Package providing the @command{jupyter} binary.")
38 (extensions
39 (list-of-file-likes (list))
40 "List of packages providing server extensions to Jupyter.")
41 (kernels
42 (list-of-file-likes (list))
43 "Kernel packages to add to the profile, e.g. for python @code{python-ipykernel}.")
44 (disable-check-xsrf?
45 (boolean #f)
46 "Whether to disable the XSRF check.")
47 (token
48 (string "MY_TOKEN")
49 "Authentication token for the Jupyter server."))
50
51(define (jupyter-profile-service config)
52 (match-record config <jupyter-configuration>
53 (python-jupyter-core extensions kernels)
54 (append (list python-jupyter-core) extensions kernels)))
55
56(define (jupyter-server-runtime-config-getter-procedure python-jupyter-core
57 field)
58 (with-extensions (list guile-json-4)
59 #~(begin
60 (use-modules (json))
61 (lambda (process . args)
62 (let* ((pid (process-id process))
63 (port
64 ((@ (ice-9 popen) open-input-pipe)
65 (string-append #$(file-append python-jupyter-core
66 "/bin/jupyter")
67 " --runtime-dir")))
68 (dir (read port))
69 (file (format #f "~a/jpserver-~a.json" dir pid)))
70 ((@ (ice-9 popen) close-pipe) port)
71 (call-with-input-file file
72 (lambda (port)
73 (let ((url (assoc-ref (json->scm port) #$field)))
74 (format #t "~a~%" url)))))))))
75
76(define (jupyter-shepherd-service config)
77 (match-record config <jupyter-configuration>
78 (python-jupyter-core disable-check-xsrf? token)
79 (list
80 (shepherd-service
81 (provision '(jupyter))
82 (documentation "Run a Jupyter server.")
83 (start
84 #~(make-forkexec-constructor
85 (list #$(file-append python-jupyter-core "/bin/jupyter")
86 "server" "--no-browser"
87 #$(string-append "--IdentityProvider.token=" token)
88 #$@(if disable-check-xsrf?
89 #~("--ServerApp.disable_check_xsrf=True")
90 #~()))
91 #:log-file "/var/log/jupyter.log"))
92 (stop #~(make-kill-destructor))
93 (respawn? #f)
94 (actions
95 (list
96 (shepherd-action
97 (name 'get-url)
98 (documentation "Print the Jupyter server URL.")
99 (procedure
100 (jupyter-server-runtime-config-getter-procedure
101 python-jupyter-core "url")))))))))
102
103(define jupyter-service-type
104 (service-type
105 (name 'jupyter)
106 (extensions
107 (list
108 (service-extension profile-service-type
109 jupyter-profile-service)
110 (service-extension shepherd-root-service-type
111 jupyter-shepherd-service)))
112 (default-value (jupyter-configuration))
113 (description
114 "Run a Jupyter server. The runtime file is reliably at
115@file{$(jupyter --runtime-dir)/jpserver-@var{pid}.json}. Provide the
116@code{get-url} function to return a valid URL to fetch from.")))